from stat_product import *
from tqdm import tqdm
from pprint import pprint

def best_pvp(name):
    max_lvl = 0
    for lvl in range(2,81):
        # exit()
        c = cp(name, 0,0,0, lvl/2)
        if c == 10:
            max_lvl = lvl/2
    if max_lvl == 0:
        return None
    big_combo = [(0,0,0,0)]
    biggest = 0
    for lvl in range(2, int(max_lvl*2)+1):
        for a in range(0,16):
            for d in range(0,16):
                for s in range(0,16):
                    p = product(name, lvl/2, a, d, s)
                    if p >= biggest and cp(name, a, d, s, lvl/2) == 10:
                        if p == biggest:
                            big_combo.append((lvl/2, a, d, s))
                        else:
                            biggest = p
                            big_combo = [(lvl/2, a, d, s)]
    return biggest, big_combo


def calc_it():
    combos = {}
    # for x in stats.keys():
    for x in tqdm(list(stats.keys())):
        best = best_pvp(x)
        if best != None:
            combos[x] = best
    pprint(combos)
        # print(x)

if False:
    calc_it()

combos = {'<NAME>': (418274.78036185505, [(1.0, 15, 14, 0), (1.0, 15, 15, 0)]),
 '<NAME>': (615705.1535035549, [(1.0, 15, 15, 0)]),
 '<NAME>': (507953.62876990385, [(1.0, 15, 15, 0)]),
 '<NAME>': (723853.9073684987, [(1.0, 7, 15, 0)]),
 'Azurill': (241710.17894692207, [(1.5, 15, 15, 0)]),
 'Baltoy': (717793.0402457573, [(1.0, 15, 15, 0)]),
 'Barboach': (677689.1369119541, [(1.0, 15, 14, 0)]),
 'Beldum': (807701.7319247427, [(1.0, 0, 8, 0)]),
 'Bidoof': (587659.2778564424, [(1.0, 15, 15, 0)]),
 'Bronzor': (599118.9635497708, [(1.0, 15, 15, 0)]),
 'Budew': (730901.6015784136, [(1.0, 11, 15, 0)]),
 'Carvanha': (477404.4601067207, [(1.0, 5, 0, 0)]),
 'Cascoon': (420613.18581399275, [(1.0, 15, 15, 0)]),
 'Caterpie': (276661.34590782586, [(1.0, 15, 15, 0)]),
 'Charmander': (652561.2714871671, [(1.0, 2, 1, 0)]),
 'Cherubi': (684734.3328254457, [(1.0, 2, 8, 0)]),
 'Chikorita': (813892.5104614916, [(1.0, 2, 15, 0)]),
 'Chimchar': (657901.3800918085, [(1.0, 2, 6, 0)]),
 'Cleffa': (535434.8894253678, [(1.0, 15, 15, 0)]),
 'Combee': (337869.6082768139, [(1.0, 15, 15, 0)]),
 'Croagunk': (637215.4857075136, [(1.0, 4, 4, 0)]),
 'Cyndaquil': (652561.2714871671, [(1.0, 2, 1, 0)]),
 'Diglett': (408921.15855330444, [(1.0, 15, 14, 0), (1.0, 15, 15, 0)]),
 'Ditto': (699872.7600019716, [(1.0, 14, 13, 0)]),
 'Duskull': (620072.8002254562, [(1.0, 15, 15, 0)]),
 'Ekans': (672617.5951728093, [(1.0, 1, 15, 0), (1.0, 2, 14, 0)]),
 'Electrike': (609664.2727521994, [(1.0, 4, 2, 0)]),
 'Feebas': (151428.61652677055, [(2.0, 14, 15, 0)]),
 'Finneon': (794130.9857537899, [(1.0, 0, 8, 0)]),
 'Glameow': (666489.274046641, [(1.0, 7, 3, 0)]),
 'Gulpin': (799582.8931233705, [(1.0, 10, 12, 0)]),
 'Happiny': (287792.5056215004, [(1.5, 15, 15, 0)]),
 'Hoothoot': (586185.2829667402, [(1.0, 15, 15, 0)]),
 'Hoppip': (458304.98395117326, [(1.0, 15, 15, 0)]),
 'Igglybuff': (359598.54141780466, [(1.0, 15, 15, 0)]),
 'Jigglypuff': (594944.3102265636, [(1.0, 15, 15, 0)]),
 'Kakuna': (298540.17683421005, [(1.0, 15, 15, 0)]),
 'Kirlia': (643398.7693549929, [(1.0, 0, 7, 0)]),
 'Kricketot': (261064.7936246913, [(1.5, 15, 14, 0)]),
 'Ledyba': (642782.9392866683, [(1.0, 15, 15, 0)]),
 'Lotad': (438540.96094704815, [(1.0, 15, 15, 0)]),
 'Luvdisc': (788712.1808118171, [(1.0, 12, 15, 0)]),
 'Magikarp': (151428.61652677055, [(2.0, 14, 15, 0)]),
 'Makuhita': (642124.6381791487, [(1.0, 15, 13, 0)]),
 'Mareep': (666545.4857161634, [(1.0, 1, 1, 0)]),
 'Marill': (376798.06314349023, [(1.0, 15, 15, 0)]),
 'Meditite': (553807.3613217571, [(1.0, 15, 15, 0)]),
 'Meowth': (572605.7927583061, [(1.0, 15, 15, 0)]),
 'Metapod': (327526.6610846665, [(1.0, 15, 15, 0)]),
 'Nidoran': (649469.6296634274, [(1.0, 14, 8, 0)]),
 'Nincada': (670526.5210665709, [(1.0, 15, 15, 0)]),
 'Nosepass': (980806.1927935104, [(1.0, 0, 10, 0)]),
 'Pichu': (261706.54351840698, [(1.0, 15, 15, 0)]),
 'Pidgey': (501038.34427041974, [(1.0, 15, 15, 0)]),
 'Pikachu': (670762.6100785654, [(1.0, 0, 15, 0)]),
 '<NAME>': (350356.0938000874, [(1.0, 15, 15, 0)]),
 'Poliwag': (648851.3012986794, [(1.0, 15, 13, 0)]),
 'Poochyena': (455831.67049218155, [(1.0, 15, 15, 0)]),
 'Ralts': (332773.0835734369, [(1.0, 15, 15, 0)]),
 'Rattata': (507953.62876990385, [(1.0, 15, 15, 0)]),
 'Remoraid': (584241.6083494719, [(1.0, 15, 0, 0)]),
 'Riolu': (598631.7957472422, [(1.0, 0, 2, 0)]),
 '<NAME>': (350356.0938000874, [(1.0, 15, 15, 0)]),
 'Seedot': (438540.96094704815, [(1.0, 15, 15, 0)]),
 'Seel': (883907.2677223444, [(1.0, 0, 10, 0)]),
 'Sentret': (435303.16878254997, [(1.0, 15, 15, 0)]),
 'Shedinja': (103549.39014978838, [(4.0, 15, 15, 0)]),
 'Shieldon': (902594.5249680598, [(1.0, 9, 15, 0)]),
 'Shinx': (611339.3805039711, [(1.0, 15, 5, 0)]),
 'Shroomish': (784621.2204187878, [(1.0, 15, 15, 0)]),
 'Shuckle': (375166.9878661779, [(1.5, 15, 15, 0)]),
 'Silcoon': (420613.18581399275, [(1.0, 15, 15, 0)]),
 'Skiploom': (834331.0734998873, [(1.0, 0, 8, 0)]),
 'Skitty': (598841.652646793, [(1.0, 15, 15, 0)]),
 'Slakoth': (736073.0751744873, [(1.0, 0, 0, 0)]),
 'Slugma': (613621.5742865861, [(1.0, 15, 2, 0)]),
 'Smeargle': (318711.4221553206, [(1.0, 15, 15, 0)]),
 'Snorunt': (726704.4635873974, [(1.0, 6, 15, 0)]),
 'Spearow': (561086.1479508203, [(1.0, 15, 15, 0)]),
 'Spheal': (771673.7992054292, [(1.0, 0, 9, 0)]),
 'Spinarak': (617558.8894495871, [(1.0, 15, 15, 0)]),
 'Squirtle': (804101.6867788769, [(1.0, 0, 15, 0)]),
 'Starly': (492961.3519341366, [(1.0, 15, 15, 0)]),
 'Sunkern': (227257.53413857124, [(1.5, 15, 15, 0)]),
 'Surskit': (634772.1518056006, [(1.0, 15, 15, 0)]),
 'Swablu': (793425.217014229, [(1.0, 14, 15, 0)]),
 'Swinub': (572909.335773728, [(1.0, 15, 15, 0)]),
 'Taillow': (538377.8826119257, [(1.0, 15, 15, 0)]),
 'Togepi': (550806.907317465, [(1.0, 15, 15, 0)]),
 'Trash Burmy': (350356.0938000874, [(1.0, 15, 15, 0)]),
 'Tyrogue': (317511.6152980673, [(1.0, 15, 15, 0)]),
 'Vulpix': (723853.9073684987, [(1.0, 7, 15, 0)]),
 'Weedle': (275412.19769621384, [(1.0, 15, 15, 0)]),
 'Whismur': (460210.55954798736, [(1.0, 15, 14, 0), (1.0, 15, 15, 0)]),
 'Wingull': (538377.8826119257, [(1.0, 15, 15, 0)]),
 'Wobbuffet': (1239284.9373331121, [(1.0, 1, 3, 0)]),
 'Wooper': (488299.53080840065, [(1.0, 15, 15, 0)]),
 'Wurmple': (396924.33912898274, [(1.0, 15, 15, 0)]),
 'Wynaut': (482198.6909428877, [(1.0, 15, 15, 0)]),
 'Zigzagoon': (360575.999893391, [(1.0, 15, 15, 0)]),
 'Zubat': (489386.2897525031, [(1.0, 15, 15, 0)])}

