game_board = ['?', '?', '?', '?', '?', '?', '?', '?', '?',
              '?', '?', '?']  # a game board
game_pairs = {0: 'dog', 1: 'fish', 2: 'duck', 3: 'lion', 4: 'elephant', 5: 'mouse',
              6: 'dog', 7: 'fish', 8: 'duck', 9: 'lion', 10: 'elephant', 11: 'mouse'}  # pairs
untouchable_positions = []  # empty list


# show the board
def show_board():
    for i in range(0, len(game_board)):
        print(i, end=" ")

    print()
    for place in game_board:
        print(place, end=" ")

    print()


# start a game
def start_game(choice_01, choice_02):
    found_pair = False
    # check for pair
    if game_pairs.get(choice_01) == game_pairs.get(choice_02):
        game_board[choice_01] = 'X'
        game_board[choice_02] = 'X'
        found_pair = True

    # display message according to pair matched or not
    if not found_pair:
        print(
            f"Not a match. Position {choice_01} was {game_pairs.get(choice_01)} and position {choice_02} was {game_pairs.get(choice_02)}")
    else:
        print(f"Well done, that's a match on {game_pairs.get(choice_01)} !")
        untouchable_positions.append(choice_01)
        untouchable_positions.append(choice_02)
        show_board()


if __name__ == '__main__':
    print("Welcome to the pairs game! There are 6 pairs to find")
    print("Here is the board:")
    show_board()  # show the board
    count_for_turns = 0  # count the number of turns

    # loop until board is full of X with pairs
    while True:
        # loop until player choose valid board place
        while True:
            choice_01 = int(input("\nPlease enter guess 1:"))
            # check place is available
            if choice_01 in untouchable_positions:
                print("That one is not available! Please try again\n")
            else:
                break

        # loop until player choose valid board place
        while True:
            choice_02 = int(input("Please enter guess 2:"))
            # check place is available
            if choice_02 in untouchable_positions:
                print("That one is not available! Please try again\n")
            else:
                break

        start_game(choice_01, choice_02)  # start the game again
        # count the number of turns the player has played
        count_for_turns = count_for_turns+1
        print(f"You've had {count_for_turns} turn(s) so far")

        # check if the game is over
        if not '?' in game_board:
            break

    # print the final result
    print(
        f"Well done, you got them all. you did it in {count_for_turns} turns")
