From c21a6f06f21c700754f9f4057c788a6a9cdaaa70 Mon Sep 17 00:00:00 2001 From: Adam Saudagar Date: Thu, 13 May 2021 14:23:54 +0530 Subject: [PATCH] resume from closest point instead of start --- fishy/engine/fullautofisher/mode/player.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fishy/engine/fullautofisher/mode/player.py b/fishy/engine/fullautofisher/mode/player.py index 8d22d9f..fa25a63 100644 --- a/fishy/engine/fullautofisher/mode/player.py +++ b/fishy/engine/fullautofisher/mode/player.py @@ -1,4 +1,5 @@ import logging +import math import pickle from pprint import pprint @@ -55,6 +56,14 @@ class Player(IMode): log_raise("data not found, can't start") 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): action = self.timeline[self.i]