"""PA2: 7 Little Words Game.

Author Dee A. B. Weikle, Alvin Chao python translation
Version 08-01-2018, 10-28-22
"""
import generator
import terminal_ui
import random
import file_utilities

CLUE_NUM = 7
MIN_WORD_LENGTH = 2


if __name__ == '__main__':    
    solutions = [] * CLUE_NUM
    clues = [] * CLUE_NUM
    answer = ""
    print("Welcome to Seven Little Words - The Text Version")
    
    filename = file_utilities.process_command_line()
    solutions, clues = file_utilities.read_game_data(filename)

    # Create the board and randomize it
    # print(solutions)
    board = generator.word_splicer(solutions)
    random.shuffle(board)
    
    # print(board)
    print("Now that you have initialized a game, let's see it.\n")
    print(generator.clue_to_string(clues))
    print(generator.board_to_string(board))
    
    # play the game
    # for (int currentClue = 0; current_clue < CLUE_NUM; currentClue++) {
    for current_clue in range(0, CLUE_NUM):
        solved = False
        first = int(0)
        second = int(0)   
        while solved is False:
            print(f"Clue {current_clue + 1}: {clues[current_clue]}\n")
            terminal_ui.prompt_n_display_hints(solutions[current_clue])                     
            first = terminal_ui.prompt_for_int("Enter the number of the first slice", CLUE_NUM * 2)
            second = terminal_ui.prompt_for_int("Enter the number of the second slice", CLUE_NUM * 2)
            if (solutions[current_clue] == (board[first - 1] + board[second - 1])):
                solved = True
                board[first - 1] = "-"
                board[second - 1] = "-"
            else:                
                print("Sorry you need to try this clue again.")
            print(generator.board_to_string(board))
        print(f"Congratulations! You solved clue {current_clue + 1}! {solutions[current_clue].upper()}")       
    print("Congratulations! You solved the puzzle!")
    print(generator.clue_to_string(clues))
    # print()
    print(generator.board_to_string(board))
