<commit_before>from smogon import SmogonMoveset
from team import Team, Pokemon
from browser import Selenium, SeleniumException
from log import SimulatorLog
from simulator import Simulator
from gamestate import GameState
from smogon import Smogon
import json
import re
import traceback

from agent import OptimisticMinimaxAgent, PessimisticMinimaxAgent

NAME_CORRECTIONS = {"Keldeo-Resolute": "Keldeo",
                    "Pikachu-Belle": "Pikachu",
                    "Pikachu-Cosplay": "Pikachu",
                    "Pikachu-Libre": "Pikachu",
                    "Pikachu-PhD": "Pikachu",
                    "Pikachu-Pop-Star": "Pikachu",
                    "Pikachu-Rock-Star": "Pikachu",
                    "Meowstic": "Meowstic-M",
                    "Gourgeist-*": "Gourgeist"}

class Showdown():
    def __init__(self, team_text, agent, username, password=<PASSWORD>, driver_path="./chromedriver"):
        self.selenium = Selenium(driver_path=driver_path)
        self.agent = agent
        self.username = username
        self.password = password
        self.team_text = team_text
        with open("data/poke2.json") as f:
            data = f.read()
        with open("data/poke_bw.json") as f2:
            data2 = f2.read()
        poke_data = json.loads(data)
        poke_bw_data = json.loads(data2)
        self.data = Smogon.convert_to_dict(poke_data)
        self.bw_data = Smogon.convert_to_dict(poke_bw_data)
        self.my_team = Team.make_team(team_text, self.data)
        self.opp_team = None
        self.simulator = Simulator()

    def reset(self):
        self.selenium.reset()
        self.opp_team = None
        self.my_team = Team.make_team(self.team_text, self.data)

    def create_initial_gamestate(self, my_team, opp_team):
        my_pokes = self.my_team.copy()
        primary = None
        for i, poke in enumerate(my_pokes.poke_list):
            poke_name = poke.name
            if poke_name in NAME_CORRECTIONS:
                poke_name = NAME_CORRECTIONS[poke_name]
            poke.health = my_team[poke_name]['health'] / 100.0 * poke.final_stats['hp']
            poke.alive = my_team[poke_name]['alive']
            if my_team[poke_name]['primary']:
                primary = i
        my_pokes.primary_poke = primary
        if not self.opp_team:
            opp_poke_names = list(opp_team.keys())
            opp_poke_list = []
            for name in opp_poke_names:
                if not name:
                    continue
                poke_name = name
                if name == "Keldeo-Resolute":
                    poke_name = "Keldeo"
                moveset = [m for m in self.data[poke_name].movesets if 'Overused' == m['tag'] or 'Underused' == m['tag'] or 'Rarelyused' == m['tag'] or 'Neverused' == m['tag'] or 'Unreleased' == m['tag'] or 'Ubers' == m['tag']]
                if not len(moveset):
                    moveset = [m for m in self.bw_data[poke_name].movesets if 'Overused' == m['tag'] or 'Underused' == m['tag'] or 'Rarelyused' == m['tag'] or 'Neverused' == m['tag'] or 'Unreleased' == m['tag'] or 'Ubers' == m['tag']]
                assert len(moveset), "No candidate movesets for %s" % name
                if len(moveset) >= 2 and (poke_name != "Latios" or poke_name != "Skarmory"):
                    moveset = SmogonMoveset.from_dict(moveset[1])
                else:
                    moveset = SmogonMoveset.from_dict(moveset[0])
                moveset.moves = moveset.moves[:4]
                typing = self.data[poke_name].typing
                stats = self.data[poke_name].stats
                poke = Pokemon(name, typing, stats, moveset, calculate=True)
                opp_poke_list.append(poke)<commit_msg>fixed name corrections<commit_after>from smogon import SmogonMoveset
