from myLib import A_Star, BFS, Classes, DFS, MiscFuncs

#default state if none is generated by user or random generator
#startingState = [ [2,3,0], [1,4,6], [7,5,8] ]
startingState = [ [7,8,3], [4,1,5], [6,0,2] ]
stringSS = MiscFuncs.createStringState(startingState)

blankPosition = []
userChoice = "0"

MiscFuncs.title()

while userChoice not in ("q", "Q"):
    MiscFuncs.UserMenu()
    userChoice = MiscFuncs.getUserInput()    

    if(userChoice is "1"):
        #Call functions to make starting state, string version of state, and find the blank position
        startingState = MiscFuncs.createUserGeneratedState()
        stringSS = MiscFuncs.createStringState(startingState)
        blankPosition = MiscFuncs.findEmptyPosition(startingState) 
        print("Your state was created! Select another option.")
        print("Here is your state:", stringSS)  
    if(userChoice is "2"):
        #Call functions to generate random starting state, string version of state, and find the blank position
        startingState = MiscFuncs.generateRandomState()
        stringSS = MiscFuncs.createStringState(startingState)
        blankPosition = MiscFuncs.findEmptyPosition(startingState)
        print("A state was generated! Select another option.")
        print("Here is your state:", stringSS)
    if(userChoice is "3"):
        myDict = {stringSS: 1}
        myNode = Classes.Node(stringSS, startingState, None, startingState, 0)
        BFS.BFS(myDict, myNode)
    if(userChoice is "4"):
        myDict = {stringSS: 1}
        myNode = Classes.Node(stringSS, startingState, None, startingState, 0)
        DFS.DFS(myDict, myNode)
    if(userChoice is "5"):
        myDict = {stringSS: 1}
        hueristic = MiscFuncs.calculateMisplacedTiles(startingState, 0)
        myNode = Classes.Node(stringSS, startingState, hueristic, startingState, 0)
        A_Star.misplacedTiles(myDict, myNode)
    if(userChoice is "6"):
        myDict = {stringSS: 1}
        hueristic = MiscFuncs.calculateMisplacedTiles(startingState, 0)
        myNode = Classes.Node(stringSS, startingState, hueristic, startingState, 0)
        A_Star.manhattanDistance(myDict, myNode)
    if(userChoice in ("q", "Q")):
        exit