Skip to content

Commit

Permalink
Fix looping between equidstant pokestops (#3787)
Browse files Browse the repository at this point in the history
* Fix looping between equidstant pokestops

* :D
  • Loading branch information
umbreon222 authored and solderzzc committed Aug 13, 2016
1 parent d4200e9 commit 653ff05
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@
* extink
* Quantra
* pmquan
* umbreon222
33 changes: 20 additions & 13 deletions pokemongo_bot/cell_workers/move_to_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from pokemongo_bot.base_task import BaseTask
from utils import distance, format_dist, fort_details


class MoveToFort(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.last_nearest_fort = None
self.lure_distance = 0
self.lure_attraction = self.config.get("lure_attraction", True)
self.lure_max_distance = self.config.get("lure_max_distance", 2000)
Expand Down Expand Up @@ -96,11 +96,10 @@ def _get_nearest_fort_on_lure_way(self, forts):

lures = filter(lambda x: True if x.get('lure_info', None) != None else False, forts)

dist_lure_me = 0

if (len(lures)):
dist_lure_me = distance(self.bot.position[0], self.bot.position[1],
lures[0]['latitude'],lures[0]['longitude'])
else:
dist_lure_me = 0
dist_lure_me = self.get_distance_from_bot(lures[0])

if dist_lure_me > 0 and dist_lure_me < self.lure_max_distance:

Expand All @@ -112,11 +111,7 @@ def _get_nearest_fort_on_lure_way(self, forts):
fort['longitude'],
lures[0]['latitude'],
lures[0]['longitude'])
dist_fort_me = distance(
fort['latitude'],
fort['longitude'],
self.bot.position[0],
self.bot.position[1])
dist_fort_me = self.get_distance_from_bot(fort)

if dist_lure_fort < dist_lure_me and dist_lure_me > dist_fort_me:
return fort, dist_lure_me
Expand All @@ -129,6 +124,9 @@ def _get_nearest_fort_on_lure_way(self, forts):
else:
return None, 0

def get_distance_from_bot(self, fort):
return distance(self.bot.position[0], self.bot.position[1], fort['latitude'], fort['longitude'])

def get_nearest_fort(self):
forts = self.bot.get_forts(order_by_distance=True)

Expand All @@ -146,7 +144,16 @@ def get_nearest_fort(self):
if (lure_distance > 0):
return next_attracted_pts

if len(forts) > 0:
return forts[0]
else:
if len(forts) <= 0:
return None

nearest_fort = forts[0]

# If last fort moved to and nearest fort are equidistant keep walking
# toward the last fort to avoid looping
if self.last_nearest_fort is not None and self.get_distance_from_bot(self.last_nearest_fort) == self.get_distance_from_bot(nearest_fort):
nearest_fort = self.last_nearest_fort

self.last_nearest_fort = nearest_fort

return nearest_fort

0 comments on commit 653ff05

Please sign in to comment.