Skip to content

Commit

Permalink
Keep by best hp max (#4144)
Browse files Browse the repository at this point in the history
* Updated wiki, explain how to use Docker under Windows

* Add keep_best_hp_max to keep pokemon with the best potential hp

* Add example of keep_best_hp_max in config

* Keep best pokemon by custom criteria order

* Correct list of criteria. Add example in config.

* Update documentations for keep custom pokemons

* Replace the important | for the set

* Clean the charmander comment
  • Loading branch information
supercourgette authored and solderzzc committed Aug 18, 2016
1 parent b060c02 commit de0d43f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
6 changes: 4 additions & 2 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,14 @@
"// Rattata": {"always_release": true},
"// Example of keeping 3 stronger (based on CP) Pidgey:": {},
"// Pidgey": {"keep_best_cp": 3},
"// Example of keeping 2 stronger (based on IV) Zubat:": {},
"// Example of keeping 2 best (based on IV) Zubat:": {},
"// Zubat": {"keep_best_iv": 2},
"// Also, it is working with any": {},
"// 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}
"// Zubat": {"keep_best_cp": 2, "keep_best_iv": 3},
"// Example of custom order of static criterion": {},
"// Zubat": {"keep_best_custom": "moveset.defense_perfection, hp_max", "amount":2}
},
"vips" : {
"Any pokemon put here directly force to use Berry & Best Ball to capture, to secure the capture rate!": {},
Expand Down
15 changes: 15 additions & 0 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ If you already have it, it will keep a stronger version and will transfer the a

```"release": {"any": {"keep_best_cp": 2}}```, ```"release": {"any": {"keep_best_cp": 10}}``` - can be any number.

### Keep the best custom pokemon configuration (dev branch)

Define a list of criteria to keep the best Pokemons according to those criteria.

The list of criteria is the following:```'cp','iv', 'iv_attack', 'iv_defense', 'iv_stamina', 'moveset.attack_perfection', 'moveset.defense_perfection', 'hp', 'hp_max'```

####Examples:

- Keep the top 25 Zubat with the best hp_max:

```"release": {"Zubat": {"keep_best_custom": "hp_max", "amount":25}}```
- Keep the top 10 Zubat with the best hp_max and, if there are Zubat with the same hp_max, to keep the one with the highest hp:

```"release": {"Zubat": {"keep_best_custom": "hp_max,hp", "amount":10}}````

## Evolve All Configuration

By setting the `evolve_all` attribute in config.json, you can instruct the bot to automatically
Expand Down
54 changes: 44 additions & 10 deletions pokemongo_bot/cell_workers/transfer_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from pokemongo_bot import inventory
from pokemongo_bot.human_behaviour import action_delay
from pokemongo_bot.base_task import BaseTask
from pokemongo_bot.inventory import Pokemons, Pokemon

from pokemongo_bot.inventory import Pokemons, Pokemon, Attack

class TransferPokemon(BaseTask):
SUPPORTED_TASK_API_VERSION = 1
Expand All @@ -19,10 +18,13 @@ def work(self):
for pokemon_id, group in pokemon_groups.iteritems():
pokemon_name = Pokemons.name_for(pokemon_id)
keep_best, keep_best_cp, keep_best_iv = self._validate_keep_best_config(pokemon_name)

#TODO continue list possible criteria
keep_best_possible_criteria = ['cp','iv', 'iv_attack', 'iv_defense', 'iv_stamina', 'moveset.attack_perfection','moveset.defense_perfection','hp','hp_max']
keep_best_custom, keep_best_criteria, keep_amount = self._validate_keep_best_config_custom(pokemon_name, keep_best_possible_criteria)

best_pokemon_ids = set()
order_criteria = 'none'
if keep_best:
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]
Expand All @@ -36,8 +38,14 @@ def work(self):
if order_criteria == 'cp':
order_criteria = 'cp and iv'
else:
order_criteria = 'iv'

order_criteria = 'iv'
elif keep_best_custom:
limit = keep_amount
best_pokemons = sorted(group, key=lambda x: keep_best_criteria, reverse=True)[:limit]
best_pokemon_ids = set(pokemon.id for pokemon in best_pokemons)
order_criteria = ' and '.join(keep_best_criteria)

if keep_best or keep_best_custom:
# remove best pokemons from all pokemons array
all_pokemons = group
best_pokemons = []
Expand Down Expand Up @@ -76,7 +84,7 @@ def _release_pokemon_get_groups(self):
continue

group_id = pokemon.pokemon_id

if group_id not in pokemon_groups:
pokemon_groups[group_id] = []

Expand Down Expand Up @@ -178,14 +186,40 @@ def _get_release_config_for(self, pokemon):
release_config = {}
return release_config

def _validate_keep_best_config_custom(self, pokemon_name, keep_best_possible_custom):
keep_best = False

release_config = self._get_release_config_for(pokemon_name)
keep_best_custom = release_config.get('keep_best_custom', '')
keep_amount = release_config.get('amount', 0)

if keep_best_custom and keep_amount:
keep_best = True

keep_best_custom = keep_best_custom.split(',')
for _str in keep_best_custom:
if _str not in keep_best_possible_custom:
keep_best = False
break

try:
keep_amount = int(keep_amount)
except ValueError:
keep_best = False

if keep_amount < 0:
keep_best = False

return keep_best, keep_best_custom, keep_amount

def _validate_keep_best_config(self, pokemon_name):
keep_best = False

release_config = self._get_release_config_for(pokemon_name)

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

if keep_best_cp or keep_best_iv:
keep_best = True
try:
Expand All @@ -197,7 +231,7 @@ def _validate_keep_best_config(self, pokemon_name):
keep_best_iv = int(keep_best_iv)
except ValueError:
keep_best_iv = 0

if keep_best_cp < 0 or keep_best_iv < 0:
keep_best = False

Expand Down

4 comments on commit de0d43f

@Foulwerp
Copy link

@Foulwerp Foulwerp commented on de0d43f Aug 18, 2016

Choose a reason for hiding this comment

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

I don't think the sorting is working as it is supposed to. @supercourgette

Captured Cubone CP 187 IV .71 it then released the Cubone CP 422 IV .89 when the higher IV should of been kept. Unless I'm missing something.

2016-08-18 11:47:02,358 [PokemonCatchWorker] [INFO] [pokemon_appeared] A wild Cubone appeared! [CP 187] [Potential 0
2016-08-18 11:47:09,460 [PokemonCatchWorker] [INFO] [threw_pokeball] Great! Used Pokeball, with chance 45.82 (40 lef
2016-08-18 11:47:09,684 [PokemonCatchWorker] [INFO] [pokemon_caught] Captured Cubone! [CP 187] [Potential 0.71] [14/
2016-08-18 11:47:14,993 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Cubone, based on iv and cp
2016-08-18 11:47:15,349 [TransferPokemon] [INFO] [pokemon_release] Exchanged Cubone [CP 422] [IV 0.89] for candy.
        "any": {
            "keep_best_custom": "iv,cp",
            "amount": 2
        },

@Foulwerp
Copy link

Choose a reason for hiding this comment

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

best_pokemons = sorted(group, key=attrgetter(*keep_best_criteria), reverse=True)[:limit]

Now I don't know Python, but after a little bit of research I think this is what we want. Is this wrong, or is there a better way to do this?

@supercourgette
Copy link
Contributor Author

@supercourgette supercourgette commented on de0d43f Aug 18, 2016

Choose a reason for hiding this comment

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

Hi @Foulwerp; that's how I should have test it, with simple ip and cp! I'm going to check it again today with your solution. Thanks for your input 👍 !

@supercourgette
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You were right, and your solution was the good one. Are you sure you don't know Python? :)

Unfortunately, I didn't have enough Pokemons to have some with a similar IV to see if their CP was then classified as expected. It should be (I tested the behavior on a custom script), but it hasn't been tested. In any case thanks a lot, I'm going to commit that.


2016-08-19 11:33:29,690 [PokemonGoBot] [INFO] Pokemon:
2016-08-19 11:33:29,690 [PokemonGoBot] [INFO] #7 Squirtle: (CP 13, IV 0.67)
2016-08-19 11:33:29,690 [PokemonGoBot] [INFO] #10 Caterpie: (CP 14, IV 0.36) | (CP 14, IV 0.24) | (CP 73, IV 0.33) | (CP 109, IV 0.53)
2016-08-19 11:33:29,691 [PokemonGoBot] [INFO] #11 Metapod: (CP 57, IV 0.29)
2016-08-19 11:33:29,691 [PokemonGoBot] [INFO] #13 Weedle: (CP 37, IV 0.56) | (CP 10, IV 0.42)
2016-08-19 11:33:29,693 [PokemonGoBot] [INFO] #16 Pidgey: (CP 10, IV 0.38) | (CP 10, IV 0.58) | (CP 95, IV 0.51)
2016-08-19 11:33:29,694 [PokemonGoBot] [INFO] #17 Pidgeotto: (CP 14, IV 0.29) | (CP 15, IV 0.51)
2016-08-19 11:33:29,694 [PokemonGoBot] [INFO] #18 Pidgeot: (CP 271, IV 0.71)
2016-08-19 11:33:29,694 [PokemonGoBot] [INFO] #19 Rattata: (CP 10, IV 0.38)
2016-08-19 11:33:29,694 [PokemonGoBot] [INFO] #21 Spearow: (CP 25, IV 0.36) | (CP 24, IV 0.29) | (CP 58, IV 0.38) | (CP 28, IV 0.78)
2016-08-19 11:33:29,696 [PokemonGoBot] [INFO] #23 Ekans: (CP 134, IV 0.44) | (CP 50, IV 0.31) | (CP 114, IV 0.36)
2016-08-19 11:33:29,696 [PokemonGoBot] [INFO] #27 Sandshrew: (CP 31, IV 0.64)
2016-08-19 11:33:29,697 [PokemonGoBot] [INFO] #29 Nidoran F: (CP 54, IV 0.42) | (CP 238, IV 0.58) | (CP 53, IV 0.31) | (CP 55, IV 0.36)
2016-08-19 11:33:29,697 [PokemonGoBot] [INFO] #32 Nidoran M: (CP 54, IV 0.51) | (CP 72, IV 0.27) | (CP 161, IV 0.42)
2016-08-19 11:33:29,697 [PokemonGoBot] [INFO] #33 Nidorino: (CP 121, IV 0.2)
2016-08-19 11:33:29,698 [PokemonGoBot] [INFO] #35 Clefairy: (CP 143, IV 0.51) | (CP 201, IV 0.36) | (CP 44, IV 0.27) | (CP 198, IV 0.31)
2016-08-19 11:33:29,700 [PokemonGoBot] [INFO] #41 Zubat: (CP 129, IV 0.6) | (CP 176, IV 0.47) | (CP 130, IV 0.62) | (CP 61, IV 0.69) | (CP 79, IV 0.67) | (CP 119, IV 0.87)
2016-08-19 11:33:29,700 [PokemonGoBot] [INFO] #42 Golbat: (CP 296, IV 0.53) | (CP 365, IV 0.89) | (CP 234, IV 0.33)
2016-08-19 11:33:29,700 [PokemonGoBot] [INFO] #43 Oddish: (CP 169, IV 0.51)
2016-08-19 11:33:29,700 [PokemonGoBot] [INFO] #46 Paras: (CP 115, IV 0.76) | (CP 11, IV 0.49) | (CP 39, IV 0.89) | (CP 11, IV 0.6)
2016-08-19 11:33:29,701 [PokemonGoBot] [INFO] #48 Venonat: (CP 158, IV 0.6) | (CP 71, IV 0.71) | (CP 70, IV 0.6)
2016-08-19 11:33:29,701 [PokemonGoBot] [INFO] #50 Diglett: (CP 55, IV 0.6)
2016-08-19 11:33:29,703 [PokemonGoBot] [INFO] #52 Meowth: (CP 141, IV 0.87) | (CP 10, IV 0.87)
2016-08-19 11:33:29,703 [PokemonGoBot] [INFO] #54 Psyduck: (CP 151, IV 0.22) | (CP 184, IV 0.33) | (CP 73, IV 0.6)
2016-08-19 11:33:29,703 [PokemonGoBot] [INFO] #56 Mankey: (CP 32, IV 0.4)
2016-08-19 11:33:29,703 [PokemonGoBot] [INFO] #58 Growlithe: (CP 57, IV 0.8)
2016-08-19 11:33:29,703 [PokemonGoBot] [INFO] #60 Poliwag: (CP 32, IV 0.71) | (CP 10, IV 0.73)
2016-08-19 11:33:29,703 [PokemonGoBot] [INFO] #69 Bellsprout: (CP 110, IV 0.73) | (CP 15, IV 0.93)
2016-08-19 11:33:29,704 [PokemonGoBot] [INFO] #72 Tentacool: (CP 37, IV 0.6) | (CP 82, IV 0.47)
2016-08-19 11:33:29,704 [PokemonGoBot] [INFO] #74 Geodude: (CP 107, IV 0.73) | (CP 92, IV 0.24)
2016-08-19 11:33:29,706 [PokemonGoBot] [INFO] #77 Ponyta: (CP 62, IV 0.53)
2016-08-19 11:33:29,706 [PokemonGoBot] [INFO] #79 Slowpoke: (CP 166, IV 0.22) | (CP 77, IV 0.33)
2016-08-19 11:33:29,707 [PokemonGoBot] [INFO] #92 Gastly: (CP 11, IV 0.96)
2016-08-19 11:33:29,707 [PokemonGoBot] [INFO] #99 Kingler: (CP 279, IV 0.56)
2016-08-19 11:33:29,707 [PokemonGoBot] [INFO] #111 Rhyhorn: (CP 50, IV 0.73)
2016-08-19 11:33:29,707 [PokemonGoBot] [INFO] #114 Tangela: (CP 124, IV 0.78)
2016-08-19 11:33:29,707 [PokemonGoBot] [INFO] #116 Horsea: (CP 33, IV 0.82)
2016-08-19 11:33:29,707 [PokemonGoBot] [INFO] #118 Goldeen: (CP 90, IV 0.44) | (CP 176, IV 0.67) | (CP 289, IV 0.76)
2016-08-19 11:33:29,707 [PokemonGoBot] [INFO] #120 Staryu: (CP 114, IV 0.6)
2016-08-19 11:33:29,709 [PokemonGoBot] [INFO] #127 Pinsir: (CP 337, IV 0.69) | (CP 389, IV 0.53)
2016-08-19 11:33:29,709 [PokemonGoBot] [INFO] #129 Magikarp: (CP 27, IV 0.2) | (CP 10, IV 0.29)
2016-08-19 11:33:29,709 [PokemonGoBot] [INFO] #133 Eevee: (CP 189, IV 0.4) | (CP 14, IV 0.91)
2016-08-19 11:33:41,586 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Caterpie, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:33:41,869 [TransferPokemon] [INFO] [pokemon_release] Exchanged Caterpie [CP 14] [IV 0.24] for candy.
2016-08-19 11:33:47,642 [TransferPokemon] [INFO] [pokemon_release] Exchanged Caterpie [CP 73] [IV 0.33] for candy.
2016-08-19 11:33:49,983 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Pidgey, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:33:53,638 [TransferPokemon] [INFO] [pokemon_release] Exchanged Pidgey [CP 10] [IV 0.38] for candy.
2016-08-19 11:33:56,198 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Spearow, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:33:59,686 [TransferPokemon] [INFO] [pokemon_release] Exchanged Spearow [CP 25] [IV 0.36] for candy.
2016-08-19 11:34:05,716 [TransferPokemon] [INFO] [pokemon_release] Exchanged Spearow [CP 24] [IV 0.29] for candy.
2016-08-19 11:34:06,877 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Ekans, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:34:11,842 [TransferPokemon] [INFO] [pokemon_release] Exchanged Ekans [CP 50] [IV 0.31] for candy.
2016-08-19 11:34:14,194 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Nidoran F, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:34:17,924 [TransferPokemon] [INFO] [pokemon_release] Exchanged Nidoran F [CP 53] [IV 0.31] for candy.
2016-08-19 11:34:23,930 [TransferPokemon] [INFO] [pokemon_release] Exchanged Nidoran F [CP 55] [IV 0.36] for candy.
2016-08-19 11:34:27,332 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Nidoran M, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:34:41,691 [TransferPokemon] [INFO] [pokemon_release] Exchanged Nidoran M [CP 72] [IV 0.27] for candy.
2016-08-19 11:34:45,371 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Clefairy, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:35:17,914 [TransferPokemon] [INFO] [pokemon_release] Exchanged Clefairy [CP 44] [IV 0.27] for candy.
2016-08-19 11:35:23,940 [TransferPokemon] [INFO] [pokemon_release] Exchanged Clefairy [CP 198] [IV 0.31] for candy.
2016-08-19 11:35:25,510 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Zubat, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:35:41,756 [TransferPokemon] [INFO] [pokemon_release] Exchanged Zubat [CP 129] [IV 0.6] for candy.
2016-08-19 11:36:17,862 [TransferPokemon] [INFO] [pokemon_release] Exchanged Zubat [CP 176] [IV 0.47] for candy.
2016-08-19 11:36:23,798 [TransferPokemon] [INFO] [pokemon_release] Exchanged Zubat [CP 130] [IV 0.62] for candy.
2016-08-19 11:36:29,798 [TransferPokemon] [INFO] [pokemon_release] Exchanged Zubat [CP 79] [IV 0.67] for candy.
2016-08-19 11:36:33,499 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Golbat, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:36:47,832 [TransferPokemon] [INFO] [pokemon_release] Exchanged Golbat [CP 234] [IV 0.33] for candy.
2016-08-19 11:36:51,032 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Paras, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:37:35,619 [TransferPokemon] [INFO] [pokemon_release] Exchanged Paras [CP 11] [IV 0.49] for candy.
2016-08-19 11:37:39,927 [TransferPokemon] [INFO] [pokemon_release] Exchanged Paras [CP 11] [IV 0.6] for candy.
2016-08-19 11:37:42,026 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Venonat, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:37:42,328 [TransferPokemon] [INFO] [pokemon_release] Exchanged Venonat [CP 70] [IV 0.6] for candy.
2016-08-19 11:37:43,618 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Psyduck, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:37:47,532 [TransferPokemon] [INFO] [pokemon_release] Exchanged Psyduck [CP 151] [IV 0.22] for candy.
2016-08-19 11:37:50,453 [TransferPokemon] [INFO] [keep_best_release] Keeping best 2 Goldeen, based on iv and cp and hp and moveset.defense_perfection
2016-08-19 11:37:50,740 [TransferPokemon] [INFO] [pokemon_release] Exchanged Goldeen [CP 90] [IV 0.44] for candy.

Please sign in to comment.