コード例 #1
0
 def test_jump(self):
     search = self.search
     state = parse_state("../../tests/jump.json")
     print(state)
     game = Game('red', state)
     best_action = search.search(game, state)
     self.assertEqual(((0, 0), (2, -2), 'JUMP'), best_action)
コード例 #2
0
 def test_eat_green(self):
     search = self.search
     state = parse_state("../../tests/eat_green.json")
     print(state)
     game = Game('red', state)
     best_action = search.search(game, state)
     self.assertTupleEqual(((0, 0), (2, -2), 'JUMP'), best_action)
コード例 #3
0
 def test_initial(self):
     search = self.search
     state = parse_state("../../tests/red_initial_state.json")
     print(state)
     game = Game('red', state)
     best_action = search.search(game, state)
     print(best_action)
コード例 #4
0
 def test_must_exit(self):
     search = self.search
     state = parse_state("../../tests/must_exit_0.json")
     print(state)
     game = Game('red', state)
     best_action = search.search(game, state)
     self.assertEqual(best_action[-1], 'EXIT')
コード例 #5
0
 def test_busy(self):
     search = self.search
     state = parse_state("../../tests/busy.json")
     print(state)
     game = Game('red', state)
     best_action = search.search(game, state)
     print(best_action)
コード例 #6
0
 def test_dominates(self):
     search = self.search
     state = parse_state("../../tests/red_dominates.json")
     print(state)
     game = Game('blue', state)
     best_action = search.search(game, state)
     print(best_action)
コード例 #7
0
 def test_pass(self):
     search = self.search
     state = parse_state("../../tests/pass.json")
     print(state)
     game = Game('blue', state)
     best_action = search.search(game, state)
     self.assertTupleEqual((None, None, 'PASS'), best_action)
コード例 #8
0
 def test_move_not_jump(self):
     search = self.search
     state = parse_state("../../tests/move_not_jump.json")
     print(state)
     game = Game('red', state)
     best_action = search.search(game, state)
     print(best_action)
コード例 #9
0
    def test_avoid_eaten(self):
        search = self.search
        state = parse_state("../../tests/avoid_eaten.json")
        print(state)

        game = Game('red', state)
        best_action = search.search(game, state)
        self.assertTupleEqual(((-2, -1), (-3, 0), 'MOVE'), best_action)
コード例 #10
0
 def test_inch_forward(self):
     search = self.search
     state = parse_state("../../tests/inch_forward.json")
     print(state)
     game = Game('red', state)
     best_action = search.search(game, state)
     print(best_action)
     self.assertEqual(((-3, 2), (-2, 2), 'MOVE'), best_action)
コード例 #11
0
 def test_move(self):
     search = self.search
     state = parse_state("../../tests/move.json")
     print(state)
     game = Game('red', state)
     best_action = search.search(game, state)
     print(best_action)
     self.assertEqual(((1, 0), 'MOVE'), best_action[1:])
コード例 #12
0
 def test_exit(self):
     search = self.search
     state = parse_state("../../tests/please_exit.json")
     print(state)
     game = Game('red', state)
     best_action = search.search(game, state)
     print(best_action)
     self.assertEqual('EXIT', best_action[-1])
コード例 #13
0
node_type = SimpleRLNode2

policy = "greedy"
# policy = "choice"

# debug = 0.001
# debug = 0.1
debug = 0

# explore = 0
# explore = 0.1
# explore = 0.2
# explore = 0.5
explore = 1

# theta = 0.05
# theta = 0.01
theta = 0.005
# theta = 0.001
# theta = 0.0005

gamma = 1
# gamma = 0.99

initial_state = State(Player.start_config, "red")
game = Game("red", initial_state)
agent.td_train(game, initial_state, debug=debug,
               node_type=node_type, policy=policy,
               explore=explore, theta=theta, gamma=gamma)