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

[Feature] added keep pokemon for batch evolution #2255

Merged
merged 7 commits into from
Aug 2, 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
5 changes: 5 additions & 0 deletions configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
"// any": {"keep_best_iv": 3},
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {},
"// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3}
"// Example of keeping as many Zubat as you have candy to evolve,
"// Zubat": {"keep_for_evo": true}
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat and on top as many Zubat
as you have candy to evolve:": {},
"// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3, "keep_for_evo": true}
},
"vips" : {
"Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate!": {},
Expand Down
5 changes: 5 additions & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
"// any": {"keep_best_iv": 3},
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {},
"// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3}
"// Example of keeping as many Zubat as you have candy to evolve,
"// Zubat": {"keep_for_evo": true}
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat and on top as many Zubat
as you have candy to evolve:": {},
"// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3, "keep_for_evo": true}
},
"vips" : {
"Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate!": {},
Expand Down
5 changes: 5 additions & 0 deletions configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
"any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"},
"// Example of always catching Rattata:": {},
"// Rattata": { "always_catch" : true }
"// Example of keeping as many Zubat as you have candy to evolve,
"// Zubat": {"keep_for_evo": true}
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat and on top as many Zubat
as you have candy to evolve:": {},
"// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3, "keep_for_evo": true}
},
"release": {
"any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"},
Expand Down
105 changes: 72 additions & 33 deletions pokemongo_bot/cell_workers/transfer_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
from pokemongo_bot import logger
from pokemongo_bot.human_behaviour import action_delay
from pokemongo_bot.cell_workers.base_task import BaseTask
from pokemongo_bot.cell_workers.utils import get_candies


class TransferPokemon(BaseTask):
def work(self):
pokemon_groups = self._release_pokemon_get_groups()
candies = get_candies(self.bot)
evolvable = 0
for pokemon_id in pokemon_groups:
group = pokemon_groups[pokemon_id]

if len(group) > 0:
pokemon_name = self.bot.pokemon_list[pokemon_id - 1]['Name']
keep_best, keep_best_cp, keep_best_iv = self._validate_keep_best_config(pokemon_name)
keep_best, keep_best_cp, keep_best_iv, keep_for_evo = self._validate_keep_best_config(pokemon_name)

if keep_best:
best_pokemon_ids = set()
Expand All @@ -33,41 +37,74 @@ def work(self):
order_criteria = 'iv'

# remove best pokemons from all pokemons array
all_pokemons = group
best_pokemons = []
best_pokemon = []
for best_pokemon_id in best_pokemon_ids:
for pokemon in all_pokemons:
for pokemon in group:
if best_pokemon_id == pokemon['pokemon_data']['id']:
all_pokemons.remove(pokemon)
best_pokemons.append(pokemon)

transfer_pokemons = [pokemon for pokemon in all_pokemons
if self.should_release_pokemon(pokemon_name,
pokemon['cp'],
pokemon['iv'],
True)]
group.remove(pokemon)
best_pokemon.append(pokemon)

