Example #1
0
def comparison_worker(identity, input, output):
    logfile = open(os.getcwd() + "/" + "rgcompare" + "." + str(identity) + ".log", 'w') if log else open(os.devnull, 'w')
    print "Starting worker {0} (logging to {1})".format(identity, logfile.name)
    try:
        with RedirectStdStreams(stdout=logfile, stderr=logfile):
            for match_id, player_fnames, map_fname, turns in iter(input.get, 'STOP'):

                map_data = ast.literal_eval(open(map_fname).read())
                settings.init_map(map_data)
                players = [game.Player(x) for x in player_fnames]
                g = game.Game(players)

                t_start = time.clock()
                for i in range(turns):
                    print (' running turn %d ' % g._state.turn).center(70, '-')
                    g.run_turn()
                t_end = time.clock()

                output.put([g.get_scores(), t_end - t_start])
    finally:
        print "Terminating worker {0}...".format(identity)
Example #2
0
def comparison_worker(identity, input, output):
    logfile = open(
        os.getcwd() + "/" + "rgcompare" + "." + str(identity) +
        ".log", 'w') if log else open(os.devnull, 'w')
    print "Starting worker {0} (logging to {1})".format(identity, logfile.name)
    try:
        with RedirectStdStreams(stdout=logfile, stderr=logfile):
            for match_id, player_fnames, map_fname, turns in iter(
                    input.get, 'STOP'):

                map_data = ast.literal_eval(open(map_fname).read())
                settings.init_map(map_data)
                players = [game.Player(x) for x in player_fnames]
                g = game.Game(players)

                t_start = time.clock()
                for i in range(turns):
                    print(' running turn %d ' % g._state.turn).center(70, '-')
                    g.run_turn()
                t_end = time.clock()

                output.put([g.get_scores(), t_end - t_start])
    finally:
        print "Terminating worker {0}...".format(identity)
Example #3
0
import ast
import pkg_resources
import unittest

from rgkit.settings import settings
from rgkit.gamestate import GameState

map_data = ast.literal_eval(
    open(pkg_resources.resource_filename('rgkit', 'maps/default.py')).read())
settings.init_map(map_data)


class TestSpawn(unittest.TestCase):
    def test_first_turn_spawning(self):
        state = GameState()

        actions = {}

        state2 = state.apply_actions(actions)

        self.assertEqual(state2.get_scores(),
                         [settings.spawn_per_player,
                          settings.spawn_per_player])

    def test_spawn_kills(self):
        state = GameState()

        state.add_robot((4, 3), 0)

        actions = {
            (4, 3): ['guard']
Example #4
0
def load_map(map_file):
    map_data = ast.literal_eval(open(MAP_FILENAME).read())
    settings.init_map(map_data)
Example #5
0
def load_map(map_file):
    map_data = ast.literal_eval(open(MAP_FILENAME).read())
    settings.init_map(map_data)
Example #6
0
def load_map():
    map_filename = pkg_resources.resource_filename(
        'rgkit', 'maps/default.py')
    map_data = ast.literal_eval(open(map_filename).read())
    settings.init_map(map_data)
Example #7
0
def load_map():
    map_filename = pkg_resources.resource_filename('rgkit', 'maps/default.py')
    map_data = ast.literal_eval(open(map_filename).read())
    settings.init_map(map_data)