def Astartprocessing(self,initalnode,goalnode,freeNodes,ax): #inital point g = plt.Rectangle((initalnode[0].x, initalnode[0].y), initalnode[0].width, initalnode[0].height, facecolor='red') ax.add_patch(g) #goal point g = plt.Rectangle((goalnode[0].x, goalnode[0].y), goalnode[0].width, goalnode[0].height, facecolor='green') ax.add_patch(g) unvisitedlist = OrderedList() stop = False #check meet goal foundpath = False visitedlist = OrderedList() unvisitedlist.add(initalnode[0]) k = 1 while(stop == False and foundpath == False): currnode = unvisitedlist.pop().getData() cost = self.findactualcost(currnode) visitedlist.add(currnode) #check close to goal if(currnode.x <= goalnode[0].x <= currnode.x+currnode.width and currnode.y <= goalnode[0].y <= currnode.y+currnode.height): foundpath = True #find 8 direction's node if(stop == False): nearnodes = self.findAround(currnode,freeNodes) #change actual cost in nearnodes for node in nearnodes: prex = node.x + node.width/2 prey = node.y + node.height/2 currx = currnode.x +currnode.width/2 curry = currnode.x+currnode.height/2 node.gValue = cost + self.getdistance(prex,prey,currx,curry) found = unvisitedlist.search(node) if(found != None): if(found.gValue > node.gValue): found.gValue = node.gValue found.father = currnode else: if(visitedlist.search(node) == None): node.father = currnode unvisitedlist.add(node) if(unvisitedlist == None): stop = True print("there is no path") if(foundpath == True): while (currnode.father!= None): #print("currx = ", currnode.x, "curry = ", currnode.y, "goalx = ", goalnode[0].x, "goaly = ", #goalnode[0].y) g = plt.Rectangle((currnode.x, currnode.y), currnode.width, currnode.height, facecolor='gray') ax.add_patch(g) currnode = currnode.father
from OrderedList import OrderedList, Node ol = OrderedList() ol.add(1) ol.add(23) print(ol.index(1)) print(ol.length()) ol.add(17) ol.add(58) ol.pop(0) ol.display()