Exemplo n.º 1
0
 def test_mcts_situation_2(self, engine, agent):
     # agent should continue because of good dice
     dice_ = engine.Die(5), engine.Die(5)
     board = engine.Board(state=(0, 4, 50), dice=dice_)
     game = engine.init_game(board=board)
     move = agent.next_move(game)
     assert move == 'c'
Exemplo n.º 2
0
 def test_mcts_situation_1(self, engine, agent):
     # agent should reroll because of bad dice
     dice_ = engine.Die(2), engine.Die(2)
     board = engine.Board(state=(0, 4, 50), dice=dice_)
     game = engine.init_game(board=board)
     move = agent.next_move(game)
     assert move == 'r'
Exemplo n.º 3
0
 def test_mcts_situation_3(self, engine, agent):
     # agent should make the wining move of leaving exactly one stone
     board = engine.Board(state=(0, 1, 9))
     game = engine.init_game(board=board)
     move = agent.next_move(game)
     expected = engine.Move(2, 9)
     assert move == expected
Exemplo n.º 4
0
 def test_mcts_situation_3(self, engine, agent):
     # even though the agent has a good roll, it should reroll
     # because it can only win with at least 11
     dice_ = engine.Die(5), engine.Die(5)
     board = engine.Board(state=(39, 49, 50), dice=dice_)
     game = engine.init_game(board=board)
     move = agent.next_move(game)
     assert move == 'r'
Exemplo n.º 5
0
 def test_mcts_situation_2(self, engine, agent2):
     # player 2 should make the winning move
     board = engine.Board(state=((1, 1, 0, 9, 9), (0, 1, 0, 9, 9),
                                 (0, 2, 2, 9, 9), (9, 9, 9, 9, 9), (9, 9, 9,
                                                                    9, 9)))
     game = engine.init_game(board=board, player_idx=1)
     move = agent2.next_move(game)
     expected = engine.Move(2, 0)
     assert move == expected
Exemplo n.º 6
0
 def test_mcts_situation_4(self, engine, agent):
     # similar situation as the last one but since there is still
     # some way left before the game ends, the agent should keep
     # the good 10 this time
     dice_ = engine.Die(5), engine.Die(5)
     board = engine.Board(state=(39, 49, 100), dice=dice_)
     game = engine.init_game(board=board)
     move = agent.next_move(game)
     assert move == 'c'
Exemplo n.º 7
0
 def test_mcts_situation_5(self, engine, agent):
     # agent should force a winning position by removing 1 stone
     # from heap 2, which leaves (1, 1, 1), which leads to a
     # winning position
     board = engine.Board(state=(1, 1, 2))
     game = engine.init_game(board=board)
     move = agent.next_move(game)
     expected = engine.Move(2, 1)
     assert move == expected
Exemplo n.º 8
0
 def test_mcts_situation_1(self, engine, agent1):
     # player 1 should make the wining move
     board = engine.Board(state=((1, 1, 0, 9, 9), (0, 0, 0, 9, 9),
                                 (0, 2, 2, 9, 9), (9, 9, 9, 9, 9), (9, 9, 9,
                                                                    9, 9)))
     game = engine.init_game(board=board)
     move = agent1.next_move(game)
     expected = engine.Move(0, 2)
     assert move == expected
Exemplo n.º 9
0
 def test_mcts_situation_3(self, engine, agent2):
     # player 2 shouldn't move 0,2 or 2,0 since this will lead to a
     # winning move for player 1 by placing on the opposite side
     board = engine.Board(state=((1, 0, 0, 9, 9), (0, 2, 0, 9, 9),
                                 (0, 0, 1, 9, 9), (9, 9, 9, 9, 9), (9, 9, 9,
                                                                    9, 9)))
     game = engine.init_game(board=board, player_idx=1)
     move = agent2.next_move(game)
     assert move != engine.Move(0, 2)
     assert move != engine.Move(2, 0)
Exemplo n.º 10
0
 def test_mcts_situation_5(self, engine, agent):
     # agent should keep because it will reach 48, which is a
     # guaranteed win next round. There is no risk since the
     # opponent cannot win this round. If the agent rerolls,
     # however, it could still lose with some bad rolls (e.g. d1,d1
     # and d1,d1).
     dice_ = engine.Die(3), engine.Die(2)
     board = engine.Board(state=(43, 37, 50), dice=dice_)
     game = engine.init_game(board=board)
     move = agent.next_move(game)
     assert move == 'c'
Exemplo n.º 11
0
 def test_mcts_situation_1(self, engine, agent, ranger_cls, melee_cls):
     # should attack damaged Ranger
     p1 = engine.Player(1)
     p2 = engine.Player(2)
     row0 = (ranger_cls(owner=p1), ranger_cls(owner=p1),
             melee_cls(owner=p1), None, None)
     row1 = (
         ranger_cls(owner=p2),
         ranger_cls(owner=p2, hp=1),  # damaged Ranger
         ranger_cls(owner=p2),
         None,
         None)
     board = engine.Board(
         state=row0 + row1,
         active_idx=1,
     )
     game = engine.init_game(board=board)
     move = agent.next_move(game)
     assert move == engine.Move(6)
Exemplo n.º 12
0
    def test_mcts_situation_2(self, engine, agent, ranger_cls, melee_cls):
        # should attack buffed Ranger
        p1 = engine.Player(1)
        p2 = engine.Player(2)

        ranger_buffed = ranger_cls(
            owner=p2,
            buffs=(engine.DamageBuff(round=1), engine.DamageBuff(round=1)),
        )

        row0 = (ranger_cls(owner=p1), ranger_cls(owner=p1),
                melee_cls(owner=p1), None, None)
        row1 = (ranger_buffed, ranger_cls(owner=p2), ranger_cls(owner=p2),
                None, None)
        board = engine.Board(
            state=row0 + row1,
            active_idx=2,
        )
        game = engine.init_game(board=board)
        move = agent.next_move(game)
        assert move == engine.Move(5)
Exemplo n.º 13
0
 def test_winner_row(self, ttt, board_row_win, determine_winner):
     game = ttt.init_game()
     game = dataclasses.replace(game, board=board_row_win)
     assert determine_winner(game) == 1
Exemplo n.º 14
0
 def test_winner_non_empty(self, ttt, board_non_empty, determine_winner):
     game = ttt.init_game()
     game = dataclasses.replace(game, board=board_non_empty)
     assert determine_winner(game) is None
Exemplo n.º 15
0
 def test_no_moves(self, ttt, board_row_win, get_legal_moves):
     game = ttt.init_game(board=board_row_win)
     assert get_legal_moves(game) == []
Exemplo n.º 16
0
 def test_moves_board_non_empty(self, ttt, board_non_empty, get_legal_moves):
     game = ttt.init_game(board=board_non_empty)
     assert get_legal_moves(game) == [(0, 0)]
Exemplo n.º 17
0
 def test_moves_board_empty(self, ttt, board_empty, get_legal_moves):
     game = ttt.init_game(board=board_empty)
     assert set(get_legal_moves(game)) == ttt.POSSIBLE_MOVES
Exemplo n.º 18
0
 def test_winner_tied(self, ttt, board_tied, determine_winner):
     game = ttt.init_game()
     game = dataclasses.replace(game, board=board_tied)
     assert determine_winner(game) == -1
Exemplo n.º 19
0
def game():
    from aidoodle.games.tictactoe import init_game
    return init_game()