def test_teambuilder_pokemon_formatting():
    tp = TeambuilderPokemon(
        nickname="testy",
        species="Dragonair",
        item="choiceband",
        ability="shedskin",
        moves=["tackle", "watergun", "hiddenpower"],
        nature="Adamant",
        evs=[0] * 6,
        gender="M",
        ivs=[31] * 6,
        shiny=True,
        level=84,
        happiness=134,
        hiddenpowertype="water",
        gmax=True,
    )
    assert (
        tp.formatted
        == "testy|dragonair|choiceband|shedskin|tackle,watergun,hiddenpower|Adamant||M|\
|S|84|134,water,,G"
    )

    assert (
        str(tp)
        == "testy|dragonair|choiceband|shedskin|tackle,watergun,hiddenpower|Adamant"
        "||M||S|84|134,water,,G"
    )
    assert (
        repr(tp)
        == "testy|dragonair|choiceband|shedskin|tackle,watergun,hiddenpower|Adamant||M"
        "||S|84|134,water,,G"
    )
Esempio n. 2
0
def random_mon():
    mon = np.random.choice(mons)

    if POKEDEX[mon]["num"] <= 0 or POKEDEX[mon]["num"] == 79:
        return random_mon()

    if "baseSpecies" in POKEDEX[mon]:
        mon = POKEDEX[mon]["baseSpecies"]
    else:
        mon = POKEDEX[mon]["species"]

    mon = to_id_str(mon)
    mon = mon.replace("é", "e")

    if mon in movesets and "learnset" in movesets[mon]:
        moveset = movesets[mon]["learnset"]
        learnset = []
        for move in moveset:
            for entry in moveset[move]:
                if entry.startswith("8L") or entry.startswith("8T"):
                    learnset.append(move)
                    break

        if not len(learnset):
            return random_mon()
        elif len(learnset) > 4:
            moves = list(np.random.choice(learnset, size=4, replace=False))
        else:
            moves = learnset
        return TeambuilderPokemon(species=mon, moves=moves, evs=random_evs())
    else:
        print("Problematic mon:", mon)
        if mon in movesets:
            print("is in moveset")
        else:
            print("not in moveset")
        return random_mon()
Esempio n. 3
0
    def parse_showdown_team(team: str) -> List[TeambuilderPokemon]:
        """Converts a showdown-formatted team string into a list of TeambuilderPokemon
        objects.

        This method can be used when using teams built in the showdown teambuilder.

        :param team: The showdown-format team to convert.
        :type team: str
        :return: The formatted team.
        :rtype: list of TeambuilderPokemon
        """
        current_mon = None
        mons = []

        for line in team.split("\n"):
            if line == "":
                if current_mon is not None:
                    mons.append(current_mon)
                current_mon = None
            elif line.startswith("Ability"):
                ability = line.replace("Ability: ", "")
                current_mon.ability = ability.strip()
            elif line.startswith("Level: "):
                level = line.replace("Level: ", "")
                current_mon.level = level.strip()
            elif line.startswith("Happiness: "):
                happiness = line.replace("Happiness: ", "")
                current_mon.happiness = happiness.strip()
            elif line.startswith("EVs: "):
                evs = line.replace("EVs: ", "")
                evs = evs.split(" / ")
                for ev in evs:
                    ev = ev.split(" ")
                    n = ev[0]
                    stat = ev[1]
                    idx = current_mon.STATS_TO_IDX[stat.lower()]
                    current_mon.evs[idx] = n
            elif line.startswith("IVs: "):
                ivs = line.replace("IVs: ", "")
                ivs = ivs.split(" / ")
                for iv in ivs:
                    iv = iv.split(" ")
                    n = iv[0]
                    stat = iv[1]
                    idx = current_mon.STATS_TO_IDX[stat.lower()]
                    current_mon.ivs[idx] = n
            elif line.startswith("- "):
                line = line.replace("- ", "").strip()
                current_mon.moves.append(line)
            elif line.startswith("Shiny"):
                current_mon.shiny = line.strip().endswith("Yes")
            elif line.strip().endswith(" Nature"):
                nature = line.strip().replace(" Nature", "")
                current_mon.nature = nature
            elif line.startswith("Hidden Power: "):
                hp_type = line.replace("Hidden Power: ", "").strip()
                current_mon.hiddenpowertype = hp_type
            else:
                current_mon = TeambuilderPokemon()
                if "@" in line:
                    mon_info, item = line.split(" @ ")
                    current_mon.item = item.strip()
                split_mon_info = mon_info.split(" ")

                if split_mon_info[-1] == "(M)":
                    current_mon.gender = "M"
                    split_mon_info.pop()
                if split_mon_info[-1] == "(F)":
                    current_mon.gender = "F"
                    split_mon_info.pop()
                if split_mon_info[-1].endswith(")"):
                    for i, info in enumerate(split_mon_info):
                        if info[0] == "(":
                            current_mon.species = " ".join(
                                split_mon_info[i:])[1:-1]
                            split_mon_info = split_mon_info[:i]
                            break
                    current_mon.nickname = " ".join(split_mon_info)
                current_mon.nickname = " ".join(split_mon_info)
        if current_mon is not None:
            mons.append(current_mon)
        return mons