diff --git a/README.md b/README.md index 6a726bac98..5b76ee0e2e 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,9 @@ will release all Pidgey caught. evolve specified pokemons on startup. This is especially useful for batch-evolving after popping up a lucky egg (currently this needs to be done manually). - The evolve all mechanism evolves only higher CP pokemons. It does this by first ordering them from high-to-low CP. + The evolve all mechanism evolves only higher IV/CP pokemons. It works by sorting the high CP pokemons (default: 300 CP or higher) + based on their IV values. After evolving all high CP pokemons, the mechanism will move on to evolving lower CP pokemons + only based on their CP (if it can). It will also automatically transfer the evolved pokemons based on the release configuration. Examples on how to use (set in config.json): @@ -220,6 +222,10 @@ will release all Pidgey caught. 2. "evolve_all": "Pidgey,Weedle" Will only evolve Pidgey and Weedle. 3. Not setting evolve_all or having any other string would not evolve any pokemons on startup. + + If you wish to change the default threshold of 300 CP, simply add the following to the config file: + "cp_min": + ## How to run with Docker diff --git a/configs/config.json.example b/configs/config.json.example index 5f36ce5372..8de8fcb821 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -14,6 +14,7 @@ "distance_unit": "km", "item_filter": "", "evolve_all": "NONE", + "cp_min": 300, "use_lucky_egg": false, "catch": { "any": {"catch_above_cp": 0, "catch_above_iv": 0, "logic": "or"} @@ -21,4 +22,4 @@ "release": { "any": {"release_under_cp": 0, "release_under_iv": 0, "logic": "or"} } -} \ No newline at end of file +} diff --git a/pokecli.py b/pokecli.py index 7ead36fa70..3a7485fdd2 100755 --- a/pokecli.py +++ b/pokecli.py @@ -141,6 +141,14 @@ def init_config(): help="(Batch mode) Pass \"all\" or a list of pokemons to evolve (e.g., \"Pidgey,Weedle,Caterpie\"). Bot will start by attempting to evolve all pokemons. Great after popping a lucky egg!", type=str, default=[]) + + parser.add_argument( + "-cm", + "--cp_min", + help= + "Minimum CP for evolve all. Bot will attempt to first evolve highest IV pokemons with CP larger than this.", + type=int, + default=300) parser.add_argument("-ec", "--evolve_captured", diff --git a/pokemongo_bot/cell_workers/evolve_all_worker.py b/pokemongo_bot/cell_workers/evolve_all_worker.py index 9c46dc7555..a855eb237e 100644 --- a/pokemongo_bot/cell_workers/evolve_all_worker.py +++ b/pokemongo_bot/cell_workers/evolve_all_worker.py @@ -21,16 +21,16 @@ def work(self): except KeyError: pass else: - evolve_list = self._sort_by_cp(response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']) + evolve_list = self._sort_by_cp_iv(response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']) if self.config.evolve_all[0] != 'all': # filter out non-listed pokemons evolve_list = [x for x in evolve_list if str(x[1]) in self.config.evolve_all] - ## enable to limit number of pokemons to evolve. Useful for testing. - # nn = 1 + # enable to limit number of pokemons to evolve. Useful for testing. + # nn = 3 # if len(evolve_list) > nn: # evolve_list = evolve_list[:nn] - ## + # id_list1 = self.count_pokemon_inventory() for pokemon in evolve_list: @@ -58,7 +58,7 @@ def _release_evolved(self, release_cand_list_ids): except KeyError: pass else: - release_cand_list = self._sort_by_cp(response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']) + release_cand_list = self._sort_by_cp_iv(response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']) release_cand_list = [x for x in release_cand_list if x[0] in release_cand_list_ids] ## at this point release_cand_list contains evolved pokemons data @@ -74,8 +74,9 @@ def _release_evolved(self, release_cand_list_ids): logger.log( '[#] {} has been exchanged for candy!'.format(pokemon_name), 'green') - def _sort_by_cp(self, inventory_items): - pokemons = [] + def _sort_by_cp_iv(self, inventory_items): + pokemons1 = [] + pokemons2 = [] for item in inventory_items: try: reduce(dict.__getitem__, [ @@ -87,22 +88,32 @@ def _sort_by_cp(self, inventory_items): pokemon = item['inventory_item_data']['pokemon_data'] pokemon_num = int(pokemon['pokemon_id']) - 1 pokemon_name = self.bot.pokemon_list[int(pokemon_num)]['Name'] - pokemons.append([ - pokemon['id'], - pokemon_name, - pokemon['cp'], - self._compute_iv(pokemon) - ]) + v = [ + pokemon['id'], + pokemon_name, + pokemon['cp'], + self._compute_iv(pokemon) + ] + if pokemon['cp'] > self.config.cp_min: + pokemons1.append(v) + else: + pokemons2.append(v) except: pass - pokemons.sort(key=lambda x: x[2], reverse=True) - return pokemons + ## Sort larger CP pokemons by IV, tie breaking by CP + pokemons1.sort(key=lambda x: (x[3], x[2]), reverse=True) + + ## Sort smaller CP pokemons by CP, tie breaking by IV + pokemons2.sort(key=lambda x: (x[2], x[3]), reverse=True) + + return pokemons1 + pokemons2 def _execute_pokemon_evolve(self, pokemon, cache): pokemon_id = pokemon[0] pokemon_name = pokemon[1] pokemon_cp = pokemon[2] + pokemon_iv = pokemon[3] if pokemon_name in cache: return @@ -111,13 +122,15 @@ def _execute_pokemon_evolve(self, pokemon, cache): response_dict = self.api.call() status = response_dict['responses']['EVOLVE_POKEMON']['result'] if status == 1: - print('[#] Successfully evolved {} with {} cp!'.format( - pokemon_name, pokemon_cp + print('[#] Successfully evolved {} with {} CP and {} IV!'.format( + pokemon_name, pokemon_cp, pokemon_iv )) + sleep(3.7) else: # cache pokemons we can't evolve. Less server calls cache[pokemon_name] = 1 - sleep(5.7) + sleep(0.7) + # TODO: move to utils. These methods are shared with other workers. def transfer_pokemon(self, pid):