Skip to content

Commit

Permalink
Added further release functionality (#1472)
Browse files Browse the repository at this point in the history
* Added functionality to keep Pokemons based on IV and CP at the same time.

* Fixed example config and _validate_keep_best_config

* Added secondary criteria IV when CP is equal and the contrasting case.

* Removed unused import
  • Loading branch information
MFizz authored and solderzzc committed Jul 28, 2016
1 parent 9938957 commit 9f56b20
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
4 changes: 3 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"// Example of keeping 2 stronger (based on IV) Zubat:": {},
"// Zubat": {"keep_best_iv": 2},
"// Also, it is working with any": {},
"// any": {"keep_best_iv": 3}
"// 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}
}
}
31 changes: 19 additions & 12 deletions pokemongo_bot/cell_workers/pokemon_transfer_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pokemongo_bot.human_behaviour import sleep, action_delay
from pokemongo_bot import logger


class PokemonTransferWorker(object):

def __init__(self, bot):
Expand All @@ -24,21 +25,31 @@ def work(self):
keep_best, keep_best_cp, keep_best_iv = self._validate_keep_best_config(pokemon_name)

if keep_best:
order_criteria = 'cp'
limit = keep_best_cp
best_pokemon_ids = set()
order_criteria = 'none'
if keep_best_cp >= 1:
cp_limit = keep_best_cp
best_cp_pokemons = sorted(group, key=lambda x: (x['cp'], x['iv']), reverse=True)[:cp_limit]
best_pokemon_ids = set(pokemon['pokemon_data']['id'] for pokemon in best_cp_pokemons)
order_criteria = 'cp'

if keep_best_iv >= 1:
order_criteria = 'iv'
limit = keep_best_iv

best_pokemons = sorted(group, key=lambda x: x[order_criteria], reverse=True)[:limit]
iv_limit = keep_best_iv
best_iv_pokemons = sorted(group, key=lambda x: (x['iv'], x['cp']), reverse=True)[:iv_limit]
best_pokemon_ids |= set(pokemon['pokemon_data']['id'] for pokemon in best_iv_pokemons)
if order_criteria == 'cp':
order_criteria = 'cp and iv'
else:
order_criteria = 'iv'

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

if best_pokemons and all_pokemons:
logger.log("Keep {} best {}, based on {}".format(len(best_pokemons),
Expand Down Expand Up @@ -190,10 +201,6 @@ def _validate_keep_best_config(self, pokemon_name):
except ValueError:
keep_best_iv = 0

if keep_best_cp > 1 and keep_best_iv > 1:
logger.log("keep_best_cp and keep_best_iv can't be > 0 at the same time. Ignore it.", "red")
keep_best = False

if keep_best_cp < 0 or keep_best_iv < 0:
logger.log("Keep best can't be < 0. Ignore it.", "red")
keep_best = False
Expand Down

1 comment on commit 9f56b20

@DimaVIII
Copy link

Choose a reason for hiding this comment

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

Nice WORK!

Please sign in to comment.