Example #1
0
def run_match(bot1, bot2):   
    #rgkit integration
    runner = Runner(player_files=(bot1,bot2), options=Options(quiet=4, game_seed=random.randint(0, default_settings.max_seed)))
    scores0, scores1 = runner.run()[0]
    if scores0 > scores1:
      return (scores0, scores1, scores0 - scores1, bot1)
    elif scores1 > scores0:
      return (scores0, scores1, scores1 - scores0, bot2)
    else:
      return (scores0, scores1, 0,'tie')
Example #2
0
 def smoke_test_robot(self):
     robot1 = q.Robot()
     robot2 = q.Robot()
     runner = Runner.from_robots(robot1, robot2)
     #runner.settings.max_turns = 5
     scores = runner.run()
     assert type(scores) is list
Example #3
0
 def test_runner_from_robots(self):
     print(TestRobot().__class__)
     runner = Runner.from_robots([TestRobot(), TestRobot()])
     self.assertEqual(runner.options, Options())
     runner.settings.max_turns = 1
     runner.options.quiet = 4
     runner.run()
Example #4
0
 def test_runner_from_robots(self):
     print(TestRobot().__class__)
     runner = Runner.from_robots([TestRobot(), TestRobot()])
     self.assertEqual(runner.options, Options())
     runner.settings.max_turns = 1
     runner.options.quiet = 4
     runner.run()
Example #5
0
    def test_robot(self):
        training_robot = Robot()
        robot2 = Robot()
        delta = training_robot.delta_callback
        runner = Runner.from_robots(training_robot, robot2,
                                    delta_callback=delta)
        runner.run()

        self.assertNotEqual(training_robot.qlearning.q, robot2.qlearning.q)
Example #6
0
    def test_runner_delta_callback(self):
        def callback(delta, game_state):
            global called
            called = True
            assert type(delta) is list
            assert type(delta[0]) is rgkit.settings.AttrDict
            assert type(game_state) is gamestate.GameState

        runner = Runner.from_robots(TestRobot(), TestRobot(),
                                    delta_callback=callback)
        runner.run()
        assert called
Example #7
0
    def test_runner_delta_callback(self):
        def callback(delta, game_state):
            global called
            called = True
            assert type(delta) is list
            assert type(delta[0]) is rgkit.settings.AttrDict
            assert type(game_state) is gamestate.GameState

        runner = Runner.from_robots([TestRobot(), TestRobot()],
                                    delta_callback=callback)
        runner.options.quiet = 4
        runner.run()
        assert called
Example #8
0
 def setUp(self):
     # needed to initialize global settings
     Runner.from_robots(Robot(), Robot())
Example #9
0
#!/usr/bin/python
from evolution_bot import ScoredPerceptron, Robot, Collective
from rgkit.run import Runner, Options
from rgkit.game import Player

snapshots = [1000, 2000, 3000, 4000, 5000]

for t in snapshots:
	loadfile0 = "evolved_brains/sim0/red/perceptron_100_25_10_turn%d_gen0.npz" % (t - 1)
	loadfile1 = "evolved_brains/sim0/blue/perceptron_100_25_10_turn%d_gen0.npz" % (t - 1)

	try:
		brain0 = ScoredPerceptron.load(loadfile0)
		pop0 = Collective(1, 0, 0, [brain0])
		robot0 = Robot(pop0)
		player0 = Player(name="red %d" % t, robot=robot0)

		brain1 = ScoredPerceptron.load(loadfile1)
		pop1 = Collective(1, 0, 0, [brain1])
		robot1 = Robot(pop1)
		player1 = Player(name="blu %d" % t, robot=robot1)

		opts = Options(print_info=True)

		r = Runner(players=[player0, player1], options=opts)
		r.run()
	except:
		print "failed to run turn %d" % t
Example #10
0
    def test_runner_from_robots_perf(self):

        runner = Runner.from_robots([TestRobot(), TestRobot()])
        runner.options.n_of_games = 100
        runner.settings.max_turns = 100
Example #11
0
 def test_default_settings(self):
     settings = Runner.default_settings()
     assert settings is not None
     assert settings == rgkit_settings
Example #12
0
    def test_runner_from_robots_perf(self):

        runner = Runner.from_robots([TestRobot(), TestRobot()])
        runner.options.n_of_games = 100
        runner.settings.max_turns = 100
Example #13
0
 def test_default_settings(self):
     settings = Runner.default_settings()
     assert settings is not None
     assert settings == rgkit_settings
Example #14
0
    def reward(my_delta):
        damage_taken = my_delta.hp - my_delta.hp_end
        reward = my_delta.damage_caused - damage_taken
        return reward

    def delta_callback(self, delta, actions, new_gamestate):
        future_game = new_gamestate.get_game_info(self.player_id)
        print "delta_callback calle"
        print("Size of Q: " + str(len(self.qlearning.q.hash_matrix)))
        for (robot_loc, robot) in self.game.robots.items():
            if hasattr(robot, 'robot_id') and robot.robot_id in self.robot_ids:
                action = self.last_action[robot.robot_id]

                for delta_me in delta:
                    state_template = State.from_game(future_game,
                                                     self.player_id)
                    if delta_me['loc'] == robot_loc:
                        future_state = copy.deepcopy(state_template)
                        future_state.robot_loc = delta_me.loc_end
                        reward = self.reward(delta_me)
                        self.qlearning.learn(self.current_state, future_state,
                                             action, reward)


if __name__ == "__main__":
    training_robot = Robot()
    robot2 = Robot()
    runner = Runner.from_robots(training_robot, robot2,
                                delta_callback=training_robot.delta_callback)
    runner.run()
Example #15
0
 def run(self, number_of_games=1):
     runner = Runner(player1_file=self.player_file,
                     player2_file=self.opponent_file,
                     delta_callback=self._delta_callback)
     runner.options.n_of_games = number_of_games
     runner.run()