def gameOver(parentState=None): ''' Handles what to do when a game ends (either if won, cap is reached, all states are investigated -- an almost impossibility --, or user quits via KeyboardInterrupt). If game is won, will display the game after every subsequent move till the end. If game is lost, will ask users if they would like to see the closest state to solved. ''' isWon = True if not parentState: # only called with an argument when game is won (parentState=solve) print('Game could not be solved :(') toContinue = input('See the best the program could do? (y or n): ') if toContinue is not 'y': return None isWon = False parentState = S.findLowestState(statesToCheck.union\ (statesChecked), S.hFunctionBasic) # search through set of states for one that produces lowest value # for a given function. Reduce is much more expensive for time. # Using hFunctionBasic will find state with most foundation cards answerLst = S.constructPath(parentState, parentAndPathDict) # take a state and a dictionary linking states to ancestors, produce a # list of all moves till parentState. totalTime = time() - timeA numOfMoves = len(answerLst) statesEval = counter S.remakeGame(firstState, answerLst) # plays a whole game given list of moves and initial state print(f'Number of moves in solution: {numOfMoves}') print(f'Total time: {totalTime} seconds') print(f'States evaluated: {counter}') return answerLst
def gameOver(parentState=None): isWon = True if not parentState: print('Game could not be solved :(') toContinue = input('See the best the program could do? (y or n): ') if toContinue is not 'y': return None isWon = False parentState = S.findLowestState(statesToCheck.union\ (statesChecked), S.hFunctionBasic) answerLst = S.constructPath(parentState, parentAndPathDict) totalTime = time() - timeA numOfMoves = len(answerLst) statesEval = counter S.remakeGame(firstState, answerLst) print(f'Number of moves in solution: {numOfMoves}') print(f'Total time: {totalTime} seconds') print(f'States evaluated: {counter}') return answerLst