Improve pathfinding

master
Tanner Collin 4 years ago
parent fa9d597483
commit 83132ab2bb
  1. 5
      game.py
  2. 21
      path.py
  3. 10
      protocol/managers.py

@ -224,8 +224,8 @@ class Game:
solution = path.Pathfinder(self.g.chunks).astar(utils.pint(self.g.pos), utils.pint(self.g.goal))
if solution:
solution = list(solution)
self.g.path = solution
self.g.job.state = self.g.job.stop
#self.g.path = solution
#self.g.job.state = self.g.job.stop
print(len(solution))
print(solution)
print(round(time.time() - start, 3), 'seconds')
@ -550,6 +550,7 @@ class Game:
if entry.value.item_id in items.GAPPLE_ID:
self.g.chat.send('gapple found: ' + str(current_chest)[1:-1])
print('gapple found:', str(current_chest)[1:-1])
def handle_spawn_living(self, packet):

@ -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)

@ -126,22 +126,14 @@ class ChunksManager:
return True
def unload_chunks(self, position):
start = time.time()
x, y, z = utils.pint(position)
player_chunk = (x//16, 0, z//16)
loaded_chunks = list(self.chunks.keys())
count = 0
for chunk in loaded_chunks:
check = (chunk[0], 0, chunk[2])
if utils.phyp_king(player_chunk, check) > 16:
if utils.phyp_king(player_chunk, check) > 20:
del self.chunks[chunk]
count += 1
if count:
print('unloaded', count, 'chunks in', time.time()-start, 's')
class ChunkNotLoadedException(Exception):

Loading…
Cancel
Save