Exemple #1
0
def getRandomNonTerminalTicTacToeState():
    ttt = TicTacToe(4)
    randomDepth = randint(0, 15)
    for depth in range(randomDepth):
        if not ttt.is_victory():
            ttt.make_move(getRandomAction(ttt.get_possible_moves()))
    if ttt.is_victory():
        ttt.undo_move()
    return ttt
Exemple #2
0
 def test_undo_move_1(self):
     tictactoe = TicTacToe(4)
     action_sequence = [(0, 0), (3, 0), (1, 1), (2, 1), (2, 2), (1, 2),
                        (3, 2), (0, 3)]
     tictactoe.initialize_game_matrix_with_action_sequence(action_sequence)
     tictactoe.undo_move()
     expected_game_matrix = np.matrix([['X', ' ', ' ', ' '],
                                       [' ', 'X', 'O', ' '],
                                       [' ', 'O', 'X', ' '],
                                       ['O', ' ', 'X', ' ']])
     self.assertTrue((expected_game_matrix == tictactoe.game_matrix).all())
Exemple #3
0
 def test_undo_move_3(self):
     tictactoe = TicTacToe(4)
     tictactoe.make_move((0, 0))
     tictactoe.make_move((1, 0))
     tictactoe.make_move((0, 1))
     tictactoe.make_move((2, 0))
     tictactoe.make_move((0, 3))
     tictactoe.undo_move()
     tictactoe.undo_move()
     action_sequence = [(0, 0), (1, 0), (0, 1)]
     expected_tictactoe_game = TicTacToe(4)
     expected_tictactoe_game.initialize_game_matrix_with_action_sequence(
         action_sequence)
     self.assertTrue(
         (expected_tictactoe_game.game_matrix == tictactoe.game_matrix
          ).all())