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

Fix Catch-Filter results in loop when many catchable pokemon is detected #4610

Merged
merged 1 commit into from
Aug 23, 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
20 changes: 16 additions & 4 deletions pokemongo_bot/cell_workers/catch_lured_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@
class CatchLuredPokemon(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.encountered = [None] * 10

def add_encountered(self, pokemon):
self.encountered = self.encountered[1:] + [pokemon['encounter_id']]

def was_encountered(self, pokemon):
if pokemon['encounter_id'] in self.encountered:
return True
return False

def work(self):
lured_pokemon = self.get_lured_pokemon()
if len(lured_pokemon) > 0:
self.catch_pokemon(lured_pokemon[0])

if len(lured_pokemon) > 1:
return WorkerResult.RUNNING
for pokemon in lured_pokemon:
if not self.was_encountered(pokemon):
self.catch_pokemon(pokemon)
self.add_encountered(pokemon)
return WorkerResult.RUNNING

return WorkerResult.SUCCESS

Expand Down
35 changes: 24 additions & 11 deletions pokemongo_bot/cell_workers/catch_visible_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
class CatchVisiblePokemon(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.encountered = [None] * 10

def add_encountered(self, pokemon):
self.encountered = self.encountered[1:] + [pokemon['encounter_id']]

def was_encountered(self, pokemon):
if pokemon['encounter_id'] in self.encountered:
return True
return False

def work(self):
num_catchable_pokemon = 0
if 'catchable_pokemons' in self.bot.cell:
Expand Down Expand Up @@ -45,25 +56,27 @@ def work(self):
'expiration_timestamp_ms': pokemon['expiration_timestamp_ms'],
}
)

self.catch_pokemon(self.bot.cell['catchable_pokemons'].pop(0))
if num_catchable_pokemon > 1:
return WorkerResult.RUNNING
else:
return WorkerResult.SUCCESS
if not self.was_encountered(pokemon):
self.catch_pokemon(pokemon)
self.add_encountered(pokemon)
return WorkerResult.RUNNING

return WorkerResult.SUCCESS

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

if num_catchable_pokemon > 1:
return WorkerResult.RUNNING
else:
return WorkerResult.SUCCESS
for pokemon in self.bot.cell['wild_pokemons']:
if not self.was_encountered(pokemon):
self.catch_pokemon(pokemon)
self.add_encountered(pokemon)
return WorkerResult.RUNNING

return WorkerResult.SUCCESS

def catch_pokemon(self, pokemon):
worker = PokemonCatchWorker(pokemon, self.bot, self.config)
Expand Down