summaryrefslogtreecommitdiff
path: root/pathfinding.py
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2015-09-04 17:53:35 +0200
committerFlorian Jung <flo@windfisch.org>2015-09-04 17:53:35 +0200
commit40adc37c04f33aca4fc29ca7dbfabac4cfa5b2f0 (patch)
tree4a8e57c16ad017b40fd15f2435a5192268b30ffe /pathfinding.py
parentc323bf3d46d4f29e1fd7ec0d8ba50c0095cab1c6 (diff)
optimize distance function
Diffstat (limited to 'pathfinding.py')
-rw-r--r--pathfinding.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/pathfinding.py b/pathfinding.py
index 5dc7b4f..aac940b 100644
--- a/pathfinding.py
+++ b/pathfinding.py
@@ -121,12 +121,22 @@ class Node:
self.near_wormholes = list(filter(lambda blob : (self.point - blob.point).len() < radius, self.graph.blobs))
def move_cost(self,other):
- dist = distance(self, other)
+ # MUST NOT be called when other not in self.siblings()!
+
+
if not (self.is_in_wormhole_plane or other.is_in_wormhole_plane):
# assert other in siblings(self,grid). otherwise this makes no sense
#return 5*(distance(self, other) + (self.value + other.value)/2)
+ xd, yd = abs(self.point.x-other.point.x), abs(self.point.y-other.point.y)
+ dist=0
+ if xd == 0 or yd == 0:
+ dist = xd+yd
+ else:
+ dist = 1.41*xd
+
return 5*dist + (self.value + other.value)/2
else:
+ dist = distance(self, other)
return max(dist, 5*dist - 500)
def siblings(self):