Exemplo n.º 1
0
 def test_make_move_horizontal_right_and_vertical_top(self):
     expected_game_matrix = np.matrix(
         [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
          [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
          [' ', ' ', ' ', 'W', ' ', ' ', ' ', ' '],
          [' ', ' ', ' ', 'W', 'B', 'B', ' ', ' '],
          [' ', ' ', ' ', 'W', 'B', ' ', ' ', ' '],
          [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
          [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
          [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']])
     reversi = Reversi()
     reversi.make_move((3, 5))
     reversi.make_move((2, 3))
     self.assertTrue((reversi.game_matrix == expected_game_matrix).all())
Exemplo n.º 2
0
def getRandomTerminalReversiState():
    reversi = Reversi()
    while not reversi.is_victory():
        playerToMove = reversi.player_to_move()
        if playerToMove != 'Game Over':
            possible_moves = reversi.suggest_moves(playerToMove)
            randomAction = getRandomAction(possible_moves)
            reversi.make_move(randomAction[0])
    return reversi
Exemplo n.º 3
0
def getRandomNonTerminalReversiState():
    reversi = Reversi()
    randomDepth = randint(0, 63)
    for depth in range(randomDepth):
        playerToMove = reversi.player_to_move()
        if not reversi.is_victory():
            possible_moves = reversi.suggest_moves(playerToMove)
            randomAction = getRandomAction(possible_moves)
            reversi.make_move(randomAction[0])
    return reversi
Exemplo n.º 4
0
 def test_make_move_diagonal_bottom_left(self):
     expected_game_matrix = np.matrix(
         [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
          [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
          [' ', ' ', 'B', 'W', ' ', 'W', ' ', ' '],
          [' ', ' ', ' ', 'B', 'W', 'B', ' ', ' '],
          [' ', ' ', 'B', 'W', 'B', ' ', ' ', ' '],
          [' ', ' ', 'W', ' ', ' ', ' ', ' ', ' '],
          [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
          [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']])
     reversi = Reversi()
     reversi.make_move((3, 5))
     reversi.make_move((2, 3))
     reversi.make_move((2, 2))
     reversi.make_move((2, 5))
     reversi.make_move((4, 2))
     reversi.make_move((5, 2))
     self.assertTrue((reversi.game_matrix == expected_game_matrix).all())
Exemplo n.º 5
0
def processReversiAction(reversiState=Reversi()):
    if not reversiState.is_victory():
        randomReversiAction = getRandomAction(reversiState.suggest_moves(reversiState.player_to_move()))
        reversiState.make_move(randomReversiAction[0])
Exemplo n.º 6
0
 def test_count_of_black_tokens_with_adjected_free_space(self):
     reversi = Reversi()
     reversi.make_move((3, 5))
     reversi.make_move((2, 3))
     reversi.make_move((2, 2))
     reversi.make_move((2, 5))
     reversi.make_move((4, 2))
     reversi.make_move((5, 2))
     reversi.make_move((2, 4))
     reversi.make_move((1, 3))
     reversi.make_move((3, 2))
     reversi.make_move((4, 6))
     reversi.make_move((2, 6))
     reversi.make_move((1, 6))
     reversi.make_move((0, 0))
     reversi.make_move((1, 1))
     reversi.make_move((0, 2))
     self.assertEqual(reversi.count_black_tokens_with_adjacent_free_space(),
                      10)
Exemplo n.º 7
0
    def test_undo_move(self):
        expected_game_matrix = np.matrix(
            [[' ', ' ', 'B', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', 'B', ' ', 'B', 'W', ' '],
             [' ', 'W', 'B', 'W', 'B', 'B', 'B', ' '],
             ['W', 'W', 'W', 'B', 'W', 'B', ' ', ' '],
             [' ', ' ', 'B', 'W', 'B', ' ', 'W', ' '],
             [' ', ' ', 'W', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']])

        reversi = Reversi()
        reversi.make_move((3, 5))
        reversi.make_move((2, 3))
        reversi.make_move((2, 2))
        reversi.make_move((2, 5))

        reversi.make_move((4, 2))
        reversi.make_move((5, 2))
        reversi.make_move((2, 4))
        reversi.make_move((1, 3))

        reversi.make_move((3, 2))
        reversi.make_move((4, 6))
        reversi.make_move((2, 6))
        reversi.make_move((1, 6))

        reversi.make_move((0, 2))
        reversi.make_move((2, 1))
        reversi.make_move((3, 1))
        reversi.make_move((3, 0))

        reversi.make_move((1, 5))
        reversi.make_move((3, 6))
        reversi.make_move((5, 7))
        reversi.make_move((1, 4))

        reversi.make_move((0, 4))
        reversi.make_move((4, 5))
        reversi.make_move((3, 7))
        reversi.make_move((1, 2))

        reversi.make_move((0, 7))
        reversi.make_move((5, 1))
        reversi.make_move((2, 0))
        reversi.make_move((1, 1))

        reversi.make_move((5, 3))
        reversi.make_move((1, 0))
        reversi.make_move((0, 0))
        reversi.make_move((4, 7))

        reversi.make_move((5, 6))
        reversi.make_move((6, 7))
        reversi.make_move((7, 7))
        reversi.make_move((5, 4))

        reversi.make_move((5, 5))
        reversi.make_move((6, 7))
        reversi.make_move((7, 7))
        reversi.make_move((5, 4))

        for i in range(23):
            reversi.undo_move()

        self.assertTrue((reversi.game_matrix == expected_game_matrix).all())
Exemplo n.º 8
0
    def test_count_of_white_tokens_with_adjected_free_space(self):
        reversi = Reversi()
        reversi.make_move((3, 5))
        reversi.make_move((2, 3))
        reversi.make_move((2, 2))
        reversi.make_move((2, 5))

        reversi.make_move((4, 2))
        reversi.make_move((5, 2))
        reversi.make_move((2, 4))
        reversi.make_move((1, 3))

        reversi.make_move((3, 2))
        reversi.make_move((4, 6))
        reversi.make_move((2, 6))
        reversi.make_move((1, 6))

        reversi.make_move((0, 2))
        reversi.make_move((2, 1))
        reversi.make_move((3, 1))
        reversi.make_move((3, 0))

        reversi.make_move((1, 5))
        reversi.make_move((3, 6))
        reversi.make_move((5, 7))
        reversi.make_move((1, 4))

        reversi.make_move((0, 4))
        reversi.make_move((4, 5))
        reversi.make_move((3, 7))
        reversi.make_move((1, 2))

        reversi.make_move((0, 7))
        reversi.make_move((5, 1))
        reversi.make_move((2, 0))
        reversi.make_move((1, 1))

        reversi.make_move((5, 3))
        reversi.make_move((1, 0))
        reversi.make_move((0, 0))
        reversi.make_move((4, 7))

        reversi.make_move((5, 6))
        reversi.make_move((6, 7))
        reversi.make_move((7, 7))
        reversi.make_move((5, 4))

        reversi.make_move((5, 5))
        reversi.make_move((6, 7))
        reversi.make_move((7, 7))
        reversi.make_move((5, 4))

        self.assertEqual(reversi.count_white_tokens_with_adjacent_free_space(),
                         11)
Exemplo n.º 9
0
    def test_make_move_complex_3(self):
        expected_game_matrix = np.matrix(
            [[' ', ' ', 'B', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', 'B', ' ', 'B', 'W', ' '],
             [' ', 'W', 'B', 'W', 'B', 'B', 'B', ' '],
             ['W', 'W', 'W', 'B', 'W', 'B', ' ', ' '],
             [' ', ' ', 'B', 'W', 'B', ' ', 'W', ' '],
             [' ', ' ', 'W', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
             [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']])
        reversi = Reversi()
        reversi.make_move((3, 5))
        reversi.make_move((2, 3))
        reversi.make_move((2, 2))
        reversi.make_move((2, 5))

        reversi.make_move((4, 2))
        reversi.make_move((5, 2))
        reversi.make_move((2, 4))
        reversi.make_move((1, 3))

        reversi.make_move((3, 2))
        reversi.make_move((4, 6))
        reversi.make_move((2, 6))
        reversi.make_move((1, 6))

        reversi.make_move((0, 2))
        reversi.make_move((2, 1))
        reversi.make_move((3, 1))
        reversi.make_move((3, 0))

        reversi.make_move((1, 5))
        self.assertTrue((reversi.game_matrix == expected_game_matrix).all())
Exemplo n.º 10
0
def processAction(reversiState=Reversi()):
    action = alpha_beta_iterative_deepening_search(reversiState)
    reversiState.make_move(action[0][0])