Improve pathfinding

This commit is contained in:
2020-10-12 23:25:26 -06:00
parent fa9d597483
commit 83132ab2bb
3 changed files with 7 additions and 29 deletions
+3 -18
View File
@@ -1,7 +1,7 @@
import importlib
import functools
import time
from math import hypot
from math import hypot, sqrt
from astar import AStar
@@ -117,21 +117,6 @@ HALF_PARKOUR = {
(-2, 0, 0): (-1, 0, 0),
}
HYPOT_LUT = {
(0, -1): 1.0,
(0, 1): 1.0,
(1, 0): 1.0,
(-1, 0): 1.0,
(1, -1): 1.414,
(-1, -1): 1.414,
(1, 1): 1.414,
(-1, 1): 1.414,
(0, 2): 2.0,
(-2, 0): 2.0,
(2, 0): 2.0,
(0, -2): 2.0,
}
# larger started being slower
BLOCK_CACHE_SIZE = 2**14
@@ -300,9 +285,9 @@ class Pathfinder(AStar):
def distance_between(self, n1, n2):
(x1, y1, z1) = n1
(x2, y2, z2) = n2
return HYPOT_LUT[x2 - x1, z2 - z1]
return hypot(x2-x1, y2-y1, z2-z1)
def heuristic_cost_estimate(self, n1, n2):
(x1, y1, z1) = n1
(x2, y2, z2) = n2
return hypot(x2 - x1, z2 - z1)
return abs(x2-x1) + abs(y2-y1) + abs(z2-z1)