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

Added release_below_ivcp and keep_best_ivcp #5465

Merged
merged 1 commit into from
Sep 16, 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
4 changes: 3 additions & 1 deletion configs/config.json.cluster.example
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
"// Rattata": { "always_catch" : true }
},
"release": {
"any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"},
"any": {"release_below_cp": 0, "release_below_iv": 0, "release_below_ivcp": 0, "logic": "or"},
"// Example of always releasing Rattata:": {},
"// Rattata": {"always_release": true},
"// Example of keeping 3 stronger (based on CP) Pidgey:": {},
Expand All @@ -277,6 +277,8 @@
"// Zubat": {"keep_best_iv": 2},
"// Keep no more than 3 best IV pokemon for every pokemon type": {},
"// any": {"keep_best_iv": 3},
"// Keep no more than 3 best IVCP pokemon for every pokemon type": {},
"// any": {"keep_best_ivcp": 3},
"// Discard all pokemon in bag except 100 pokemon with best CP": {},
"// all": {"keep_best_cp": 100},
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {},
Expand Down
4 changes: 3 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
"Vaporeon": { "catch_above_iv": 0.99, "charged_attack": ["Hydro Pump"], "fast_attack": ["Water Gun"]}
},
"release": {
"any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"},
"any": {"release_below_cp": 0, "release_below_iv": 0, "release_below_ivcp": 0, "logic": "or"},
"// Example of always releasing Rattata:": {},
"// Rattata": {"always_release": true},
"// Example of keeping 3 stronger (based on CP) Pidgey:": {},
Expand All @@ -354,6 +354,8 @@
"// Zubat": {"keep_best_iv": 2},
"// Keep no more than 3 best IV pokemon for every pokemon type": {},
"// any": {"keep_best_iv": 3},
"// Keep no more than 3 best IVCP pokemon for every pokemon type": {},
"// any": {"keep_best_ivcp": 3},
"// Discard all pokemon in bag except 100 pokemon with best CP": {},
"// all": {"keep_best_cp": 100},
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {},
Expand Down
4 changes: 3 additions & 1 deletion configs/config.json.map.example
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@
"// Rattata": { "always_catch" : true }
},
"release": {
"any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"},
"any": {"release_below_cp": 0, "release_below_iv": 0, "release_below_ivcp": 0, "logic": "or"},
"// Example of always releasing Rattata:": {},
"// Rattata": {"always_release": true},
"// Example of keeping 3 stronger (based on CP) Pidgey:": {},
Expand All @@ -543,6 +543,8 @@
"// Zubat": {"keep_best_iv": 2},
"// Keep no more than 3 best IV pokemon for every pokemon type": {},
"// any": {"keep_best_iv": 3},
"// Keep no more than 3 best IVCP pokemon for every pokemon type": {},
"// any": {"keep_best_ivcp": 3},
"// Discard all pokemon in bag except 100 pokemon with best CP": {},
"// all": {"keep_best_cp": 100},
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {},
Expand Down
4 changes: 3 additions & 1 deletion configs/config.json.path.example
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
"// Rattata": { "always_catch" : true }
},
"release": {
"any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or"},
"any": {"release_below_cp": 0, "release_below_iv": 0, "release_below_ivcp": 0, "logic": "or"},
"// Example of always releasing Rattata:": {},
"// Rattata": {"always_release": true},
"// Example of keeping 3 stronger (based on CP) Pidgey:": {},
Expand All @@ -283,6 +283,8 @@
"// Zubat": {"keep_best_iv": 2},
"// Keep no more than 3 best IV pokemon for every pokemon type": {},
"// any": {"keep_best_iv": 3},
"// Keep no more than 3 best IVCP pokemon for every pokemon type": {},
"// any": {"keep_best_ivcp": 3},
"// Discard all pokemon in bag except 100 pokemon with best CP": {},
"// all": {"keep_best_cp": 100},
"// Example of keeping the 2 strongest (based on CP) and 3 best (based on IV) Zubat:": {},
Expand Down
2 changes: 1 addition & 1 deletion configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
"Kangaskhan": { "always_catch": true }
},
"release": {
"any": {"release_below_cp": 0, "release_below_iv": 0, "logic": "or" },
"any": {"release_below_cp": 0, "release_below_iv": 0, "release_below_ivcp": 0, "logic": "or" },

"// Legendary pokemons (Goes under S-Tier)": {},
"Lapras": { "release_below_cp": 1041, "release_below_iv": 0.8, "logic": "and" },
Expand Down
8 changes: 6 additions & 2 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,16 @@ def _register_events(self):
self.event_manager.register_event(
'future_pokemon_release',
parameters=(
'pokemon', 'cp', 'iv', 'below_iv', 'below_cp', 'cp_iv_logic'
'pokemon', 'cp', 'iv', 'ivcp', 'below_iv', 'below_cp', 'below_ivcp', 'cp_iv_logic'
)
)
self.event_manager.register_event(
'pokemon_release',
parameters=('pokemon', 'iv', 'cp', 'candy')
parameters=('pokemon', 'iv', 'cp', 'ivcp', 'candy')
)
self.event_manager.register_event(
'pokemon_keep',
parameters=('pokemon', 'iv', 'cp', 'ivcp')
)

# polyline walker
Expand Down
78 changes: 59 additions & 19 deletions pokemongo_bot/cell_workers/transfer_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def work(self):
self._release_pokemon_worst_in_group(group, 'all')

def _should_work(self):
return True
random_number = randrange (0,20,1)
return inventory.Pokemons.get_space_left() <= self.min_free_slot - random_number

Expand All @@ -54,35 +55,47 @@ def _release_pokemon_get_groups(self):
return pokemon_groups

def _release_pokemon_worst_in_group(self, group, pokemon_name):
keep_best, keep_best_cp, keep_best_iv = self._validate_keep_best_config(
keep_best, keep_best_cp, keep_best_iv, keep_best_ivcp = self._validate_keep_best_config(
pokemon_name)
# TODO continue list possible criteria
keep_best_possible_criteria = ['cp', 'iv', 'iv_attack', 'iv_defense', 'iv_stamina',
keep_best_possible_criteria = ['cp', 'iv', 'iv_attack', 'iv_defense', 'iv_stamina', 'ivcp',
'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:
if keep_best_cp >= 1:
if keep_best_ivcp > 0:
ivcp_limit = keep_best_ivcp
best_ivcp_pokemons = sorted(group, key=lambda x: (
x.ivcp), reverse=True)[:ivcp_limit]
best_pokemon_ids = set(
pokemon.unique_id for pokemon in best_ivcp_pokemons)
order_criteria = 'ivcp'

if keep_best_cp > 0:
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.unique_id for pokemon in best_cp_pokemons)
order_criteria = 'cp'
if order_criteria != 'none':
order_criteria = order_criteria + ' and cp'
else:
order_criteria = 'cp'

if keep_best_iv >= 1:
if keep_best_iv > 0:
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.unique_id for pokemon in best_iv_pokemons)
if order_criteria == 'cp':
order_criteria = 'cp and iv'
if order_criteria != 'none':
order_criteria = order_criteria + ' and iv'
else:
order_criteria = 'iv'

elif keep_best_custom:
limit = keep_amount
# not sure if the u of unicode will stay, so make it go away
Expand Down Expand Up @@ -118,6 +131,18 @@ def _release_pokemon_worst_in_group(self, group, pokemon_name):
'criteria': order_criteria
}
)
for pokemon in best_pokemons:
self.emit_event(
'pokemon_keep',
data={
'pokemon': pokemon.name,
'iv': pokemon.iv,
'cp': pokemon.cp,
'ivcp': pokemon.ivcp
},
formatted="Kept {} (CP: {}, IV: {}, IVCP: {})".format(pokemon.name, pokemon.cp, pokemon.iv, pokemon.ivcp),
)

