Two heuristics for an 8 puzzle problem GoalNode=[[7,2,4],[5,0,6],[8,3,1]] StartNode=[[0,1,2],[3,4,5],[6,7,8]] temp = [] h1 = -1 h2 = 0 print("Given StartNode is: ",StartNode) print("\n\n\t Given GoalNode is: ",GoalNode) print("\n\n######################################") for i in range(len(StartNode)): for j in range (len(StartNode)): if StartNode[i][j] != GoalNode[i][j]: h1+=1 print("\n\n\t h1 : Number of misplaced tiles =>",h1) print("\n\n######################################") print("\n\nDistances of the tiles from their goal positions are: \n") for i in range(len(StartNode)): for j in range (len(StartNode)): if (StartNode[i][j]==0): pass else: if (GoalNode[0][0] == StartNode[i][j]): temp.append(abs(i-0) + abs(j-0)) print("\t",temp)
Comments
Post a Comment