Example #1
0
    def test_nastyplot_with_choicespecs_does_not_make_sense(self):
        nature = 'jolly'
        spread = '0,0,0,252,4,252'
        item = 'choicespecs'
        ability = 'intimidate'
        moves = [Move('nastyplot')]

        self.assertFalse(set_makes_sense(nature, spread, item, ability, moves))
Example #2
0
    def test_swordsdance_with_choiceband_does_not_make_sense(self):
        nature = 'jolly'
        spread = '0,0,0,252,4,252'
        item = 'choiceband'
        ability = 'intimidate'
        moves = [Move('swordsdance')]

        self.assertFalse(set_makes_sense(nature, spread, item, ability, moves))
Example #3
0
    def test_standard_set_makes_sense(self):
        nature = 'jolly'
        spread = '0,0,0,252,4,252'
        item = 'unknown_item'
        ability = 'intimidate'
        moves = []

        self.assertTrue(set_makes_sense(nature, spread, item, ability, moves))
Example #4
0
    def test_trick_with_scarf_makes_sense(self):
        nature = 'jolly'
        spread = '0,0,0,252,4,252'
        item = 'choicescarf'
        ability = 'intimidate'
        moves = [
            Move('trick'),
            Move('darkpulse'),
            Move('thunderbolt'),
        ]

        self.assertTrue(set_makes_sense(nature, spread, item, ability, moves))
Example #5
0
    def prepare_battles(self,
                        guess_mega_evo_opponent=True,
                        join_moves_together=False):
        """Returns a list of battles based on this one
        The battles have the opponent's reserve pokemon's unknowns filled in
        The opponent's active pokemon in each of the battles has a different set"""
        battle_copy = deepcopy(self)
        battle_copy.opponent.lock_moves()

        if battle_copy.user.active.can_mega_evo:
            # mega-evolving here gives the pkmn the random-battle spread (Serious + 85s)
            # unfortunately the correct spread is not stored anywhere as of this being written
            # this only happens on the turn the pkmn mega-evolves - the next turn will be fine
            battle_copy.user.active.forme_change(
                get_mega_pkmn_name(battle_copy.user.active.name))

        if guess_mega_evo_opponent and not battle_copy.opponent.mega_revealed(
        ) and self.mega_evolve_possible():
            check_in_sets = battle_copy.battle_type == constants.STANDARD_BATTLE
            battle_copy.opponent.active.try_convert_to_mega(
                check_in_sets=check_in_sets)

        # for reserve pokemon only guess their most likely item/ability/spread and guess all moves
        for pkmn in filter(lambda x: x.is_alive(),
                           battle_copy.opponent.reserve):
            pkmn.guess_most_likely_attributes()

        try:
            pokemon_sets = get_pokemon_sets(battle_copy.opponent.active.name)
        except KeyError:
            logger.warning("No set for {}".format(
                battle_copy.opponent.active.name))
            return [battle_copy]

        possible_spreads = sorted(pokemon_sets[SPREADS_STRING],
                                  key=lambda x: x[2],
                                  reverse=True)
        possible_abilities = sorted(pokemon_sets[ABILITY_STRING],
                                    key=lambda x: x[1],
                                    reverse=True)
        possible_items = sorted(pokemon_sets[ITEM_STRING],
                                key=lambda x: x[1],
                                reverse=True)
        possible_moves = sorted(pokemon_sets[MOVES_STRING],
                                key=lambda x: x[1],
                                reverse=True)

        spreads = battle_copy.opponent.active.get_possible_spreads(
            possible_spreads)
        items = battle_copy.opponent.active.get_possible_items(possible_items)
        abilities = battle_copy.opponent.active.get_possible_abilities(
            possible_abilities)
        expected_moves, chance_moves = battle_copy.opponent.active.get_possible_moves(
            possible_moves, battle_copy.battle_type)

        if join_moves_together:
            chance_move_combinations = [chance_moves]
        else:
            number_of_unknown_moves = max(
                4 - len(battle_copy.opponent.active.moves) -
                len(expected_moves), 0)
            chance_move_combinations = list(
                itertools.combinations(chance_moves, number_of_unknown_moves))

        combinations = list(
            itertools.product(spreads, items, abilities,
                              chance_move_combinations))

        # create battle clones for each of the combinations
        battles = list()
        for c in combinations:
            new_battle = deepcopy(battle_copy)

            all_moves = [m.name for m in new_battle.opponent.active.moves]
            all_moves += expected_moves
            all_moves += c[3]
            all_moves = [Move(m) for m in all_moves]

            if join_moves_together or set_makes_sense(c[0][0], c[0][1], c[1],
                                                      c[2], all_moves):
                new_battle.opponent.active.set_spread(c[0][0], c[0][1])
                if new_battle.opponent.active.name == 'ditto':
                    new_battle.opponent.active.stats = battle_copy.opponent.active.stats
                new_battle.opponent.active.item = c[1]
                new_battle.opponent.active.ability = c[2]
                for m in expected_moves:
                    new_battle.opponent.active.add_move(m)
                for m in c[3]:
                    new_battle.opponent.active.add_move(m)

                logger.debug(
                    "Possible set for opponent's {}:\t{} {} {} {} {}".format(
                        battle_copy.opponent.active.name, c[0][0], c[0][1],
                        c[1], c[2], all_moves))
                battles.append(new_battle)

            new_battle.opponent.lock_moves()

        return battles if battles else [battle_copy]