if transfer_pokemons:
logger.log("Keep {} best {}, based on {}".format(len(best_pokemons),
if len(best_pokemon) > 0:
logger.log("Keep {} best {}, based on {}".format(len(best_pokemon),
pokemon_name,
order_criteria), "green")
for best_pokemon in best_pokemons:
for best_pokemon in best_pokemon:
logger.log("{} [CP {}] [Potential {}]".format(pokemon_name,
best_pokemon['cp'],
best_pokemon['iv']), 'green')

logger.log("Transferring {} pokemon".format(len(transfer_pokemons)), "green")
high_pokemon = []
for pokemon in group:
if self.should_release_pokemon(pokemon_name, pokemon['cp'], pokemon['iv']):
group.remove(pokemon)
high_pokemon.append(pokemon)
if len(high_pokemon) > 0:
logger.log("Keep {} {}, based on cp/iv criteria".format(len(high_pokemon),
pokemon_name), "green")
for high_pokemon in high_pokemon:
logger.log("{} [CP {}] [Potential {}]".format(pokemon_name,
high_pokemon['cp'],
high_pokemon['iv']), 'green')

if keep_for_evo and len(group) > 0:
if 'Previous evolution(s)' in self.bot.pokemon_list[pokemon_id - 1]:
logger.log(
'{} has previous evolution stages. This focuses on 1st stage because they use less '
'candy'.format(pokemon_name), 'red')
continue

if candies == {}:
logger.log("Api call for candies failed, try again")
return
candy = candies[pokemon_id]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pokemon with 2 evolutions always use candy of the first kind of pokemon.
We have two solutions use the ['Next Evolution Requirements']['Name'] to order candies array (as my PR #2244 ). Or add the Evolution candy family in the JSON used for pokemon_list variable

Copy link
Contributor Author

@MFizz MFizz Aug 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achretien Ah yes I didn't think of that. In my mind the best solution would be only to include pokemon with 2 evolutionsteps possible. The normal use case would be mass evolution with lucky egg for exp. And in this case 1st stage evolutions would be preferable because they use less candy.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should ask bot masters :).
In this case I will add an option in my PR, I currently evolve pokemon best evolution first.
In this case I will burn all the candies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 'Next Evolution Requirements' in self.bot.pokemon_list[pokemon_id - 1]:
req_candy = self.bot.pokemon_list[pokemon_id - 1]['Next Evolution Requirements']['Amount']
num_keep = (len(group) + candy) / (req_candy + 1)

if len(group) > num_keep:
group.sort(key=lambda x: x['iv'], reverse=True)
evo_pokemon = group[:num_keep]
group = group[num_keep:]
else:
evo_pokemon = group
group = []

evolvable += len(evo_pokemon)
if len(evo_pokemon) > 0:
logger.log("Keep {} {}, for evolution - {} candies".format(len(evo_pokemon),
pokemon_name, candy), "green")
for evo_pokemon in evo_pokemon:
logger.log("{} [CP {}] [Potential {}]".format(pokemon_name,
evo_pokemon['cp'],
evo_pokemon['iv']), 'green')

logger.log("Transferring {} {}".format(len(group), pokemon_name), "green")

for pokemon in transfer_pokemons:
self.release_pokemon(pokemon_name, pokemon['cp'], pokemon['iv'], pokemon['pokemon_data']['id'])
else:
group = sorted(group, key=lambda x: x['cp'], reverse=True)
for item in group:
pokemon_cp = item['cp']
pokemon_potential = item['iv']
for pokemon in group:
self.release_pokemon(pokemon_name, pokemon['cp'], pokemon['iv'], pokemon['pokemon_data']['id'])

if self.should_release_pokemon(pokemon_name, pokemon_cp, pokemon_potential):
self.release_pokemon(pokemon_name, item['cp'], item['iv'], item['pokemon_data']['id'])
logger.log("{} pokemon transferred total. {} evolutions ready (based on pokemons additional to the ones kept"
" with cp/iv criteria)".format(len(group), evolvable), "green")

def _release_pokemon_get_groups(self):
pokemon_groups = {}
Expand Down Expand Up @@ -126,15 +163,16 @@ def get_pokemon_potential(self, pokemon_data):
continue
return round((total_iv / 45.0), 2)

def should_release_pokemon(self, pokemon_name, cp, iv, keep_best_mode = False):
def should_release_pokemon(self, pokemon_name, cp, iv):
release_config = self._get_release_config_for(pokemon_name)

if (keep_best_mode
and not release_config.has_key('never_release')
and not release_config.has_key('always_release')
and not release_config.has_key('release_below_cp')
and not release_config.has_key('release_below_iv')):
return True
release_strings = ['never_release', 'always_release', 'release_below_cp', 'release_below_iv']
keep_strings = ['keep_best_cp', 'keep_best_iv']
if not any(x in release_config for x in release_strings):
if any(x in release_config for x in keep_strings):
return True
else:
return False

cp_iv_logic = release_config.get('logic')
if not cp_iv_logic:
Expand Down Expand Up @@ -201,6 +239,7 @@ def _validate_keep_best_config(self, pokemon_name):

keep_best_cp = release_config.get('keep_best_cp', 0)
keep_best_iv = release_config.get('keep_best_iv', 0)
keep_for_evo = release_config.get('keep_for_evo', False)

if keep_best_cp or keep_best_iv:
keep_best = True
Expand All @@ -221,4 +260,4 @@ def _validate_keep_best_config(self, pokemon_name):
if keep_best_cp == 0 and keep_best_iv == 0:
keep_best = False

return keep_best, keep_best_cp, keep_best_iv
return keep_best, keep_best_cp, keep_best_iv, keep_for_evo
11 changes: 11 additions & 0 deletions pokemongo_bot/cell_workers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,14 @@ def find_biggest_cluster(radius, points, order=None):
return {'latitude': best_coord[0], 'longitude': best_coord[1], 'num_points': len(max_clique)}
else:
return None


def get_candies(bot):
response_dict = bot.get_inventory()
inv = response_dict.get("responses", {}).get("GET_INVENTORY", {}).get("inventory_delta").get("inventory_items")
candies = {}
for item in inv:
candy = item.get("inventory_item_data", {}).get("candy", {})
if candy != {}:
candies[candy['family_id']] = candy['candy']
return candies