for pokemon in transfer_pokemons:
self.release_pokemon(pokemon)
else:
Expand All @@ -133,7 +158,8 @@ def should_release_pokemon(self, pokemon, keep_best_mode=False):
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')):
and not release_config.has_key('release_below_iv')
and not release_config.has_key('release_below_ivcp')):
return True

cp_iv_logic = release_config.get('logic')
Expand All @@ -144,6 +170,7 @@ def should_release_pokemon(self, pokemon, keep_best_mode=False):
release_results = {
'cp': False,
'iv': False,
'ivcp': False
}

if release_config.get('never_release', False):
Expand All @@ -160,23 +187,29 @@ def should_release_pokemon(self, pokemon, keep_best_mode=False):
if pokemon.iv < release_iv:
release_results['iv'] = True

release_ivcp = release_config.get('release_below_ivcp', 0)
if pokemon.ivcp < release_ivcp:
release_results['ivcp'] = True

logic_to_function = {
'or': lambda x, y: x or y,
'and': lambda x, y: x and y
'or': lambda x, y, z: x or y or z,
'and': lambda x, y, z: x and y and z
}

if logic_to_function[cp_iv_logic](*release_results.values()):
self.emit_event(
'future_pokemon_release',
formatted="*Releasing {}* CP: {}, IV: {} | based on rule: CP < {} {} IV < {}".format(pokemon.name, pokemon.cp, pokemon.iv,
release_cp, cp_iv_logic.upper(),release_iv),
formatted="*Releasing {}* CP: {}, IV: {}, IVCP: {} | based on rule: CP < {} {} IV < {} IVCP < {}".format(pokemon.name, pokemon.cp, pokemon.iv, pokemon.ivcp,
release_cp, cp_iv_logic.upper(),release_iv, release_ivcp),
data={
'pokemon': pokemon.name,
'cp': pokemon.cp,
'iv': pokemon.iv,
'ivcp': pokemon.ivcp,
'below_cp': release_cp,
'cp_iv_logic': cp_iv_logic.upper(),
'below_iv': release_iv
'below_iv': release_iv,
'below_ivcp': release_ivcp
},
)

