Skip to content

Commit

Permalink
Refactoring function to get forts (#1578)
Browse files Browse the repository at this point in the history
* Refactoring function to get forts

* Optionally sort by distance
  • Loading branch information
elicwhite authored and douglascamata committed Jul 29, 2016
1 parent a1433f2 commit 029df03
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
17 changes: 16 additions & 1 deletion pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def tick(self):
return

self.navigator.take_step()

self.tick_count +=1

def get_meta_cell(self):
Expand Down Expand Up @@ -561,3 +561,18 @@ def get_player_info(self):
logger.log(
'Pokemon Captured: {pokemons_captured}'.format(**playerdata) +
' | Pokestops Visited: {poke_stop_visits}'.format(**playerdata), 'cyan')

def get_forts(self, order_by_distance=False):
forts = [fort
for fort in self.cell['forts']
if 'latitude' in fort and 'type' in fort]

if order_by_distance:
forts.sort(key=lambda x: distance(
self.position[0],
self.position[1],
x['latitude'],
x['longitude']
))

return forts
36 changes: 13 additions & 23 deletions pokemongo_bot/cell_workers/spin_nearest_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,16 @@ def should_run(self):
return self.config.spin_forts and enough_space

def get_nearest_fort(self):
if 'forts' in self.cell:
# Only include those with a lat/long
forts = [fort
for fort in self.cell['forts']
if 'latitude' in fort and 'type' in fort]
gyms = [gym for gym in self.cell['forts'] if 'gym_points' in gym]

# Remove stops that are still on timeout
forts = filter(lambda x: x["id"] not in self.fort_timeouts, forts)

# Remove all forts which were spun in the last ticks to avoid circles if set
if self.config.avoid_circles:
forts = filter(lambda x: x["id"] not in self.recent_forts, forts)

# Sort all by distance from current pos- eventually this should
# build graph & A* it
forts.sort(key=lambda x: distance(self.position[
0], self.position[1], x['latitude'], x['longitude']))

if len(forts) > 0:
return forts[0]
else:
return None
forts = self.bot.get_forts()

# Remove stops that are still on timeout
forts = filter(lambda x: x["id"] not in self.fort_timeouts, forts)

# Remove all forts which were spun in the last ticks to avoid circles if set
if self.config.avoid_circles:
forts = filter(lambda x: x["id"] not in self.recent_forts, forts)

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

0 comments on commit 029df03

Please sign in to comment.