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)
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
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
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
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
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)
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)
def test_apply_move(self, board_empty, ttt, apply_move): board = board_empty state_new = apply_move( board=board, move=ttt.Move(0, 0), player=ttt.Player(1), ).state assert state_new == ( (1, 0, 0, 9, 9), (0, 0, 0, 9, 9), (0, 0, 0, 9, 9), (9, 9, 9, 9, 9), (9, 9, 9, 9, 9)) board = ttt.Board(state_new) state_new = apply_move( board=board, move=ttt.Move(1, 1), player=ttt.Player(2), ).state assert state_new == ( (1, 0, 0, 9, 9), (0, 2, 0, 9, 9), (0, 0, 0, 9, 9), (9, 9, 9, 9, 9), (9, 9, 9, 9, 9)) board = ttt.Board(state_new) state_new = apply_move( board=board, move=ttt.Move(0, 2), player=ttt.Player(1), ).state assert state_new == ( (1, 0, 1, 9, 9), (0, 2, 0, 9, 9), (0, 0, 0, 9, 9), (9, 9, 9, 9, 9), (9, 9, 9, 9, 9)) board = ttt.Board(state_new) state_new = apply_move( board=board, move=ttt.Move(0, 1), player=ttt.Player(2), ).state assert state_new == ( (1, 2, 1, 9, 9), (0, 2, 0, 9, 9), (0, 0, 0, 9, 9), (9, 9, 9, 9, 9), (9, 9, 9, 9, 9)) board = ttt.Board(state_new) state_new = apply_move( board=board, move=ttt.Move(2, 2), player=ttt.Player(1), ).state assert state_new == ( (1, 2, 1, 9, 9), (0, 2, 0, 9, 9), (0, 0, 1, 9, 9), (9, 9, 9, 9, 9), (9, 9, 9, 9, 9)) board = ttt.Board(state_new) state_new = apply_move( board=board, move=ttt.Move(2, 1), player=ttt.Player(2), ).state assert state_new == ( (1, 2, 1, 9, 9), (0, 2, 0, 9, 9), (0, 2, 1, 9, 9), (9, 9, 9, 9, 9), (9, 9, 9, 9, 9))