Expand Down Expand Up @@ -209,9 +242,10 @@ def release_pokemon(self, pokemon):
'pokemon': pokemon.name,
'iv': pokemon.iv,
'cp': pokemon.cp,
'ivcp': pokemon.ivcp,
'candy': candy.quantity
},
formatted="*{} Released* You now have {} {} candies".format(pokemon.name, candy.quantity, pokemon.name),
formatted="Released {} (CP: {}, IV: {}, IVCP: {}) You now have {} {} candies".format(pokemon.name, pokemon.cp, pokemon.iv, pokemon.ivcp, candy.quantity, pokemon.name),
)
with self.bot.database as conn:
c = conn.cursor()
Expand Down Expand Up @@ -276,8 +310,9 @@ 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_best_ivcp = release_config.get('keep_best_ivcp', 0)

if keep_best_cp or keep_best_iv:
if keep_best_cp or keep_best_iv or keep_best_ivcp:
keep_best = True
try:
keep_best_cp = int(keep_best_cp)
Expand All @@ -289,10 +324,15 @@ def _validate_keep_best_config(self, pokemon_name):
except ValueError:
keep_best_iv = 0

if keep_best_cp < 0 or keep_best_iv < 0:
try:
keep_best_ivcp = int(keep_best_ivcp)
except ValueError:
keep_best_ivcp = 0

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

if keep_best_cp == 0 and keep_best_iv == 0:
if keep_best_cp == 0 and keep_best_iv == 0 and keep_best_ivcp == 0:
keep_best = False

return keep_best, keep_best_cp, keep_best_iv
return keep_best, keep_best_cp, keep_best_iv, keep_best_ivcp
1 change: 1 addition & 0 deletions pokemongo_bot/event_handlers/logging_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class LoggingHandler(EventHandler):
'pokemon_inventory_full': 'red',
'pokemon_nickname_invalid': 'red',
'pokemon_not_in_range': 'yellow',
'pokemon_keep': 'green',
'pokemon_release': 'green',
'pokemon_upgraded': 'green',
'pokemon_vanished': 'red',
Expand Down