Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix looping between equidstant pokestops" #3848

Merged
merged 1 commit into from
Aug 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,3 @@
* extink
* Quantra
* pmquan
* umbreon222
33 changes: 13 additions & 20 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,10 +96,11 @@ 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 = self.get_distance_from_bot(lures[0])
dist_lure_me = distance(self.bot.position[0], self.bot.position[1],
lures[0]['latitude'],lures[0]['longitude'])
else:
dist_lure_me = 0

if dist_lure_me > 0 and dist_lure_me < self.lure_max_distance:

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

if dist_lure_fort < dist_lure_me and dist_lure_me > dist_fort_me:
return fort, dist_lure_me
Expand All @@ -124,9 +129,6 @@ 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 @@ -144,16 +146,7 @@ def get_nearest_fort(self):
if (lure_distance > 0):
return next_attracted_pts

if len(forts) <= 0:
if len(forts) > 0:
return forts[0]
else:
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