from team import Team, Pokemon
from browser import Selenium, SeleniumException
from log import SimulatorLog
from simulator import Simulator
from gamestate import GameState
from smogon import Smogon
import json
import re
import traceback

from agent import OptimisticMinimaxAgent, PessimisticMinimaxAgent

NAME_CORRECTIONS = {"Keldeo-Resolute": "Keldeo",
                    "Pikachu-Belle": "Pikachu",
                    "Pikachu-Cosplay": "Pikachu",
                    "Pikachu-Libre": "Pikachu",
                    "Pikachu-PhD": "Pikachu",
                    "Pikachu-Pop-Star": "Pikachu",
                    "Pikachu-Rock-Star": "Pikachu",
                    "Meowstic": "Meowstic-M",
                    "Gourgeist-*": "Gourgeist"}

class Showdown():
    def __init__(self, team_text, agent, username, password=None, driver_path="./chromedriver"):
        self.selenium = Selenium(driver_path=driver_path)
        self.agent = agent
        self.username = username
        self.password = password
        self.team_text = team_text
        with open("data/poke2.json") as f:
            data = f.read()
        with open("data/poke_bw.json") as f2:
            data2 = f2.read()
        poke_data = json.loads(data)
        poke_bw_data = json.loads(data2)
        self.data = Smogon.convert_to_dict(poke_data)
        self.bw_data = Smogon.convert_to_dict(poke_bw_data)
        self.my_team = Team.make_team(team_text, self.data)
        self.opp_team = None
        self.simulator = Simulator()

    def reset(self):
        self.selenium.reset()
        self.opp_team = None
        self.my_team = Team.make_team(self.team_text, self.data)

    def create_initial_gamestate(self, my_team, opp_team):
        my_pokes = self.my_team.copy()
        primary = None
        for i, poke in enumerate(my_pokes.poke_list):
            poke_name = poke.name
            if poke_name in NAME_CORRECTIONS:
                poke_name = NAME_CORRECTIONS[poke_name]
            poke.health = my_team[poke_name]['health'] / 100.0 * poke.final_stats['hp']
            poke.alive = my_team[poke_name]['alive']
            if my_team[poke_name]['primary']:
                primary = i
        my_pokes.primary_poke = primary
        if not self.opp_team:
            opp_poke_names = list(opp_team.keys())
            opp_poke_list = []
            for name in opp_poke_names:
                if not name:
                    continue
                poke_name = name
                if poke_name in NAME_CORRECTIONS:
                    poke_name = NAME_CORRECTIONS[poke_name]
                moveset = [m for m in self.data[poke_name].movesets if 'Overused' == m['tag'] or 'Underused' == m['tag'] or 'Rarelyused' == m['tag'] or 'Neverused' == m['tag'] or 'Unreleased' == m['tag'] or 'Ubers' == m['tag']]
                if not len(moveset):
                    moveset = [m for m in self.bw_data[poke_name].movesets if 'Overused' == m['tag'] or 'Underused' == m['tag'] or 'Rarelyused' == m['tag'] or 'Neverused' == m['tag'] or 'Unreleased' == m['tag'] or 'Ubers' == m['tag']]
                assert len(moveset), "No candidate movesets for %s" % name
                if len(moveset) >= 2 and (poke_name != "Latios" or poke_name != "Skarmory"):
                    moveset = SmogonMoveset.from_dict(moveset[1])
                else:
                    moveset = SmogonMoveset.from_dict(moveset[0])
                moveset.moves = moveset.moves[:4]
                typing = self.data[poke_name].typing
                stats = self.data[poke_name].stats
                poke = Pokemon(name, typing, stats, moveset, calculate=True)
                opp_poke_list.append(poke)
{'fraction_non_alphanumeric': 0.11443520257579823, 'fraction_numerical': 0.00348806010195868, 'mean_word_length': 2.1270973154362416, 'pattern_counts': {'":': 19, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '854902', 'n_tokens_mistral': 2522, 'n_tokens_neox': 2410, 'n_words': 510}