Example #6
0
    def prepare_battles(self, join_moves_together=False):
        """Returns a list of battles based on this one
        The battles have the opponent's reserve pokemon's unknowns filled in
        The opponent's active pokemon in each of the battles has a different set"""
        battle_copy = deepcopy(self)

        if not battle_copy.opponent.mega_revealed():
            check_in_sets = battle_copy.battle_type == constants.STANDARD_BATTLE
            battle_copy.opponent.active.try_convert_to_mega(
                check_in_sets=check_in_sets)

        # for reserve pokemon only guess their most likely item/ability/spread and guess all moves
        for pkmn in filter(lambda x: x.is_alive(),
                           battle_copy.opponent.reserve):
            pkmn.guess_most_likely_attributes()

        try:
            pokemon_sets = get_pokemon_sets(battle_copy.opponent.active.name)
        except KeyError:
            logger.warning("No set for {}".format(
                battle_copy.opponent.active.name))
            return [battle_copy]

        possible_spreads = sorted(pokemon_sets[SPREADS_STRING],
                                  key=lambda x: x[2],
                                  reverse=True)
        possible_abilities = sorted(pokemon_sets[ABILITY_STRING],
                                    key=lambda x: x[1],
                                    reverse=True)
        possible_items = sorted(pokemon_sets[ITEM_STRING],
                                key=lambda x: x[1],
                                reverse=True)
        possible_moves = sorted(pokemon_sets[MOVES_STRING],
                                key=lambda x: x[1],
                                reverse=True)

        spreads = battle_copy.opponent.active.get_possible_spreads(
            possible_spreads)
        items = battle_copy.opponent.active.get_possible_items(possible_items)
        abilities = battle_copy.opponent.active.get_possible_abilities(
            possible_abilities)
        expected_moves, chance_moves = battle_copy.opponent.active.get_possible_moves(
            possible_moves, battle_copy.battle_type)

        if join_moves_together:
            chance_move_combinations = [chance_moves]
        else:
            number_of_unknown_moves = max(
                4 - len(battle_copy.opponent.active.moves) -
                len(expected_moves), 0)
            chance_move_combinations = list(
                itertools.combinations(chance_moves, number_of_unknown_moves))

        combinations = list(
            itertools.product(spreads, items, abilities,
                              chance_move_combinations))

        logger.debug("Guessing these moves for the opponent's {}: {}".format(
            battle_copy.opponent.active.name, expected_moves))

        # create battle clones for each of the combinations
        battles = list()
        for c in combinations:
            new_battle = deepcopy(battle_copy)

            all_moves = [m.name for m in new_battle.opponent.active.moves]
            all_moves += expected_moves
            all_moves += c[3]

            if join_moves_together or set_makes_sense(c[0][0], c[0][1], c[1],
                                                      c[2], all_moves):
                new_battle.opponent.active.set_spread(c[0][0], c[0][1])
                new_battle.opponent.active.item = c[1]
                new_battle.opponent.active.ability = c[2]
                for m in expected_moves:
                    new_battle.opponent.active.add_move(m)
                for m in c[3]:
                    new_battle.opponent.active.add_move(m)

                logger.debug("Possible set for opponent's {}: {}".format(
                    battle_copy.opponent.active.name, c))
                battles.append(new_battle)

        return battles if battles else [battle_copy]