Ejemplo n.º 1
0
def _find_best_move(battle: Battle):
    state = battle.to_object()
    logger.debug("Attempting to find best move from: {}".format(state))
    mutator = StateMutator(state)
    move_scores = get_move_combination_scores(mutator)
    logger.debug("Score lookups produced: {}".format(move_scores))

    decision = decide_random_from_average_and_safest(move_scores)
    logger.debug("Decision: {}".format(decision))

    if decision.startswith(constants.SWITCH_STRING) and decision != "switcheroo":
        switch_pokemon = decision.split("switch ")[-1]
        for pkmn in battle.user.reserve:
            if pkmn.name == switch_pokemon:
                message = "/switch {}".format(pkmn.index)
                break
        else:
            raise ValueError("Tried to switch to: {}".format(switch_pokemon))
    else:
        message = "/choose move {}".format(decision)
        if battle.user.active.can_mega_evo:
            message = "{} {}".format(message, constants.MEGA)
        elif battle.user.active.can_ultra_burst:
            message = "{} {}".format(message, constants.ULTRA_BURST)

        if battle.user.active.get_move(decision).can_z:
            message = "{} {}".format(message, constants.ZMOVE)

    return [message, str(battle.rqid)]
Ejemplo n.º 2
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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 5
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
     }