Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b8eaad0

Browse files
authored
Added octile heuristic option
1 parent 14e0f4f commit b8eaad0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

‎AstarSearch.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /