Dobře, přihodim sem kód, díky za zájem.
vstupem do algoritmu je mapa, plus počáteční a koncový bod
pathFound = True
openList = []
closedList = []
heapq.heappush(openList, (1 , start))
start.setOnOpenList(True)
start.setG(0)
while end.getOnClosedList() != True:
if len(openList) > 0:
current = heapq.heappop(openList)[1]
current.setOnClosedList(True)
closedList.append(current)
surrounding = current.getSurroundingNodes()
for next in surrounding:
if((next.getCost() > 0) and (next.getOnClosedList() != True)):
if(next.getOnOpenList() != True):
next.setParent(current)
next.setG(current.getG() + next.getCost())
next.setH(next.calcHeuristicTarget(end))
heapq.heappush(openList, (next.getF(), next))
next.setOnOpenList(True)
else:
if(current.getG() > (next.getG() + current.getCost())):
current.setParent(next)
current.setG(next.getG() + current.getCost())
heapq.heappop(openList)
heapq.heappush(openList, (current.getF(), current))
else:
pathFound = False
break
return pathFound, openList, closedList