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

Pokemon optimizer enhancements #3743

Merged
merged 42 commits into from
Aug 13, 2016
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
204ad0e
catching every single pokemon nearby
douglascamata Aug 7, 2016
c9b25d6
catch lured pokemon in all forts nearby
douglascamata Aug 7, 2016
081d90d
adding run_interval to some tasks to avoid running all the time and m…
douglascamata Aug 7, 2016
4f3a744
added config to ignore item count for Spin and MoveToFort
douglascamata Aug 7, 2016
235f6bf
spinning all pokestops in range
douglascamata Aug 7, 2016
ec83d2b
Merge branch 'dev' of github.com:PokemonGoF/PokemonGo-Bot into faetur…
douglascamata Aug 7, 2016
1fd60e7
fixing loop in spin fort task
douglascamata Aug 7, 2016
1cc011c
First basic features of the pokemon optimizer
julienlavergne Aug 7, 2016
a894a32
For now, dry run only
julienlavergne Aug 8, 2016
7490bf8
Add cygwin to supported platform and improved log readability (#2948)
villish Aug 8, 2016
2a7a6cd
- Add dry_run and use_lucky_egg in config
julienlavergne Aug 8, 2016
e2e71f1
Merge remote-tracking branch 'origin/dev' into pokemon_optimizer
julienlavergne Aug 8, 2016
4b0faaa
Add lucky egg support when enough pokemon to evolve
julienlavergne Aug 8, 2016
a205de8
fixing returns
douglascamata Aug 8, 2016
8de542a
Merge branch 'faeture/xp-improvements' of github.com:PokemonGoF/Pokem…
douglascamata Aug 8, 2016
bb931f4
Merge branch 'dev' of github.com:PokemonGoF/PokemonGo-Bot into faetur…
douglascamata Aug 8, 2016
ef2bb53
Merge branch 'dev' of github.com:PokemonGoF/PokemonGo-Bot into faetur…
douglascamata Aug 8, 2016
e8fd901
Merge remote-tracking branch 'origin/dev' into pokemon_optimizer
julienlavergne Aug 8, 2016
ff1f5e4
Merge remote-tracking branch 'origin/faeture/xp-improvements' into po…
julienlavergne Aug 8, 2016
0514a94
- Support Eevee evolution scheme
julienlavergne Aug 9, 2016
d34f74c
Revert "Merge remote-tracking branch 'origin/faeture/xp-improvements'…
julienlavergne Aug 9, 2016
afcbf59
Merge remote-tracking branch 'origin/dev' into pokemon_optimizer
julienlavergne Aug 9, 2016
4d9375f
- Fix an issue in evolve_pokemon task
julienlavergne Aug 9, 2016
86fe6bb
Add missing inventory refresh at the end of the process
julienlavergne Aug 9, 2016
7d6a24b
Merge remote-tracking branch 'origin/dev' into pokemon_optimizer
julienlavergne Aug 9, 2016
0552e95
Merge remote-tracking branch 'origin/dev' into pokemon_optimizer
julienlavergne Aug 10, 2016
49f83e6
Add missing inventory refresh after catching a pokemon
julienlavergne Aug 10, 2016
15fb493
Add parameters "transfer" and "evolve" to activate/deactivate corresp…
julienlavergne Aug 10, 2016
45905e5
Merge remote-tracking branch 'origin/dev' into pokemon_optimizer
julienlavergne Aug 10, 2016
f30cbf2
Move some functions around
julienlavergne Aug 10, 2016
ae6c278
Default lucky egg to false + had again parameter "evolve_only_with_lu…
julienlavergne Aug 11, 2016
0530d80
Fix qn issue with egg counting
julienlavergne Aug 11, 2016
3714221
Update configuration example
julienlavergne Aug 11, 2016
b880f58
Merge remote-tracking branch 'origin/dev' into pokemon_optimizer
julienlavergne Aug 11, 2016
4b02024
Upgrade to latest inventory
julienlavergne Aug 11, 2016
cbb54d8
Fix bug
julienlavergne Aug 12, 2016
fe4551c
Add parameter "use_candies_for_xp" to activate/deactivate usage of ca…
julienlavergne Aug 12, 2016
a5ea4a2
Merge remote-tracking branch 'origin/dev' into pokemon_optimizer
julienlavergne Aug 12, 2016
aa1b1b2
Add dps, dps_attack and dps_defense in available sorting keys. So you…
julienlavergne Aug 12, 2016
c1129fb
Merge remote-tracking branch 'origin/dev' into pokemon_optimizer
julienlavergne Aug 13, 2016
cc0bba0
Update inventory when releasing and evolving pokemons
julienlavergne Aug 13, 2016
9c88601
Display Pokemon Bag count update
julienlavergne Aug 13, 2016
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
53 changes: 51 additions & 2 deletions configs/config.json.optimizer.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,74 @@
{
"type": "PokemonOptimizer",
"config": {
"// the 'transfer' parameter activate or deactivate the transfer of pokemons": {},
"// at false, no pokemon is going to be transfered, ever": {},
"// at false, you will still get the log information of what the optimizer": {},
"// would have transfered if the parameter was true": {},
"transfer": true,
"// the 'evolve' parameter activate or deactivate the evolution of pokemons": {},
"// at false, no pokemon is going to be evolved, ever": {},
"// at false, you will still get the log information of what the": {},
"// optimizer would have evolved if the parameter was true": {},
"evolve": true,
"// the 'use_candies_for_xp' parameter let you choose if you want the optimizer": {},
"// to use your candies to evolve low quality pokemons in order to maximize your xp": {},
"// at false, the optimizer will still use candies to evolve your best Pokemons": {},
"use_candies_for_xp": true,
"// the 'use_lucky_egg' parameter let you choose if you want the optimizer": {},
"// to use a lucky egg right before evolving Pokemons. At false; the optimizer": {},
"// is free to evolve Pokemons even if you do not have any lucky egg.": {},
"use_lucky_egg": true,
"// the 'evolve_only_with_lucky_egg' parameter let you choose if you want the optimizer": {},
"// to only Evolve Pokemons when a lucky egg is available": {},
"evolve_only_with_lucky_egg": true,
"// the 'minimum_evolve_for_lucky_egg' parameter let you define the minimum": {},
"// number of Pokemons that must evolve before using a lucky egg": {},
"// If that number is not reached, and evolve_only_with_lucky_egg is true, evolution will be skipped": {},
"// If that number is not reached, and evolve_only_with_lucky_egg is false,": {},
"// evolution will be performed without using a lucky egg": {},
"minimum_evolve_for_lucky_egg": 90,
"// the 'keep' parameter let you define what pokemons you consider are the 'best'. These Pokemons": {},
"// will be keep and evolved. Note that Pokemons are evaluated inside their whole family": {},
"// Multiple way of ranking can be defined. Following configuration let you keep the best iv,": {},
"// the best ncp and the best cp": {},
"keep": [
{
"// Following setting let you keep the best iv of the family": {},
"// the 'top' parameter allow you to define how many Pokemons you want to keep": {},
"// at the top of your ranking. If several Pokemons get the same score, they are": {},
"// considered equal. Thus, top=1 might result in keeping more than 1 Pokemon.": {},
"top": 1,
"// the 'evolve' parameter let you choose if you want to evolve the Pokemons you keep": {},
"evolve": true,
"// Available sorting keys are:": true,
"// iv, cp, ncp, ivcp, max_cp, iv_attack, iv_defense, iv_stamina, hp_max, level": true,
"// the 'sort' parameter define how you want to rank your pokemons": {},
"// Critera are sorted fro, the most important to the least important.": {},
"// Available criteria are:": {},
"// 'iv' = individual value": [},
"// 'ivcp' = iv weigted so that for equal iv, attack > defense > stamina": {},
"// 'cp' = combat power (can be increased with candies)": {},
"// 'cp_exact' = combar power (not rounded)": {},
"// 'ncp' (normalized cp) or 'cp_percent' = ratio cp / max_cp": {},
"// iv_attack = attach component of iv": {},
"// iv_defense = defense component of iv": {},
"// iv_stamina = stamina component of iv": {},
"// dps = raw dps based on the moves of the pokemon": {},
"// dps_attack = average dps when attacking": {},
"// dps_defense = average dps when defending": {},
"// Note that the more criteria you add to this list, the less likely Pokemons": {},
"// will be equals": {},
"sort": ["iv"]
},
{
"// Following setting let you keep keep the best normalized cp of the family": {},
"// That is the Pokemon with higher CP once fully evolved": {},
"top": 1,
"evolve": true,
"sort": ["ncp"]
},
{
"// Following setting let you keep keep the best cp of the family.": {},
"// But will not evolve it further (in favor of the best ncp)": {},
"top": 1,
"evolve": false,
"sort": ["cp"]
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/evolve_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def _execute_pokemon_evolve(self, pokemon, cache):
'pokemon': pokemon.name,
'iv': pokemon.iv,
'cp': pokemon.cp,
'xp': 0
'ncp': '?',
'dps': '?',
'xp': '?'
}
)
inventory.candies().get(pokemon.pokemon_id).consume(pokemon.evolution_cost)
Expand Down
90 changes: 59 additions & 31 deletions pokemongo_bot/cell_workers/pokemon_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def initialize(self):

self.config_transfer = self.config.get("transfer", False)
self.config_evolve = self.config.get("evolve", False)
self.config_use_candies_for_xp = self.config.get("use_candies_for_xp", True)
self.config_use_lucky_egg = self.config.get("use_lucky_egg", False)
self.config_evolve_only_with_lucky_egg = self.config.get("evolve_only_with_lucky_egg", True)
self.config_minimum_evolve_for_lucky_egg = self.config.get("minimum_evolve_for_lucky_egg", 90)
Expand Down Expand Up @@ -56,6 +57,9 @@ def parse_inventory(self):
for pokemon in inventory.pokemons().all():
family_id = pokemon.first_evolution_id
setattr(pokemon, "ncp", pokemon.cp_percent)
setattr(pokemon, "dps", pokemon.moveset.dps)
setattr(pokemon, "dps_attack", pokemon.moveset.dps_attack)
setattr(pokemon, "dps_defense", pokemon.moveset.dps_defense)

self.family_by_family_id.setdefault(family_id, []).append(pokemon)

Expand Down Expand Up @@ -173,39 +177,58 @@ def get_evolution_plan(self, family_id, family, evolve_best, keep_best):
next_evo.name = inventory.pokemons().name_for(next_pid)
evolve_best.append(next_evo)

# Compute how many crap we should keep if we want to batch evolve them for xp
junior_evolution_cost = inventory.pokemons().evolution_cost_for(family_id)
if self.config_use_candies_for_xp:
# Compute how many crap we should keep if we want to batch evolve them for xp
junior_evolution_cost = inventory.pokemons().evolution_cost_for(family_id)

# transfer + keep_for_evo = len(crap)
# leftover_candies = candies - len(crap) + transfer * 1
# keep_for_evo = leftover_candies / junior_evolution_cost
#
# keep_for_evo = (candies - len(crap) + transfer) / junior_evolution_cost
# keep_for_evo = (candies - keep_for_evo) / junior_evolution_cost
# transfer + keep_for_evo = len(crap)
# leftover_candies = candies - len(crap) + transfer * 1
# keep_for_evo = leftover_candies / junior_evolution_cost
#
# keep_for_evo = (candies - len(crap) + transfer) / junior_evolution_cost
# keep_for_evo = (candies - keep_for_evo) / junior_evolution_cost

if (candies > 0) and junior_evolution_cost:
keep_for_evo = int(candies / (junior_evolution_cost + 1))
else:
keep_for_evo = 0
if (candies > 0) and junior_evolution_cost:
keep_for_evo = int(candies / (junior_evolution_cost + 1))
else:
keep_for_evo = 0

evo_crap = [p for p in crap if p.has_next_evolution() and p.evolution_cost == junior_evolution_cost][:keep_for_evo]
transfer = [p for p in crap if p not in evo_crap]
evo_crap = [p for p in crap if p.has_next_evolution() and p.evolution_cost == junior_evolution_cost][:keep_for_evo]
transfer = [p for p in crap if p not in evo_crap]
else:
evo_crap = []
transfer = crap

return (transfer, can_evolve_best, evo_crap)

def apply_optimization(self, transfer, evo):
for pokemon in transfer:
self.transfer_pokemon(pokemon)

if self.config_evolve:
if len(evo) < self.config_minimum_evolve_for_lucky_egg:
self.logger.info("Skipping evolution step. Not enough Pokemons to evolve")
return

if self.config_evolve and (len(evo) < self.config_minimum_evolve_for_lucky_egg):
self.logger.info("Skipping evolution step. Not enough Pokemons to evolve")
return

if self.config_evolve and self.config_use_lucky_egg:
if len(evo) == 0:
return

lucky_egg = inventory.items().get(Item.ITEM_LUCKY_EGG.value) # @UndefinedVariable

if lucky_egg.count == 0:
if self.config_evolve_only_with_lucky_egg:
self.logger.info("Skipping evolution step. No lucky egg available")
return
elif len(evo) >= self.config_minimum_evolve_for_lucky_egg:
self.use_lucky_egg()
if self.config_evolve_only_with_lucky_egg and (lucky_egg.count == 0):
self.logger.info("Skipping evolution step. No lucky egg available")
return

if len(evo) < self.config_minimum_evolve_for_lucky_egg:
self.logger.info("Skipping evolution step. Not enough Pokemons (%s) to evolve", len(evo))
return

self.use_lucky_egg()

self.logger.info("Evolving %s Pokemons", len(evo))

Expand All @@ -219,10 +242,12 @@ def transfer_pokemon(self, pokemon):
pass

self.emit_event("pokemon_release",
formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}]",
formatted="Exchanged {pokemon} [IV {iv}] [CP {cp}] [NCP {ncp}] [DPS {dps}]",
data={"pokemon": pokemon.name,
"iv": pokemon.iv,
"cp": pokemon.cp})
"cp": pokemon.cp,
"ncp": round(pokemon.ncp, 2),
"dps": round(pokemon.dps, 2)})

