From 223027239d6ead79b46923a5296c6761de816a88 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sat, 23 Jul 2016 20:37:32 -0400 Subject: [PATCH 01/17] fixed a bug with zero values in release_config causing bot to crash --- pokemongo_bot/cell_workers/pokemon_catch_worker.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pokemongo_bot/cell_workers/pokemon_catch_worker.py b/pokemongo_bot/cell_workers/pokemon_catch_worker.py index 35f1253474..f5077da517 100644 --- a/pokemongo_bot/cell_workers/pokemon_catch_worker.py +++ b/pokemongo_bot/cell_workers/pokemon_catch_worker.py @@ -225,6 +225,8 @@ def should_release_pokemon(self, pokemon_name, cp, iv, response_dict): 'iv': False, } + min_cp = 0 + min_iv = 0 if release_config.get('min_cp'): min_cp = release_config['min_cp'] if cp < min_cp: From 812ba251b32f725391564dc62971c13591d2bd92 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 00:11:08 -0400 Subject: [PATCH 02/17] added evolve all option --- pokecli.py | 6 +++++ pokemongo_bot/stepper.py | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/pokecli.py b/pokecli.py index 0f7e1d3553..7e31f2fa31 100755 --- a/pokecli.py +++ b/pokecli.py @@ -126,6 +126,12 @@ def init_config(): type=list, default=[]) + parser.add_argument("-ev", + "--evolve_all", + help="Bot will start by attempting to evolve all pokemons. Great after popping a lucky egg!", + type=bool, + default=False) + config = parser.parse_args() if not config.username and not 'username' in load: config.username = raw_input("Username: ") diff --git a/pokemongo_bot/stepper.py b/pokemongo_bot/stepper.py index d6004d9fe3..4b9d2d3792 100644 --- a/pokemongo_bot/stepper.py +++ b/pokemongo_bot/stepper.py @@ -32,6 +32,12 @@ def __init__(self, bot): self.origin_lon = self.bot.position[1] def take_step(self): + if self.config.evolve_all: + # Run evolve all once. Flip the bit. + print('[#] Attempting to evolve all pokemons ...') + self.config.evolve_all = False + self._evolve_all() + position = (self.origin_lat, self.origin_lon, 0.0) self.api.set_position(*position) @@ -151,3 +157,46 @@ def _encode(self, cellid): output = [] encoder._VarintEncoder()(output.append, cellid) return ''.join(output) + + def _evolve_all(self): + self.api.get_inventory() + response_dict = self.api.call() + cache = {} + + try: + reduce(dict.__getitem__, [ + "responses", "GET_INVENTORY", "inventory_delta", "inventory_items"], response_dict) + except KeyError: + pass + else: + for item in response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']: + try: + reduce(dict.__getitem__, [ + "inventory_item_data", "pokemon_data"], item) + except KeyError: + pass + else: + try: + pokemon = item['inventory_item_data']['pokemon_data'] + self._execute_pokemon_evolve(pokemon, cache) + time.sleep(1.2) + except: + pass + + def _execute_pokemon_evolve(self, pokemon, cache): + pokemon_num = int(pokemon['pokemon_id']) - 1 + pokemon_name = self.bot.pokemon_list[ + int(pokemon_num)]['Name'] + if pokemon_name in cache: + return + + self.api.evolve_pokemon(pokemon_id=pokemon['id']) + response_dict = self.api.call() + status = response_dict['responses']['EVOLVE_POKEMON']['result'] + if status == 1: + print('[#] Successfully evolved {}!'.format( + pokemon_name + )) + else: + # cache pokemons we can't evolve. Less server calls + cache[pokemon_name] = 1 From c282881a22335141c6f569b9f4b9fe2a8790a27c Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 00:11:08 -0400 Subject: [PATCH 03/17] added evolve all option --- pokecli.py | 6 +++++ pokemongo_bot/stepper.py | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/pokecli.py b/pokecli.py index ce3afb3706..d1ddafb2e6 100755 --- a/pokecli.py +++ b/pokecli.py @@ -126,6 +126,12 @@ def init_config(): type=list, default=[]) + parser.add_argument("-ev", + "--evolve_all", + help="Bot will start by attempting to evolve all pokemons. Great after popping a lucky egg!", + type=bool, + default=False) + config = parser.parse_args() if not config.username and not 'username' in load: config.username = raw_input("Username: ") diff --git a/pokemongo_bot/stepper.py b/pokemongo_bot/stepper.py index d6004d9fe3..4b9d2d3792 100644 --- a/pokemongo_bot/stepper.py +++ b/pokemongo_bot/stepper.py @@ -32,6 +32,12 @@ def __init__(self, bot): self.origin_lon = self.bot.position[1] def take_step(self): + if self.config.evolve_all: + # Run evolve all once. Flip the bit. + print('[#] Attempting to evolve all pokemons ...') + self.config.evolve_all = False + self._evolve_all() + position = (self.origin_lat, self.origin_lon, 0.0) self.api.set_position(*position) @@ -151,3 +157,46 @@ def _encode(self, cellid): output = [] encoder._VarintEncoder()(output.append, cellid) return ''.join(output) + + def _evolve_all(self): + self.api.get_inventory() + response_dict = self.api.call() + cache = {} + + try: + reduce(dict.__getitem__, [ + "responses", "GET_INVENTORY", "inventory_delta", "inventory_items"], response_dict) + except KeyError: + pass + else: + for item in response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']: + try: + reduce(dict.__getitem__, [ + "inventory_item_data", "pokemon_data"], item) + except KeyError: + pass + else: + try: + pokemon = item['inventory_item_data']['pokemon_data'] + self._execute_pokemon_evolve(pokemon, cache) + time.sleep(1.2) + except: + pass + + def _execute_pokemon_evolve(self, pokemon, cache): + pokemon_num = int(pokemon['pokemon_id']) - 1 + pokemon_name = self.bot.pokemon_list[ + int(pokemon_num)]['Name'] + if pokemon_name in cache: + return + + self.api.evolve_pokemon(pokemon_id=pokemon['id']) + response_dict = self.api.call() + status = response_dict['responses']['EVOLVE_POKEMON']['result'] + if status == 1: + print('[#] Successfully evolved {}!'.format( + pokemon_name + )) + else: + # cache pokemons we can't evolve. Less server calls + cache[pokemon_name] = 1 From 8f4c96b22b663e9dcec6be9f3412702c65c166d5 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 00:11:08 -0400 Subject: [PATCH 04/17] added evolve all option --- pokecli.py | 6 +++++ pokemongo_bot/stepper.py | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/pokecli.py b/pokecli.py index ce3afb3706..d1ddafb2e6 100755 --- a/pokecli.py +++ b/pokecli.py @@ -126,6 +126,12 @@ def init_config(): type=list, default=[]) + parser.add_argument("-ev", + "--evolve_all", + help="Bot will start by attempting to evolve all pokemons. Great after popping a lucky egg!", + type=bool, + default=False) + config = parser.parse_args() if not config.username and not 'username' in load: config.username = raw_input("Username: ") diff --git a/pokemongo_bot/stepper.py b/pokemongo_bot/stepper.py index d6004d9fe3..4b9d2d3792 100644 --- a/pokemongo_bot/stepper.py +++ b/pokemongo_bot/stepper.py @@ -32,6 +32,12 @@ def __init__(self, bot): self.origin_lon = self.bot.position[1] def take_step(self): + if self.config.evolve_all: + # Run evolve all once. Flip the bit. + print('[#] Attempting to evolve all pokemons ...') + self.config.evolve_all = False + self._evolve_all() + position = (self.origin_lat, self.origin_lon, 0.0) self.api.set_position(*position) @@ -151,3 +157,46 @@ def _encode(self, cellid): output = [] encoder._VarintEncoder()(output.append, cellid) return ''.join(output) + + def _evolve_all(self): + self.api.get_inventory() + response_dict = self.api.call() + cache = {} + + try: + reduce(dict.__getitem__, [ + "responses", "GET_INVENTORY", "inventory_delta", "inventory_items"], response_dict) + except KeyError: + pass + else: + for item in response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']: + try: + reduce(dict.__getitem__, [ + "inventory_item_data", "pokemon_data"], item) + except KeyError: + pass + else: + try: + pokemon = item['inventory_item_data']['pokemon_data'] + self._execute_pokemon_evolve(pokemon, cache) + time.sleep(1.2) + except: + pass + + def _execute_pokemon_evolve(self, pokemon, cache): + pokemon_num = int(pokemon['pokemon_id']) - 1 + pokemon_name = self.bot.pokemon_list[ + int(pokemon_num)]['Name'] + if pokemon_name in cache: + return + + self.api.evolve_pokemon(pokemon_id=pokemon['id']) + response_dict = self.api.call() + status = response_dict['responses']['EVOLVE_POKEMON']['result'] + if status == 1: + print('[#] Successfully evolved {}!'.format( + pokemon_name + )) + else: + # cache pokemons we can't evolve. Less server calls + cache[pokemon_name] = 1 From 4ad2309765ee7ab525430837cb03e625ebd7b769 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 00:37:43 -0400 Subject: [PATCH 05/17] added to contrib. list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4e7e9c9d2b..99c19746c1 100644 --- a/README.md +++ b/README.md @@ -295,6 +295,7 @@ If using multiple usernames format like this: * Grace * Calcyfer * asaf400 + * guyz ------- ## Credits From ec56630898bbfea9f42d4f29d482fb07f0d51b11 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 09:17:18 -0400 Subject: [PATCH 06/17] sorting pokemons by cp --- .../cell_workers/evolve_all_worker.py | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/cell_workers/evolve_all_worker.py b/pokemongo_bot/cell_workers/evolve_all_worker.py index fe6b2c9776..f6ce6433bb 100644 --- a/pokemongo_bot/cell_workers/evolve_all_worker.py +++ b/pokemongo_bot/cell_workers/evolve_all_worker.py @@ -20,6 +20,7 @@ def work(self): except KeyError: pass else: + self._sort_by_cp(response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']) for item in response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']: try: reduce(dict.__getitem__, [ @@ -29,11 +30,46 @@ def work(self): else: try: pokemon = item['inventory_item_data']['pokemon_data'] - self._execute_pokemon_evolve(pokemon, cache) - sleep(1.2) + # TODO: reenable + # self._execute_pokemon_evolve(pokemon, cache) + # sleep(1.2) except: pass + def _sort_by_cp(self, inventory_items): + pokemons = [] + for item in inventory_items: + try: + reduce(dict.__getitem__, [ + "inventory_item_data", "pokemon_data"], item) + except KeyError: + pass + else: + try: + 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'] + ]) + except: + pass + + pokemons.sort(key=lambda x: x[2], reverse=True) + ## TODO: remove temp + print + print + for p in pokemons: + print p + print + print + ## + return pokemons + + + def _execute_pokemon_evolve(self, pokemon, cache): pokemon_num = int(pokemon['pokemon_id']) - 1 pokemon_name = self.bot.pokemon_list[ From b96d38ea4f70d89d0c1cc057aba176ab71fcc162 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 09:22:32 -0400 Subject: [PATCH 07/17] stepper update from upstream --- pokemongo_bot/stepper.py | 49 ---------------------------------------- 1 file changed, 49 deletions(-) diff --git a/pokemongo_bot/stepper.py b/pokemongo_bot/stepper.py index 4b9d2d3792..d6004d9fe3 100644 --- a/pokemongo_bot/stepper.py +++ b/pokemongo_bot/stepper.py @@ -32,12 +32,6 @@ def __init__(self, bot): self.origin_lon = self.bot.position[1] def take_step(self): - if self.config.evolve_all: - # Run evolve all once. Flip the bit. - print('[#] Attempting to evolve all pokemons ...') - self.config.evolve_all = False - self._evolve_all() - position = (self.origin_lat, self.origin_lon, 0.0) self.api.set_position(*position) @@ -157,46 +151,3 @@ def _encode(self, cellid): output = [] encoder._VarintEncoder()(output.append, cellid) return ''.join(output) - - def _evolve_all(self): - self.api.get_inventory() - response_dict = self.api.call() - cache = {} - - try: - reduce(dict.__getitem__, [ - "responses", "GET_INVENTORY", "inventory_delta", "inventory_items"], response_dict) - except KeyError: - pass - else: - for item in response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']: - try: - reduce(dict.__getitem__, [ - "inventory_item_data", "pokemon_data"], item) - except KeyError: - pass - else: - try: - pokemon = item['inventory_item_data']['pokemon_data'] - self._execute_pokemon_evolve(pokemon, cache) - time.sleep(1.2) - except: - pass - - def _execute_pokemon_evolve(self, pokemon, cache): - pokemon_num = int(pokemon['pokemon_id']) - 1 - pokemon_name = self.bot.pokemon_list[ - int(pokemon_num)]['Name'] - if pokemon_name in cache: - return - - self.api.evolve_pokemon(pokemon_id=pokemon['id']) - response_dict = self.api.call() - status = response_dict['responses']['EVOLVE_POKEMON']['result'] - if status == 1: - print('[#] Successfully evolved {}!'.format( - pokemon_name - )) - else: - # cache pokemons we can't evolve. Less server calls - cache[pokemon_name] = 1 From 9fb4ea2cc762704daa8268167710ef71a0932e14 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 11:32:11 -0400 Subject: [PATCH 08/17] much improved evolve all --- pokecli.py | 11 +- pokemongo_bot/__init__.py | 2 +- .../cell_workers/evolve_all_worker.py | 213 +++++++++++++++--- 3 files changed, 190 insertions(+), 36 deletions(-) diff --git a/pokecli.py b/pokecli.py index 49969d14f9..ccec52ecba 100755 --- a/pokecli.py +++ b/pokecli.py @@ -135,13 +135,13 @@ def init_config(): parser.add_argument("-ev", "--evolve_all", - help="Bot will start by attempting to evolve all pokemons. Great after popping a lucky egg!", - type=bool, - default=False) + 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("-ec", "--evolve_captured", - help="Bot will attempt to evolve all the pokemons captured!", + help="(Ad-hoc mode) Bot will attempt to evolve all the pokemons captured!", type=bool, default=False) @@ -182,6 +182,9 @@ def init_config(): for line in lines: sources.write(re.sub(r"%s" % find_url, replace_url % config.gmapkey, line)) + if config.evolve_all: + config.evolve_all = [str(pokemon_name) for pokemon_name in config.evolve_all.split(',')] + return config diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index fe2e8c441a..f066c59e2f 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -39,9 +39,9 @@ def work_on_cell(self, cell, position, include_fort_on_path): if self.config.evolve_all: # Run evolve all once. Flip the bit. print('[#] Attempting to evolve all pokemons ...') - self.config.evolve_all = False worker = EvolveAllWorker(self) worker.work() + self.config.evolve_all = [] self._filter_ignored_pokemons(cell) diff --git a/pokemongo_bot/cell_workers/evolve_all_worker.py b/pokemongo_bot/cell_workers/evolve_all_worker.py index f6ce6433bb..2afdd509fc 100644 --- a/pokemongo_bot/cell_workers/evolve_all_worker.py +++ b/pokemongo_bot/cell_workers/evolve_all_worker.py @@ -1,12 +1,13 @@ from utils import distance, format_dist from pokemongo_bot.human_behaviour import sleep from pokemongo_bot import logger +from sets import Set class EvolveAllWorker(object): def __init__(self, bot): self.api = bot.api self.config = bot.config - # self.stepper = bot.stepper + self.bot = bot # self.position = bot.position def work(self): @@ -20,21 +21,58 @@ def work(self): except KeyError: pass else: - self._sort_by_cp(response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']) - for item in response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']: + evolve_list = self._sort_by_cp(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 + # if len(evolve_list) > nn: + # evolve_list = evolve_list[:nn] + ## + + id_list1 = self.count_pokemon_inventory() + for pokemon in evolve_list: try: - reduce(dict.__getitem__, [ - "inventory_item_data", "pokemon_data"], item) - except KeyError: + self._execute_pokemon_evolve(pokemon, cache) + except: pass - else: - try: - pokemon = item['inventory_item_data']['pokemon_data'] - # TODO: reenable - # self._execute_pokemon_evolve(pokemon, cache) - # sleep(1.2) - except: - pass + id_list2 = self.count_pokemon_inventory() + release_cand_list_ids = list(Set(id_list2) - Set(id_list1)) + + if release_cand_list_ids: + print('[#] Evolved {} pokemons! Checking if any of them needs to be released ...'.format( + len(release_cand_list_ids) + )) + self._release_evolved(release_cand_list_ids) + + def _release_evolved(self, release_cand_list_ids): + self.api.get_inventory() + response_dict = self.api.call() + cache = {} + + try: + reduce(dict.__getitem__, [ + "responses", "GET_INVENTORY", "inventory_delta", "inventory_items"], response_dict) + except KeyError: + pass + else: + release_cand_list = self._sort_by_cp(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 + for cand in release_cand_list: + pokemon_id = cand[0] + pokemon_name = cand[1] + pokemon_cp = cand[2] + pokemon_potential = cand[3] + + if self.should_release_pokemon(pokemon_name, pokemon_cp, pokemon_potential): + # Transfering Pokemon + self.transfer_pokemon(pokemon_id) + logger.log( + '[#] {} has been exchanged for candy!'.format(pokemon_name), 'green') def _sort_by_cp(self, inventory_items): pokemons = [] @@ -52,38 +90,151 @@ def _sort_by_cp(self, inventory_items): pokemons.append([ pokemon['id'], pokemon_name, - pokemon['cp'] + pokemon['cp'], + self._compute_iv(pokemon) ]) except: pass pokemons.sort(key=lambda x: x[2], reverse=True) - ## TODO: remove temp - print - print - for p in pokemons: - print p - print - print - ## return pokemons - - def _execute_pokemon_evolve(self, pokemon, cache): - pokemon_num = int(pokemon['pokemon_id']) - 1 - pokemon_name = self.bot.pokemon_list[ - int(pokemon_num)]['Name'] + pokemon_id = pokemon[0] + pokemon_name = pokemon[1] + pokemon_cp = pokemon[2] + if pokemon_name in cache: return - self.api.evolve_pokemon(pokemon_id=pokemon['id']) + self.api.evolve_pokemon(pokemon_id=pokemon_id) response_dict = self.api.call() status = response_dict['responses']['EVOLVE_POKEMON']['result'] if status == 1: - print('[#] Successfully evolved {}!'.format( - pokemon_name + print('[#] Successfully evolved {} with {} cp!'.format( + pokemon_name, pokemon_cp )) else: # cache pokemons we can't evolve. Less server calls cache[pokemon_name] = 1 + sleep(1.2) + + # TODO: move to utils. These methods are shared with other workers. + def transfer_pokemon(self, pid): + self.api.release_pokemon(pokemon_id=pid) + response_dict = self.api.call() + + def count_pokemon_inventory(self): + self.api.get_inventory() + response_dict = self.api.call() + id_list = [] + return self.counting_pokemon(response_dict, id_list) + + def counting_pokemon(self, response_dict, id_list): + try: + reduce(dict.__getitem__, [ + "responses", "GET_INVENTORY", "inventory_delta", "inventory_items"], response_dict) + except KeyError: + pass + else: + for item in response_dict['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']: + try: + reduce(dict.__getitem__, [ + "inventory_item_data", "pokemon_data"], item) + except KeyError: + pass + else: + pokemon = item['inventory_item_data']['pokemon_data'] + if pokemon.get('is_egg', False): + continue + id_list.append(pokemon['id']) + + return id_list + + def should_release_pokemon(self, pokemon_name, cp, iv): + if self._check_always_capture_exception_for(pokemon_name): + return False + else: + release_config = self._get_release_config_for(pokemon_name) + cp_iv_logic = release_config.get('cp_iv_logic') + if not cp_iv_logic: + cp_iv_logic = self._get_release_config_for('any').get('cp_iv_logic', 'and') + + release_results = { + 'cp': False, + 'iv': False, + } + + if 'release_under_cp' in release_config: + min_cp = release_config['release_under_cp'] + if cp < min_cp: + release_results['cp'] = True + + if 'release_under_iv' in release_config: + min_iv = release_config['release_under_iv'] + if iv < min_iv: + release_results['iv'] = True + + if release_config.get('always_release'): + return True + + logic_to_function = { + 'or': lambda x, y: x or y, + 'and': lambda x, y: x and y + } + + #logger.log( + # "[x] Release config for {}: CP {} {} IV {}".format( + # pokemon_name, + # min_cp, + # cp_iv_logic, + # min_iv + # ), 'yellow' + #) + + return logic_to_function[cp_iv_logic](*release_results.values()) + + def _get_release_config_for(self, pokemon): + release_config = self.config.release_config.get(pokemon) + if not release_config: + release_config = self.config.release_config['any'] + return release_config + + def _get_exceptions(self): + exceptions = self.config.release_config.get('exceptions') + if not exceptions: + return None + return exceptions + + def _get_always_capture_list(self): + exceptions = self._get_exceptions() + if not exceptions: + return [] + always_capture_list = exceptions['always_capture'] + if not always_capture_list: + return [] + return always_capture_list + + def _check_always_capture_exception_for(self, pokemon_name): + always_capture_list = self._get_always_capture_list() + if not always_capture_list: + return False + else: + for pokemon in always_capture_list: + if pokemon_name == str(pokemon): + return True + return False + + # TODO: should also go to util and refactor in catch worker + def _compute_iv(self, pokemon): + total_IV = 0.0 + iv_stats = ['individual_attack', 'individual_defense', 'individual_stamina'] + + for individual_stat in iv_stats: + try: + total_IV += pokemon[individual_stat] + except: + pokemon[individual_stat] = 0 + continue + pokemon_potential = round((total_IV / 45.0), 2) + return pokemon_potential From d0d9c5fa3c68006fd2d71a0d5ae734bf61cab923 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 11:45:43 -0400 Subject: [PATCH 09/17] Update README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index d2954ab16e..51291949fd 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,23 @@ This project uses Google Maps. There's one map coupled with the project, but as 1. Pokemon name is always capitalize and case-sensitive 2. Be careful with the ``any`` configuration! + +### Evolve All Configuration + By setting the `evolve_all` attribute in config.json, you can instruct the bot to automatically + 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. + It will also automatically transfer the evolved pokemons based on the release configuration. + Examples on how to use (set in config.json): + + 1. "evolve_all": "all" + Will evolve ALL pokemons. + 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. + ## How to run with Docker From a147aeb028495bc8ae449a01a6dca68430e4b027 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 11:47:26 -0400 Subject: [PATCH 10/17] updated config example --- config.json.example | 1 + 1 file changed, 1 insertion(+) diff --git a/config.json.example b/config.json.example index 8090d0482d..8c642734fa 100644 --- a/config.json.example +++ b/config.json.example @@ -13,4 +13,5 @@ "location_cache": true, "distance_unit": "km", "item_filter": "101,102,103,104" + "evolve_all": "NONE" } From 5834c07d2236780215584dad090a3cbb8c11e959 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 15:13:55 -0400 Subject: [PATCH 11/17] longer sleeps - to avoid flooding the servers --- pokemongo_bot/cell_workers/evolve_all_worker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/evolve_all_worker.py b/pokemongo_bot/cell_workers/evolve_all_worker.py index 2afdd509fc..9c46dc7555 100644 --- a/pokemongo_bot/cell_workers/evolve_all_worker.py +++ b/pokemongo_bot/cell_workers/evolve_all_worker.py @@ -117,7 +117,7 @@ def _execute_pokemon_evolve(self, pokemon, cache): else: # cache pokemons we can't evolve. Less server calls cache[pokemon_name] = 1 - sleep(1.2) + sleep(5.7) # TODO: move to utils. These methods are shared with other workers. def transfer_pokemon(self, pid): From 07905763b155951e95dd0d67e33fb3f97a953377 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 23:32:48 -0400 Subject: [PATCH 12/17] mixed IV and CP evolving --- pokecli.py | 8 ++++ .../cell_workers/evolve_all_worker.py | 45 ++++++++++++------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/pokecli.py b/pokecli.py index 07cf746c06..b684522d22 100755 --- a/pokecli.py +++ b/pokecli.py @@ -138,6 +138,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..c71a346f97 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,8 +122,8 @@ 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 )) else: # cache pokemons we can't evolve. Less server calls From b03ba30beb80fd44bf3c9a507eecdf15ab24f54b Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Sun, 24 Jul 2016 23:40:54 -0400 Subject: [PATCH 13/17] Update README.md --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4c0d8f4b44..fc70f9d10c 100644 --- a/README.md +++ b/README.md @@ -190,14 +190,16 @@ To update your project do: `git pull` in the project folder - `location_cache` : - `distance_unit` : - `item_filter` : -- `evolve_all` : Set to true to evolve pokemon if possible +- `evolve_all` : Set to "all" or specify a list (e.g., "Pidgey,Weedle") to evolve pokemons ### Evolve All Configuration By setting the `evolve_all` attribute in config.json, you can instruct the bot to automatically 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). + a lucky egg. - 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): @@ -207,6 +209,10 @@ To update your project do: `git pull` in the project folder 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 From 651a5224cc6f89aeeafebb4e29f7e137decb5d7c Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Mon, 25 Jul 2016 08:35:52 -0400 Subject: [PATCH 14/17] modified config example --- configs/config.json.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configs/config.json.example b/configs/config.json.example index 0dfe442918..30ab8ea3b0 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -14,5 +14,6 @@ "distance_unit": "km", "item_filter": "101,102,103,104", "evolve_all": "NONE", + "min_cp": 300, "use_lucky_egg": false -} \ No newline at end of file +} From af49c7751c9f474639aedd2d726d93a6d06c4470 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Mon, 25 Jul 2016 09:49:05 -0400 Subject: [PATCH 15/17] shorter sleep duration after failed evolve. Should make things faster --- pokemongo_bot/cell_workers/evolve_all_worker.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/evolve_all_worker.py b/pokemongo_bot/cell_workers/evolve_all_worker.py index c71a346f97..d01e920e9f 100644 --- a/pokemongo_bot/cell_workers/evolve_all_worker.py +++ b/pokemongo_bot/cell_workers/evolve_all_worker.py @@ -125,10 +125,12 @@ def _execute_pokemon_evolve(self, pokemon, cache): print('[#] Successfully evolved {} with {} CP and {} IV!'.format( pokemon_name, pokemon_cp, pokemon_iv )) + sleep(5.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): From e99117e93d12a5fea0e84514cf8bc128c48b87f0 Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Mon, 25 Jul 2016 09:49:25 -0400 Subject: [PATCH 16/17] shorter sleep duration after success evolve. Should make things faster --- pokemongo_bot/cell_workers/evolve_all_worker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemongo_bot/cell_workers/evolve_all_worker.py b/pokemongo_bot/cell_workers/evolve_all_worker.py index d01e920e9f..a855eb237e 100644 --- a/pokemongo_bot/cell_workers/evolve_all_worker.py +++ b/pokemongo_bot/cell_workers/evolve_all_worker.py @@ -125,7 +125,7 @@ def _execute_pokemon_evolve(self, pokemon, cache): print('[#] Successfully evolved {} with {} CP and {} IV!'.format( pokemon_name, pokemon_cp, pokemon_iv )) - sleep(5.7) + sleep(3.7) else: # cache pokemons we can't evolve. Less server calls cache[pokemon_name] = 1 From 0a549c6469bf98037b09ea336b063aaf9e3a9dfa Mon Sep 17 00:00:00 2001 From: Guy Zyskind Date: Mon, 25 Jul 2016 14:00:44 -0400 Subject: [PATCH 17/17] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index ac6afe8212..5b76ee0e2e 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,6 @@ to only release Pidgey with bad rolls. Additionally, you can specify always_release and never_release flags. For example: ```"Pidgey": {"always_release": true}``` will release all Pidgey caught. ->>>>>>> upstream/dev ### Evolve All Configuration By setting the `evolve_all` attribute in config.json, you can instruct the bot to automatically