mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
resume from closest point instead of start
This commit is contained in:
parent
55c867f790
commit
c21a6f06f2
@ -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]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user