summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2015-08-18 17:57:08 +0200
committerFlorian Jung <flo@windfisch.org>2015-08-18 17:57:08 +0200
commitb5655690e849b2605a7e092a26f05b6d0dd4a313 (patch)
treecfac84c3f30779d5c2ec060164f0cddaa3b0a897
parentf9e8d80441902561f3e7d1f1e46588543f7e5535 (diff)
s/manhattan/euclidic distance/g
-rw-r--r--pathfinding.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/pathfinding.py b/pathfinding.py
index 662ecfe..076213c 100644
--- a/pathfinding.py
+++ b/pathfinding.py
@@ -1,5 +1,6 @@
from gui import marker, marker_updated
import gui
+import math
# A* code taken and adapted from https://gist.github.com/jamiees2/5531924
@@ -17,15 +18,15 @@ class Node:
# assert other in siblings(self,grid). otherwise this makes no sense
# assert that siblings are only in horizontal or vertical directions. otherwise
# someone must replace the number "1" by appropriate distances
- return manhattan(self, other) + (self.value + other.value)/2
+ return distance(self, other) + (self.value + other.value)/2
def siblings(point,grid):
x,y = point.point_in_grid
links = [grid[d[0]][d[1]] for d in [(x-1, y),(x,y - 1),(x,y + 1),(x+1,y)]]
return [link for link in links if link.value != None]
-def manhattan(point,point2):
- return abs(point.point[0] - point2.point[0]) + abs(point.point[1]-point2.point[1])
+def distance(point,point2):
+ return math.sqrt((point.point[0] - point2.point[0])**2 + (point.point[1]-point2.point[1])**2)
def aStar(start, goal, grid):
print("aStar("+str(start.point)+"="+str(start.point_in_grid)+", "+str(goal.point)+"="+str(goal.point_in_grid)+")")
@@ -65,7 +66,7 @@ def aStar(start, goal, grid):
else:
#If it isn't in the open set, calculate the G and H score for the node
node.G = current.G + current.move_cost(node)
- node.H = manhattan(node, goal)
+ node.H = distance(node, goal)
node.parent = current
openset.add(node)