if self.config_transfer:
inventory.candies().get(pokemon.pokemon_id).add(1)
Expand All @@ -231,30 +256,31 @@ def transfer_pokemon(self, pokemon):
def use_lucky_egg(self):
lucky_egg = inventory.items().get(Item.ITEM_LUCKY_EGG.value) # @UndefinedVariable

if self.config_evolve and self.config_use_lucky_egg:
response_dict = self.bot.use_lucky_egg()
lucky_egg.remove(1)
else:
response_dict = {"responses": {"USE_ITEM_XP_BOOST": {"result": 1}}}
if lucky_egg.count == 0:
return

response_dict = self.bot.use_lucky_egg()

if not response_dict:
self.emit_event("lucky_egg_error",
level='error',
formatted="Failed to use lucky egg!")
return False
return

result = response_dict.get("responses", {}).get("USE_ITEM_XP_BOOST", {}).get("result", 0)

if result == 1:
lucky_egg.remove(1)

self.emit_event("used_lucky_egg",
formatted="Used lucky egg ({amount_left} left).",
data={"amount_left": lucky_egg.count})
return True
return
else:
self.emit_event("lucky_egg_error",
level='error',
formatted="Failed to use lucky egg!")
return False
return

def evolve_pokemon(self, pokemon):
if self.config_evolve:
Expand All @@ -270,10 +296,12 @@ def evolve_pokemon(self, pokemon):

if result == 1:
self.emit_event("pokemon_evolved",
formatted="Evolved {pokemon} [IV {iv}] [CP {cp}] [+{xp} xp]",
formatted="Evolved {pokemon} [IV {iv}] [CP {cp}] [NCP {ncp}] [DPS {dps}] [+{xp} xp]",
data={"pokemon": pokemon.name,
"iv": pokemon.iv,
"cp": pokemon.cp,
"ncp": round(pokemon.ncp, 2),
"dps": round(pokemon.dps, 2),
"xp": xp})

if self.config_evolve:
Expand Down
4 changes: 3 additions & 1 deletion pokemongo_bot/cell_workers/transfer_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ def release_pokemon(self, pokemon):
data={
'pokemon': pokemon.name,
'cp': pokemon.cp,
'iv': pokemon.iv
'iv': pokemon.iv,
'ncp': '?',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do these need to be here but not need xp that you have in the other one?

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 don't gain xp when exchanging pokemons. After we may have to choose what stats are the most relevant to display. I am displaying what I think people are interested to see to make sure they don't release good pokemons.

'dps': '?'
}
)
action_delay(self.bot.config.action_wait_min, self.bot.config.action_wait_max)
Expand Down