def heur_alternate(state): # IMPLEMENT '''a better heuristic''' '''INPUT: a sokoban state''' '''OUTPUT: a numeric value that serves as an estimate of the distance of the state to the goal.''' # heur_manhattan_distance has flaws. # Write a heuristic function that improves upon heur_manhattan_distance to estimate distance between the current state and the goal. # Your function should return a numeric value for the estimate of the distance to the goal. h_val = 0 # Default value of Total Manhattan Distance for all boxes # Check Dead Lock First: if checkCornerLock(state) == True: #print("===>Corner Locked", state.index) return 99999 if checkBorderLock(state) == True: #print("===>Border Locked", state.index) return 99999 locked2x2 = check2x2Locked(state) if locked2x2 != set(): for i in locked2x2: if i not in state.storage: #print("===>2x2 Locked", state.index) # print(SokobanState.state_string(state)) return 99999 if checkSpecialCornerLock(state) == True: #print("===>Special Corner Locked", state.index) return 99999 checkProblemCase = checkProblemType(state) if checkProblemCase == 'Regular': h_val = regular_h_f(state) if checkProblemCase == 'UL': h_val = corner_consentrated_storage_h_f(state, 'UL') if checkProblemCase == 'UR': h_val = corner_consentrated_storage_h_f(state, 'UR') if checkProblemCase == 'DL': h_val = corner_consentrated_storage_h_f(state, 'DL') if checkProblemCase =='DR': h_val = corner_consentrated_storage_h_f(state, 'DR') print("====================================") print("Analyzing Case:", state.index) print(SokobanState.state_string(state)) print("box:", h_val) return h_val
while currentTime < stopTime: solution = searchEngine.search(stopTime-currentTime, costBound) #Apply Search Engine to get solution if solution != False: #If solution find before time limit print("new gval is" , solution.gval) if solution.gval < costBound[0]: #Compair Current Solution g_val to so far best solution g_val bestSolutionSoFar = solution #If better, replace so far best solution costBound = (bestSolutionSoFar.gval, 99999, 99999) #replace so far best solution's gval and compair later g val with this g val for pruning elif solution == False: print("final:") return bestSolutionSoFar currentTime = os.times()[0] #Update current time for next loop return bestSolutionSoFar ######################################### ##### For Test ######### ######################################### counter = 0 for i in PROBLEMS: print("Checking Problem #",counter) print(SokobanState.state_string(i)) print(checkProblemType(i)) print("===============") counter = counter +1
if(state.width-1,state.height-2) in state.boxes: if (((state.width-2,state.height-1) not in state.storage) or ((state.width-1,state.height-2) not in state.storage)) and ((state.width-1,state.height -1) not in state.robots): print("Special Corner Lock!") return True return caseCornerLocked ######################################### ##### For Test ######### ######################################### print(SokobanState.state_string(PROBLEMS[18])) print("Width,x =", a.width) print("Height,y =", a.height) print(checkBorderLock(a)) """ counter = 0 for a in PROBLEMS: print("Check Problem #:",counter) print(SokobanState.state_string(a)) print("Width,x =", a.width) print("Height,y =", a.height) print(checkProblemType(a)) print("=============================")