Exemple #1
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
Exemple #2
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()
Exemple #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()
Exemple #4
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)
Exemple #5
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
Exemple #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.options.quiet = 4
        runner.run()
        assert called
Exemple #7
0
 def setUp(self):
     # needed to initialize global settings
     Runner.from_robots(Robot(), Robot())
Exemple #8
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
Exemple #9
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
Exemple #10
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()