Exemplo n.º 1
0
def test_minimax():
    new_game = Game()
    new_board = Board()
    new_board.board = [["O", "O", "X"], ["X", "?", "O"], ["?", "?", "X"]]
    new_game.board = new_board
    new_game.player1 = Player(1, "Human", "O")
    new_game.player2 = Player(2, "Computer", "X")
    assert new_game.expert_ai(new_game.board, -math.inf, math.inf,
                              "X") == (1, 2, 1)
Exemplo n.º 2
0
def test_minimax_2():
    new_game = Game()
    new_board = Board()
    new_board.board = [["?", "O", "?"], ["X", "O", "?"], ["O", "X", "X"]]
    new_game.board = copy.deepcopy(new_board)
    new_game.player1 = Player(1, "Human", "O")
    new_game.player2 = Player(2, "Computer", "X")
    assert new_game.expert_ai(new_game.board, -math.inf, math.inf,
                              "X") == (0, 0, 2)
Exemplo n.º 3
0
def test_minimax_3():
    new_game = Game()
    new_board = Board()
    new_board.board = [["?", "?", "?"], ["?", "O", "?"], ["X", "O", "X"]]
    new_game.board = new_board
    new_game.player1 = Player(1, "Human", "O")
    new_game.player2 = Player(2, "Computer", "X")
    new_game.current_turn = new_game.player2
    result = new_game.expert_ai(new_game.board, -math.inf, math.inf, "X")
    assert result[1] == 0
    assert result[2] == 1
Exemplo n.º 4
0
def next_move_and_result(player, board_string):
    new_board = Board()
    flat_board = board_string.split()
    board_array = [flat_board[0:3], flat_board[3:6], flat_board[6:9]]
    new_board.board = board_array
    new_game = Game()
    new_game.board = new_board
    new_game.player1 = Player(1, "Human", "O")
    new_game.player2 = Player(2, "Computer", "X")
    result, best_row, best_column = new_game.expert_ai(new_game.board, player)
    board_array[best_row][best_column] = "*"
    new_board_string = "\n    ".join(" ".join(row) for row in board_array)
    return """
    Position score: {}
    {}
    """.format(result, new_board_string)