l = []
for k,v in combos.items():
    l += [(v[0], k, v[1])]

def make_decimal(n):
    return 

l = sorted(l, key=operator.itemgetter(0), reverse=True)
format_d = {}
for p, name, stats in l:
    stats = " OR ".join([f'L{int(lvl) if lvl == int(lvl) else lvl} {a}/{d}/{s}' for lvl, a, d, s in stats])
    format_d[name] = stats

num_spaces = max(len(x) for x in format_d.keys()) + 1
for k,v in format_d.items():
    print(f'{k}{" "*(num_spaces-len(k))}: {v}')

# print(cp('Wobbuffet', 15, 15, 0, 1))
print(len(combos))
from stat_product import *
from tqdm import tqdm
from pprint import pprint

def best_pvp(name):
    max_lvl = 0
    for lvl in range(2,81):
        # exit()
        c = cp(name, 0,0,0, lvl/2)
        if c == 10:
            max_lvl = lvl/2
    if max_lvl == 0:
        return None
    big_combo = [(0,0,0,0)]
    biggest = 0
    for lvl in range(2, int(max_lvl*2)+1):
        for a in range(0,16):
            for d in range(0,16):
                for s in range(0,16):
                    p = product(name, lvl/2, a, d, s)
                    if p >= biggest and cp(name, a, d, s, lvl/2) == 10:
                        if p == biggest:
                            big_combo.append((lvl/2, a, d, s))
                        else:
                            biggest = p
                            big_combo = [(lvl/2, a, d, s)]
    return biggest, big_combo


