Example #1
0
    def setUp(self):
        self.battle = Battle(None)
        self.battle.user.name = 'p1'
        self.battle.opponent.name = 'p2'

        self.opponent_active = Pokemon('caterpie', 100)
        self.battle.opponent.active = self.opponent_active
Example #2
0
async def parse_message(ps_websocket_client, msg, battles):
    split_msg = msg.split('|')

    if split_msg[1].strip() == 'updatechallenges':
        await ps_websocket_client.accept_challenge(split_msg, battles)
        return

    if split_msg[1].strip() == 'init' and split_msg[2].strip() == 'battle':
        battle = None
        for curr in battles:
            if curr.battle_tag == 'pending':
                battle = curr
                battle.battle_tag = split_msg[0].replace('>', '').strip()
                user_name = split_msg[-1].replace('☆', '').strip()
                battle.opponent.account_name = split_msg[4].replace(
                    user_name, '').replace('vs.', '').strip()
                battle.opponent.name = 'pending'
                break
        if battle == None:
            logger.debug("ERROR: can't find pending slot")
        return

    if 'battle' in split_msg[0]:
        battle = None
        i = 0
        for curr in battles:
            if curr.battle_tag == split_msg[0].replace('>', '').strip():
                battle = curr
                break
            i += 1
        if battle == None:
            logger.debug("ERROR: can't find battle slot")
            return
        if battle.opponent.name == 'pending':
            await initialize_battle(ps_websocket_client, battle, split_msg)
        elif battle.started == False:
            if battle.battle_type == constants.STANDARD_BATTLE:
                await run_start_standard_battle(ps_websocket_client, battle,
                                                msg)
                return
            else:
                await run_start_random_battle(ps_websocket_client, battle, msg)
                return
        else:
            ended = await pokemon_battle(ps_websocket_client, battle, msg)
            if (ended):
                battles[i] = Battle('empty')
            return

    if split_msg[1].strip() == 'pm' and '$' in split_msg[4]:
        await ps_websocket_client.parse_command(split_msg, battles)
        return
Example #3
0
async def _initialize_battle_with_tag(ps_websocket_client: PSWebsocketClient):
    battle_tag, opponent_name = await get_battle_tag_and_opponent(ps_websocket_client)
    while True:
        msg = await ps_websocket_client.receive_message()
        split_msg = msg.split('|')
        if split_msg[1].strip() == 'request' and split_msg[2].strip():
            user_json = json.loads(split_msg[2].strip('\''))
            user_id = user_json[constants.SIDE][constants.ID]
            opponent_id = constants.ID_LOOKUP[user_id]
            battle = Battle(battle_tag)
            battle.opponent.name = opponent_id
            battle.opponent.account_name = opponent_name
            return battle, opponent_id, user_json
Example #4
0
    def setUp(self):
        self.battle = Battle(None)
        self.battle.user.name = 'p1'
        self.battle.opponent.name = 'p2'

        self.user_active = Pokemon('caterpie', 100)
        self.opponent_active = Pokemon('caterpie', 100)

        # manually set hp to 200 for testing purposes
        self.opponent_active.max_hp = 200
        self.opponent_active.hp = 200

        self.battle.opponent.active = self.opponent_active
        self.battle.user.active = self.user_active
Example #5
0
    def setUp(self):
        self.battle = Battle(None)
        self.battle.user.name = 'p1'
        self.battle.opponent.name = 'p2'

        self.opponent_active = Pokemon('caterpie', 100)
        self.battle.opponent.active = self.opponent_active
        self.battle.opponent.active.ability = None

        self.user_active = Pokemon('weedle', 100)
        self.battle.user.active = self.user_active

        self.username = "******"

        self.battle.username = self.username
Example #6
0
async def showdown():
    env = Env()
    env.read_env()
    config.log_to_file = env.bool("LOG_TO_FILE", config.log_to_file)
    config.save_replay = env.bool("SAVE_REPLAY", config.save_replay)
    config.decision_method = env("DECISION_METHOD", config.decision_method)
    config.use_relative_weights = env.bool("USE_RELATIVE_WEIGHTS",
                                           config.use_relative_weights)
    config.gambit_exe_path = env("GAMBIT_PATH", config.gambit_exe_path)
    config.search_depth = int(env("MAX_SEARCH_DEPTH", config.search_depth))
    config.greeting_message = env("GREETING_MESSAGE", config.greeting_message)
    config.battle_ending_message = env("BATTLE_OVER_MESSAGE",
                                       config.battle_ending_message)
    logger.setLevel(env("LOG_LEVEL", "DEBUG"))
    websocket_uri = env("WEBSOCKET_URI", "sim.smogon.com:8000")
    username = env("PS_USERNAME")
    password = env("PS_PASSWORD", "")
    bot_mode = env("BOT_MODE")
    team_name = env("TEAM_NAME", None)
    pokemon_mode = env("POKEMON_MODE", constants.DEFAULT_MODE)

    apply_mods(pokemon_mode)
    original_pokedex = deepcopy(pokedex)
    original_move_json = deepcopy(all_move_json)

    ps_websocket_client = await PSWebsocketClient.create(
        username, password, websocket_uri)
    await ps_websocket_client.login()

    battles = []
    for i in range(5):
        battles.append(Battle('empty'))

    while True:
        msg = await ps_websocket_client.receive_message()
        """ loop = asyncio.get_event_loop()
        t = threading.Thread(target = thr, args=(ps_websocket_client, msg, battles))
        t.start() """

        await parse_message(ps_websocket_client, msg, battles)
