@@ -128,8 +128,20 @@ def buildGraph(self, filename):
128128 # method for calculating the heuristic (Euclidean Distance)
129129 def heuristic (self , currentNode , targetNode ):
130130
131- return math .sqrt ((currentNode .position [0 ] - targetNode .position [0 ])** 2 + (currentNode .position [1 ] - targetNode .position [1 ])** 2 )
132- # return abs(currentNode.position[0] - targetNode.position[0]) + abs(currentNode.position[1] - targetNode.position[1])
131+ # -------------Octile Heuristic----------------------------
132+ 133+ xVal = abs (currentNode .position [0 ] - targetNode .position [0 ])
134+ yVal = abs (currentNode .position [1 ] - targetNode .position [1 ])
135+ 136+ return max (xVal , yVal ) + ((math .sqrt (2 )- 1 )* min (xVal , yVal ))
137+ 138+ # -------------Octile Heuristic----------------------------
139+ 140+ # -------------Euclidean Heuristic-------------------------
141+ 142+ # return math.sqrt((currentNode.position[0] - targetNode.position[0])**2 + (currentNode.position[1] - targetNode.position[1])**2)
143+ 144+ # -------------Euclidean Heuristic-------------------------
133145
134146 # method for implementing the a star search algorithm
135147 def aStarSearch (self , source , target ):
0 commit comments