예제 #1
0
 def test_move_first(self):
     ''' Make sure the AI cannot lose when it goes first by testing all
         possible game combinations. '''
     board = Board()
     player = AIPlayer(True, board)
     # Let the AI go first
     player.next_move()
     self._test_all_moves(board, player)
예제 #2
0
 def _test_all_moves(self, board, player):
     # Try each possible move
     for move in board.open_moves():
         # Try a move, then let the AI go again
         new_board = Board(board.x_first)
         new_board._state = board._state
         new_board.move(move, not player.player)
         if(self._game_over(new_board)):
             continue
         new_player = AIPlayer(player.player, new_board)
         new_player.next_move()
         if(self._game_over(new_board)):
             continue
         self._test_all_moves(new_board, new_player)