Example #7
0
 def setUp(self):
     self.battle = Battle(None)
     self.battle.user.active = Pokemon('Pikachu', 100)
     self.battle.opponent.active = Pokemon('Pikachu', 100)
Example #8
0
 def setUp(self):
     self.battle = Battle(None)
     self.battle.user.active = Pokemon("pikachu", 100)
     self.request_json = {
         "active": [{
             "moves": [{
                 "move": "Storm Throw",
                 "id": "stormthrow",
                 "pp": 16,
                 "maxpp": 16,
                 "target": "normal",
                 "disabled": False
             }, {
                 "move": "Ice Punch",
                 "id": "icepunch",
                 "pp": 24,
                 "maxpp": 24,
                 "target": "normal",
                 "disabled": False
             }, {
                 "move": "Bulk Up",
                 "id": "bulkup",
                 "pp": 32,
                 "maxpp": 32,
                 "target": "self",
                 "disabled": False
             }, {
                 "move": "Knock Off",
                 "id": "knockoff",
                 "pp": 32,
                 "maxpp": 32,
                 "target": "normal",
                 "disabled": False
             }]
         }],
         "side": {
             "name":
             "NiceNameNerd",
             "id":
             "p1",
             "pokemon": [{
                 "ident":
                 "p1: Throh",
                 "details":
                 "Throh, L83, M",
                 "condition":
                 "335/335",
                 "active":
                 True,
                 "stats": {
                     "atk": 214,
                     "def": 189,
                     "spa": 97,
                     "spd": 189,
                     "spe": 122
                 },
                 "moves": ["stormthrow", "icepunch", "bulkup", "knockoff"],
                 "baseAbility":
                 "moldbreaker",
                 "item":
                 "leftovers",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "moldbreaker"
             }, {
                 "ident":
                 "p1: Empoleon",
                 "details":
                 "Empoleon, L77, F",
                 "condition":
                 "256/256",
                 "active":
                 False,
                 "stats": {
                     "atk": 137,
                     "def": 180,
                     "spa": 215,
                     "spd": 200,
                     "spe": 137
                 },
                 "moves": ["icebeam", "grassknot", "scald", "flashcannon"],
                 "baseAbility":
                 "torrent",
                 "item":
                 "choicespecs",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "torrent"
             }, {
                 "ident":
                 "p1: Emboar",
                 "details":
                 "Emboar, L79, M",
                 "condition":
                 "303/303",
                 "active":
                 False,
                 "stats": {
                     "atk": 240,
                     "def": 148,
                     "spa": 204,
                     "spd": 148,
                     "spe": 148
                 },
                 "moves":
                 ["headsmash", "superpower", "flareblitz", "grassknot"],
                 "baseAbility":
                 "reckless",
                 "item":
                 "assaultvest",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "reckless"
             }, {
                 "ident":
                 "p1: Zoroark",
                 "details":
                 "Zoroark, L77, M",
                 "condition":
                 "219/219",
                 "active":
                 False,
                 "stats": {
                     "atk": 166,
                     "def": 137,
                     "spa": 229,
                     "spd": 137,
                     "spe": 206
                 },
                 "moves":
                 ["sludgebomb", "darkpulse", "flamethrower", "focusblast"],
                 "baseAbility":
                 "illusion",
                 "item":
                 "choicespecs",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "illusion"
             }, {
                 "ident":
                 "p1: Reuniclus",
                 "details":
                 "Reuniclus, L78, M",
                 "condition":
                 "300/300",
                 "active":
                 False,
                 "stats": {
                     "atk": 106,
                     "def": 162,
                     "spa": 240,
                     "spd": 178,
                     "spe": 92
                 },
                 "moves": ["calmmind", "shadowball", "psyshock", "recover"],
                 "baseAbility":
                 "magicguard",
                 "item":
                 "lifeorb",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "magicguard"
             }, {
                 "ident":
                 "p1: Moltres",
                 "details":
                 "Moltres, L77",
                 "condition":
                 "265/265",
                 "active":
                 False,
                 "stats": {
                     "atk": 159,
                     "def": 183,
                     "spa": 237,
                     "spd": 175,
                     "spe": 183
                 },
                 "moves": ["fireblast", "toxic", "hurricane", "roost"],
                 "baseAbility":
                 "flamebody",
                 "item":
                 "leftovers",
                 "pokeball":
                 "pokeball",
                 "ability":
                 "flamebody"
             }]
         },
         "rqid":
         2
     }