# checks if all the lights are turned off.
def checker(lights, num_lights):
    counter = 0

    # we loop through all of the lights to count if all are turned off
    for light in lights:
        if light == "🌚":
            counter = counter + 1
            if counter == num_lights:
                return True

    return False


def start_game():
    print("Lights Out!")

    # get the number of lights from the user
    num_lights = int(input("Enter number of lights: "))

    # make a list filled with the sun emoji
    lights = list(num_lights*"🌞")

    # convert the list into a string then display it on the terminal
    print("".join(lights))

    # save the number of times the user toggles a light
    moves = 0

    # toggle the lights until it's all moon emoji
    while True:
        toggle_index = int(input("Which light should you toggle? [1-10] "))-1

        moves = moves + 1

        if toggle_index < num_lights and toggle_index >= 0 :
            # toggle the chosen index of the user
            if lights[toggle_index] == "🌚":
                lights[toggle_index] = "🌞"
            else:
                lights[toggle_index] = "🌚"

            # toggle the light on the right side of the chosen index
            if toggle_index+1 < num_lights and lights[toggle_index+1] == "🌚":
                lights[toggle_index+1] = "🌞"
            elif toggle_index+1 < num_lights:
                lights[toggle_index+1] = "🌚"

            # toggle the light on the left side of the chosen index
            if toggle_index-1 >= 0 and lights[toggle_index-1] == "🌚":
                lights[toggle_index-1] = "🌞"
            elif toggle_index-1 >= 0:
                lights[toggle_index-1] = "🌚"

        else:
            print(f"The light that you picked doesn't exist. Pick only from 1 to {num_lights}")

        # convert the list into a string then display it on the terminal
        print("".join(lights))

        # this if statement will run when the checker function returns True and it will exit the current loop and go back to the while loop in get_choice function.
        if checker(lights, num_lights):
            print(f"You won! Moves: {moves}")
            break


def get_choice():
    choice = 0

    while(choice != 1 or choice != 2):
        # print the menu
        print("Welcome to Arcade\n[1] Lights Out!\n[2] Exit")

        # ask the user for their choice, i.e., to play the game or exit the game
        choice = int(input("Enter Choice: "))

        # when user wants to play the game, call start_game function. when the user wins, they will be asked again if they want to play again or exit. that's why there's no "break" here.
        if choice == 1:
            start_game()

        elif choice == 2:
            print("Exit Game")
            break

        else:
            print("Invalid choice. Choices: 1 or 2 only.")


if __name__ == "__main__":
    get_choice()

# checks if all the lights are turned off.
def checker(lights, num_lights):
    counter = 0

    # we loop through all of the lights to count if all are turned off
    for light in lights:
        if light == "🌚":
            counter = counter + 1
            if counter == num_lights:
                return True

    return False


def start_game():
    print("Lights Out!")

    # get the number of lights from the user
    num_lights = int(input("Enter number of lights: "))

    # make a list filled with the sun emoji
    lights = list(num_lights*"🌞")

    # convert the list into a string then display it on the terminal
    print("".join(lights))

    # save the number of times the user toggles a light
    moves = 0

    # toggle the lights until it's all moon emoji
    while True:
        toggle_index = int(input("Which light should you toggle? [1-10] "))-1

        moves = moves + 1

        if toggle_index < num_lights and toggle_index >= 0 :
            # toggle the chosen index of the user
            if lights[toggle_index] == "🌚":
                lights[toggle_index] = "🌞"
            else:
                lights[toggle_index] = "🌚"

            # toggle the light on the right side of the chosen index
            if toggle_index+1 < num_lights and lights[toggle_index+1] == "🌚":
                lights[toggle_index+1] = "🌞"
            elif toggle_index+1 < num_lights:
                lights[toggle_index+1] = "🌚"

            # toggle the light on the left side of the chosen index
            if toggle_index-1 >= 0 and lights[toggle_index-1] == "🌚":
                lights[toggle_index-1] = "🌞"
            elif toggle_index-1 >= 0:
                lights[toggle_index-1] = "🌚"

        else:
            print(f"The light that you picked doesn't exist. Pick only from 1 to {num_lights}")

        # convert the list into a string then display it on the terminal
        print("".join(lights))

        # this if statement will run when the checker function returns True and it will exit the current loop and go back to the while loop in get_choice function.
        if checker(lights, num_lights):
            print(f"You won! Moves: {moves}")
            break


def get_choice():
    choice = 0

    while(choice != 1 or choice != 2):
        # print the menu
        print("Welcome to Arcade\n[1] Lights Out!\n[2] Exit")

        # ask the user for their choice, i.e., to play the game or exit the game
        choice = int(input("Enter Choice: "))

        # when user wants to play the game, call start_game function. when the user wins, they will be asked again if they want to play again or exit. that's why there's no "break" here.
        if choice == 1:
            start_game()

        elif choice == 2:
            print("Exit Game")
            break

        else:
            print("Invalid choice. Choices: 1 or 2 only.")


if __name__ == "__main__":
    get_choice()

# checks if all the lights are turned off. # we loop through all of the lights to count if all are turned off # get the number of lights from the user # make a list filled with the sun emoji # convert the list into a string then display it on the terminal # save the number of times the user toggles a light # toggle the lights until it's all moon emoji # toggle the chosen index of the user # toggle the light on the right side of the chosen index # toggle the light on the left side of the chosen index # convert the list into a string then display it on the terminal # this if statement will run when the checker function returns True and it will exit the current loop and go back to the while loop in get_choice function. # print the menu # ask the user for their choice, i.e., to play the game or exit the game # when user wants to play the game, call start_game function. when the user wins, they will be asked again if they want to play again or exit. that's why there's no "break" here.