def calc_it():
    combos = {}
    # for x in stats.keys():
    for x in tqdm(list(stats.keys())):
        best = best_pvp(x)
        if best != None:
            combos[x] = best
    pprint(combos)
        # print(x)

if False:
    calc_it()

combos = {'<NAME>': (418274.78036185505, [(1.0, 15, 14, 0), (1.0, 15, 15, 0)]),
 '<NAME>': (615705.1535035549, [(1.0, 15, 15, 0)]),
 '<NAME>': (507953.62876990385, [(1.0, 15, 15, 0)]),
 '<NAME>': (723853.9073684987, [(1.0, 7, 15, 0)]),
 'Azurill': (241710.17894692207, [(1.5, 15, 15, 0)]),
 'Baltoy': (717793.0402457573, [(1.0, 15, 15, 0)]),
 'Barboach': (677689.1369119541, [(1.0, 15, 14, 0)]),
 'Beldum': (807701.7319247427, [(1.0, 0, 8, 0)]),
 'Bidoof': (587659.2778564424, [(1.0, 15, 15, 0)]),
 'Bronzor': (599118.9635497708, [(1.0, 15, 15, 0)]),
 'Budew': (730901.6015784136, [(1.0, 11, 15, 0)]),
 'Carvanha': (477404.4601067207, [(1.0, 5, 0, 0)]),
 'Cascoon': (420613.18581399275, [(1.0, 15, 15, 0)]),
 'Caterpie': (276661.34590782586, [(1.0, 15, 15, 0)]),
 'Charmander': (652561.2714871671, [(1.0, 2, 1, 0)]),
 'Cherubi': (684734.3328254457, [(1.0, 2, 8, 0)]),
 'Chikorita': (813892.5104614916, [(1.0, 2, 15, 0)]),
 'Chimchar': (657901.3800918085, [(1.0, 2, 6, 0)]),
 'Cleffa': (535434.8894253678, [(1.0, 15, 15, 0)]),
 'Combee': (337869.6082768139, [(1.0, 15, 15, 0)]),
 'Croagunk': (637215.4857075136, [(1.0, 4, 4, 0)]),
 'Cyndaquil': (652561.2714871671, [(1.0, 2, 1, 0)]),
 'Diglett': (408921.15855330444, [(1.0, 15, 14, 0), (1.0, 15, 15, 0)]),
 'Ditto': (699872.7600019716, [(1.0, 14, 13, 0)]),
 'Duskull': (620072.8002254562, [(1.0, 15, 15, 0)]),
 'Ekans': (672617.5951728093, [(1.0, 1, 15, 0), (1.0, 2, 14, 0)]),
 'Electrike': (609664.2727521994, [(1.0, 4, 2, 0)]),
 'Feebas': (151428.61652677055, [(2.0, 14, 15, 0)]),
 'Finneon': (794130.9857537899, [(1.0, 0, 8, 0)]),
 'Glameow': (666489.274046641, [(1.0, 7, 3, 0)]),
 'Gulpin': (799582.8931233705, [(1.0, 10, 12, 0)]),
 'Happiny': (287792.5056215004, [(1.5, 15, 15, 0)]),
 'Hoothoot': (586185.2829667402, [(1.0, 15, 15, 0)]),
 'Hoppip': (458304.98395117326, [(1.0, 15, 15, 0)]),
 'Igglybuff': (359598.54141780466, [(1.0, 15, 15, 0)]),
 'Jigglypuff': (594944.3102265636, [(1.0, 15, 15, 0)]),
 'Kakuna': (298540.17683421005, [(1.0, 15, 15, 0)]),
 'Kirlia': (643398.7693549929, [(1.0, 0, 7, 0)]),
 'Kricketot': (261064.7936246913, [(1.5, 15, 14, 0)]),
 'Ledyba': (642782.9392866683, [(1.0, 15, 15, 0)]),
 'Lotad': (438540.96094704815, [(1.0, 15, 15, 0)]),
 'Luvdisc': (788712.1808118171, [(1.0, 12, 15, 0)]),
 'Magikarp': (151428.61652677055, [(2.0, 14, 15, 0)]),
 'Makuhita': (642124.6381791487, [(1.0, 15, 13, 0)]),
 'Mareep': (666545.4857161634, [(1.0, 1, 1, 0)]),
 'Marill': (376798.06314349023, [(1.0, 15, 15, 0)]),
 'Meditite': (553807.3613217571, [(1.0, 15, 15, 0)]),
 'Meowth': (572605.7927583061, [(1.0, 15, 15, 0)]),
 'Metapod': (327526.6610846665, [(1.0, 15, 15, 0)]),
 'Nidoran': (649469.6296634274, [(1.0, 14, 8, 0)]),
 'Nincada': (670526.5210665709, [(1.0, 15, 15, 0)]),
 'Nosepass': (980806.1927935104, [(1.0, 0, 10, 0)]),
 'Pichu': (261706.54351840698, [(1.0, 15, 15, 0)]),
 'Pidgey': (501038.34427041974, [(1.0, 15, 15, 0)]),
 'Pikachu': (670762.6100785654, [(1.0, 0, 15, 0)]),
 '<NAME>': (350356.0938000874, [(1.0, 15, 15, 0)]),
 'Poliwag': (648851.3012986794, [(1.0, 15, 13, 0)]),
 'Poochyena': (455831.67049218155, [(1.0, 15, 15, 0)]),
 'Ralts': (332773.0835734369, [(1.0, 15, 15, 0)]),
 'Rattata': (507953.62876990385, [(1.0, 15, 15, 0)]),
 'Remoraid': (584241.6083494719, [(1.0, 15, 0, 0)]),
 'Riolu': (598631.7957472422, [(1.0, 0, 2, 0)]),
 '<NAME>': (350356.0938000874, [(1.0, 15, 15, 0)]),
 'Seedot': (438540.96094704815, [(1.0, 15, 15, 0)]),
 'Seel': (883907.2677223444, [(1.0, 0, 10, 0)]),
 'Sentret': (435303.16878254997, [(1.0, 15, 15, 0)]),
 'Shedinja': (103549.39014978838, [(4.0, 15, 15, 0)]),
 'Shieldon': (902594.5249680598, [(1.0, 9, 15, 0)]),
 'Shinx': (611339.3805039711, [(1.0, 15, 5, 0)]),
 'Shroomish': (784621.2204187878, [(1.0, 15, 15, 0)]),
 'Shuckle': (375166.9878661779, [(1.5, 15, 15, 0)]),
 'Silcoon': (420613.18581399275, [(1.0, 15, 15, 0)]),
 'Skiploom': (834331.0734998873, [(1.0, 0, 8, 0)]),
 'Skitty': (598841.652646793, [(1.0, 15, 15, 0)]),
 'Slakoth': (736073.0751744873, [(1.0, 0, 0, 0)]),
 'Slugma': (613621.5742865861, [(1.0, 15, 2, 0)]),
 'Smeargle': (318711.4221553206, [(1.0, 15, 15, 0)]),
 'Snorunt': (726704.4635873974, [(1.0, 6, 15, 0)]),
 'Spearow': (561086.1479508203, [(1.0, 15, 15, 0)]),
 'Spheal': (771673.7992054292, [(1.0, 0, 9, 0)]),
 'Spinarak': (617558.8894495871, [(1.0, 15, 15, 0)]),
 'Squirtle': (804101.6867788769, [(1.0, 0, 15, 0)]),
 'Starly': (492961.3519341366, [(1.0, 15, 15, 0)]),
 'Sunkern': (227257.53413857124, [(1.5, 15, 15, 0)]),
 'Surskit': (634772.1518056006, [(1.0, 15, 15, 0)]),
 'Swablu': (793425.217014229, [(1.0, 14, 15, 0)]),
 'Swinub': (572909.335773728, [(1.0, 15, 15, 0)]),
 'Taillow': (538377.8826119257, [(1.0, 15, 15, 0)]),
 'Togepi': (550806.907317465, [(1.0, 15, 15, 0)]),
 'Trash Burmy': (350356.0938000874, [(1.0, 15, 15, 0)]),
 'Tyrogue': (317511.6152980673, [(1.0, 15, 15, 0)]),
 'Vulpix': (723853.9073684987, [(1.0, 7, 15, 0)]),
 'Weedle': (275412.19769621384, [(1.0, 15, 15, 0)]),
 'Whismur': (460210.55954798736, [(1.0, 15, 14, 0), (1.0, 15, 15, 0)]),
 'Wingull': (538377.8826119257, [(1.0, 15, 15, 0)]),
 'Wobbuffet': (1239284.9373331121, [(1.0, 1, 3, 0)]),
 'Wooper': (488299.53080840065, [(1.0, 15, 15, 0)]),
 'Wurmple': (396924.33912898274, [(1.0, 15, 15, 0)]),
 'Wynaut': (482198.6909428877, [(1.0, 15, 15, 0)]),
 'Zigzagoon': (360575.999893391, [(1.0, 15, 15, 0)]),
 'Zubat': (489386.2897525031, [(1.0, 15, 15, 0)])}

l = []
for k,v in combos.items():
    l += [(v[0], k, v[1])]

def make_decimal(n):
    return 

l = sorted(l, key=operator.itemgetter(0), reverse=True)
format_d = {}
for p, name, stats in l:
    stats = " OR ".join([f'L{int(lvl) if lvl == int(lvl) else lvl} {a}/{d}/{s}' for lvl, a, d, s in stats])
    format_d[name] = stats

num_spaces = max(len(x) for x in format_d.keys()) + 1
for k,v in format_d.items():
    print(f'{k}{" "*(num_spaces-len(k))}: {v}')

# print(cp('Wobbuffet', 15, 15, 0, 1))
print(len(combos))
# exit() # for x in stats.keys(): # print(x) # print(cp('Wobbuffet', 15, 15, 0, 1))