resume from closest point instead of start

This commit is contained in:
Adam Saudagar 2021-05-13 14:23:54 +05:30
parent 55c867f790
commit c21a6f06f2

View File

@ -1,4 +1,5 @@
import logging import logging
import math
import pickle import pickle
from pprint import pprint from pprint import pprint
@ -55,6 +56,14 @@ class Player(IMode):
log_raise("data not found, can't start") log_raise("data not found, can't start")
logging.info("starting player") logging.info("starting player")
self.i = self._closest_point()
def _closest_point(self):
current = self.engine.get_coods()
distances = [(i, math.sqrt((target[0] - current[0]) ** 2 + (target[1] - current[1]) ** 2))
for i, (command, target) in enumerate(self.timeline) if command == "move_to"]
return min(distances, key=lambda d: d[1])[0]
def _loop(self): def _loop(self):
action = self.timeline[self.i] action = self.timeline[self.i]