Skip to content

Instantly share code, notes, and snippets.

@Kevin-Mok
Last active August 13, 2021 09:17
Show Gist options
  • Save Kevin-Mok/da287a6ac0e2717607bb98dfa1f86162 to your computer and use it in GitHub Desktop.
Save Kevin-Mok/da287a6ac0e2717607bb98dfa1f86162 to your computer and use it in GitHub Desktop.
Script to calculate the most common IV percentages in Pokemon Go.
from pprint import pprint
FLOOR_IV = 10
CEILING_IV = 15
IV_TYPES = 3
MAX_IV = CEILING_IV * IV_TYPES
def populate_iv_dict():
"""Returns iv_dict with key as IV percent and value as
number of IV combinations with that percent.
"""
iv_dict = {}
for attack in range(FLOOR_IV, CEILING_IV + 1):
for defense in range(FLOOR_IV, CEILING_IV + 1):
for hp in range(FLOOR_IV, CEILING_IV + 1):
iv_sum = attack + defense + hp
iv_percent = round(iv_sum / MAX_IV, 2)
if iv_percent not in iv_dict:
iv_dict[iv_percent] = 1
else:
iv_dict[iv_percent] += 1
return iv_dict
def get_iv_percentages(iv_dict):
"""Calculate odds of each IV based on iv_dict.
:iv_dict: dict where keys are IV percent and values are
number of IV combos with that percent. Created with
populate_iv_dict().
:returns: dict where keys are IV percent and values are odds.
"""
total_combos = sum(iv_dict.values())
iv_odds = {}
for iv_percent in iv_dict:
iv_odds[iv_percent] = round(iv_dict[iv_percent] / total_combos, 3)
return iv_odds
def print_iv_odds_as_csv(iv_odds):
"""Print iv_odds in CSV format.
:iv_odds: dict where keys are IV percent and values are odds.
"""
for iv_percent in iv_odds:
print(f'{iv_percent}\t{iv_odds[iv_percent]}')
if __name__ == "__main__":
iv_dict = populate_iv_dict()
iv_odds = get_iv_percentages(iv_dict)
print_iv_odds_as_csv(iv_odds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment