Beispiel #1
0
 def switch_pokemon(self, switch_index, who, log=False, hazards=True):
     my_team = self.get_team(who)
     opp_team = self.get_team(1 - who)
     if my_team.primary().name == "Meloetta":
         my_team.primary().meloetta_reset()
     my_team.set_primary(switch_index)
     my_poke = my_team.primary()
     my_poke.reset_taunt()
     my_poke.reset_disabled()
     my_poke.reset_last_move()
     my_poke.reset_encore()
     opp_poke = opp_team.primary()
     if log:
         pass
         # print (
         #     "%s switched in." % my_poke
         # )
     if my_poke.ability == "Intimidate":
         if log:
             pass
             # print ("%s got intimidated." % opp_poke)
         opp_poke.decrease_stage('patk', 1)
     if self.rocks[who] and hazards:
         type = 1.0
         type_multipliers = [
             get_multiplier(x, "Rock") for x in my_poke.typing
         ]
         for x in type_multipliers:
             type *= x
         damage = 1.0 / 8 * type
         d = my_poke.damage_percent(damage)
         if log:
             pass
             # print "%s was damaged %f due to rocks!" % (my_poke, d)
         if self.spikes[
                 who] > 0 and "Flying" not in my_poke.typing and my_poke.ability != "Levitate":
             if self.spikes[who] == 1:
                 d = my_poke.damage_percent(1.0 / 8)
             elif self.spikes[who] == 2:
                 d = my_poke.damage_percent(1.0 / 6)
             elif self.spikes[who] == 3:
                 d = my_poke.damage_percent(1.0 / 4)
             if log:
                 pass
Beispiel #2
0
    def switch_pokemon(self, switch_index, who, log=False, hazards=True):
        my_team = self.get_team(who)
        opp_team = self.get_team(1 - who)
        if my_team.primary().name == "Meloetta":
            my_team.primary().meloetta_reset()
        my_team.set_primary(switch_index)
        my_poke = my_team.primary()
        my_poke.reset_taunt()
        my_poke.reset_disabled()
	my_poke.reset_last_move()
	my_poke.reset_encore()
        opp_poke = opp_team.primary()
        if log:
            pass
            # print (
            #     "%s switched in." % my_poke
            # )
        if my_poke.ability == "Intimidate":
            if log:
                pass
                # print ("%s got intimidated." % opp_poke)
            opp_poke.decrease_stage('patk', 1)
        if self.rocks[who] and hazards:
            type = 1.0
            type_multipliers = [get_multiplier(x, "Rock") for x in my_poke.typing]
            for x in type_multipliers:
                type *= x
            damage = 1.0 / 8 * type
            d = my_poke.damage_percent(damage)
            if log:
                pass
                # print "%s was damaged %f due to rocks!" % (my_poke, d)
            if self.spikes[who] > 0 and "Flying" not in my_poke.typing and my_poke.ability != "Levitate":
                if self.spikes[who] == 1:
                    d = my_poke.damage_percent(1.0 / 8)
                elif self.spikes[who] == 2:
                    d = my_poke.damage_percent(1.0 / 6)
                elif self.spikes[who] == 3:
                    d = my_poke.damage_percent(1.0 / 4)
                if log:
                    pass
Beispiel #3
0
class GameState():
    def __init__(self, teams):
        self.teams = teams
        self.rocks = [False, False]
        self.spikes = [0, 0]

    def dump(self, path):
        with open(path, 'wb') as fp:
            pickle.dump(self, fp)

    @staticmethod
    def load(path):
        with open(path, 'rb') as fp:
            gs = pickle.load(fp)
        return gs

    def deep_copy(self):
        state = GameState([x.copy() for x in self.teams])
        state.rocks = self.rocks[:]
        state.spikes = self.spikes[:]
        return state

    def set_rocks(self, who, rock_bool):
        self.rocks[who] = rock_bool

    def add_spikes(self, who):
        self.spikes[who] += 1

    def get_team(self, team):
        return self.teams[team]

    def to_tuple(self):
        return (tuple(x.to_tuple() for x in self.teams), (self.rocks[0], self.rocks[1], self.spikes[0], self.spikes[1]))

    @staticmethod
    def from_tuple(tupl):
        return GameState([team.from_tuple() for team in tupl[0]])

    def evaluate(self, who):
        win_bonus = 0
        my_team = self.get_team(who)
        opp_team = self.get_team(1 - who)
        if self.is_over():
            if my_team.alive():
                win_bonus = 10000
            else:
                win_bonus = -10000
        my_team_health = sum([x.health/x.final_stats['hp'] for x in my_team.poke_list])
        opp_team_health = sum([x.health/x.final_stats['hp'] for x in opp_team.poke_list])
        my_team_death = len([x for x in my_team.poke_list if not x.alive])
        opp_team_death = len([x for x in opp_team.poke_list if not x.alive])
        my_burn, opp_burn = 0, 0
        my_rocks, opp_rocks = 0, 0
        spikes = 0
        if self.is_over():
            my_team_stages, opp_team_stages = 0, 0
        else:
            my_poke = my_team.primary()
            opp_poke = opp_team.primary()
            my_team_stages = my_poke.stages['spatk'] + my_poke.stages['patk']
            opp_team_stages = opp_poke.stages['spatk'] + opp_poke.stages['patk']
            opp_rocks = 0.75 if self.rocks[1 - who] else 0
            my_rocks = -1.0 if self.rocks[who] else 0
            if self.spikes[1 - who] == 1:
                spikes = 0.3
            elif self.spikes[1 - who] == 2:
                spikes = 0.6
            elif self.spikes[1 - who] == 3:
                spikes = 1
            opp_burn = 0.75 if (opp_poke.status == "burn" and opp_poke.final_stats['patk'] > 245 and opp_poke.ability != "Guts") else 0
            my_burn = -1.5 if (my_poke.status == "burn" and my_poke.final_stats['patk'] > 250 and my_poke.ability != "Guts") else 0
        return win_bonus + my_team_health - opp_team_health - 0.5 * my_team_death + 0.5 * opp_team_death + opp_rocks + my_rocks + opp_burn + my_burn + spikes# + 0.07 * (my_team_stages - opp_team_stages)

    def is_over(self):
        return not (self.teams[0].alive() and self.teams[1].alive())

    def switch_pokemon(self, switch_index, who, log=False, hazards=True):
        my_team = self.get_team(who)
        opp_team = self.get_team(1 - who)
        if my_team.primary().name == "Meloetta":
            my_team.primary().meloetta_reset()
        my_team.set_primary(switch_index)
        my_poke = my_team.primary()
        my_poke.reset_taunt()
        my_poke.reset_disabled()
	    my_poke.reset_last_move()
	    my_poke.reset_encore()
        opp_poke = opp_team.primary()
        if log:
            print (
                "%s switched in." % my_poke
            )
        if my_poke.ability == "Intimidate":
            if log:
                print ("%s got intimidated." % opp_poke)
            opp_poke.decrease_stage('patk', 1)
        if self.rocks[who] and hazards:
            type = 1.0
            type_multipliers = [get_multiplier(x, "Rock") for x in my_poke.typing]
            for x in type_multipliers:
                type *= x
            damage = 1.0 / 8 * type
            d = my_poke.damage_percent(damage)
            if log:
                print "%s was damaged %f due to rocks!" % (my_poke, d)
            if self.spikes[who] > 0 and "Flying" not in my_poke.typing and my_poke.ability != "Levitate":
                if self.spikes[who] == 1:
                    d = my_poke.damage_percent(1.0 / 8)
                elif self.spikes[who] == 2:
                    d = my_poke.damage_percent(1.0 / 6)
                elif self.spikes[who] == 3:
                    d = my_poke.damage_percent(1.0 / 4)
                if log:
                    print "%s was damaged %f due to spikes!" % (my_poke, d)
Beispiel #4
0
    def handle(self, gamestate, who, log=False):
        attacker = gamestate.get_team(who).primary()
        defender = gamestate.get_team(1 - who).primary()
        if self.category == "Physical":
            atks = "patk"
            defs = "pdef"
        else:
            atks = "spatk"
            defs = "spdef"
        if self.name == "Secret Sword" or self.name == "Psyshock":
            defs = "pdef"
        attack = attacker.get_stat(atks)
        defense = defender.get_stat(defs)
        abs_atk_buffs = 1.0 + 0.5 * abs(attacker.get_stage(atks))
        abs_def_buffs = 1.0 + 0.5 * abs(defender.get_stage(defs))
        atk_stage_multiplier = abs_atk_buffs if attacker.get_stage(
            atks) > 0 else 1 / abs_atk_buffs
        def_stage_multiplier = abs_def_buffs if defender.get_stage(
            defs) > 0 else 1 / abs_def_buffs
        type = 1
        move_type = self.type
        name = self.name
        power = self.power(gamestate, who)
        other = 1.0 * atk_stage_multiplier / def_stage_multiplier
        old_ability = defender.ability
        if (attacker.ability == "Mold Breaker" or attacker.ability
                == "Turboblaze" or attacker.ability == "Teravolt"
            ) and defender.ability in self.pokedata.moldbreaker:
            defender.ability = None
        if attacker.ability == "Pixilate":
            if move_type == "Normal":
                move_type = "Fairy"
                other *= 1.3
        if attacker.ability == "Aerilate":
            if move_type == "Normal":
                move_type = "Flying"
                other *= 1.3
        if attacker.ability == "Protean":
            attacker.typing = [move_type]
        if (defender.ability == "Levitate"
                or defender.item == "Air Balloon") and move_type == "Ground":
            other *= 0
        if attacker.ability == "Technician" and power <= 60:
            other *= 1.5
        if defender.ability == "Thick Fat" and (move_type == "Fire"
                                                or move_type == "Ice"):
            other *= 0.5

        if self.name == "Knock Off" and defender.item is not None:
            other *= 1.5

        if attacker.item in set(
            ["Choice Scarf", "Choice Band", "Choice Specs"]):
            attacker.choiced = True
            attacker.move_choice = name
        if attacker.item == "Choice Band" and self.category == "Physical":
            other *= 1.5
        if attacker.item == "Choice Specs" and self.category == "Special":
            other *= 1.5
        if defender.item == "Assault Vest" and self.category == "Special":
            defense *= 1.5
        if defender.item == "Eviolite":
            defense *= 1.5
        if attacker.status == "burn" and self.category == "Physical":
            if attacker.ability == "Guts":
                other *= 1.5
            else:
                other /= 2.0
        stab = 1.5 if move_type in attacker.typing else 1
        if attacker.ability == "Adaptability" and stab == 1.5:
            stab = 2
        if move_type == "Water" and (defender.ability == "Water Absorb"
                                     or defender.ability == "Dry Skin"):
            other *= 0
            defender.heal(0.25)
        if move_type == "Fire" and defender.ability == "Dry Skin":
            other *= 1.25
        if move_type == "Water" and defender.ability == "Storm Drain":
            other *= 0
            defender.increase_stage('spatk', 1)
        if move_type == "Electric" and defender.ability == "Volt Absorb":
            other *= 0
            defender.heal(0.25)
        if move_type == "Electric" and defender.ability == "Lightning Rod":
            other *= 0
            defender.increase_stage('spatk', 1)
        if move_type == "Electric" and defender.ability == "Motor Drive":
            other *= 0
            defender.increase_stage('spe', 1)
        if move_type == "Fire" and defender.ability == "Flash Fire":
            other *= 0
        type_multipliers = [
            get_multiplier(x, move_type, attacker.ability == "Scrappy")
            for x in defender.typing
        ]
        for x in type_multipliers:
            type *= x
        critical = 1
        r = 1
        modifier = stab * type * critical * other * r
        if attacker.ability == "Huge Power" or attacker.ability == "Pure Power":
            attack *= 2
        damage = (((42.0) * attack / defense * power) / 50 + 2) * modifier

        defender.damage(damage)

        self.handler(gamestate, damage, who)
        defender.ability = old_ability
        return damage
Beispiel #5
0
    def handle(self, gamestate, who, log=False):
        attacker = gamestate.get_team(who).primary()
        defender = gamestate.get_team(1 - who).primary()
        if self.category == "Physical":
            atks = "patk"
            defs = "pdef"
        else:
            atks = "spatk"
            defs = "spdef"
        if self.name == "Secret Sword" or self.name == "Psyshock":
            defs = "pdef"
        attack = attacker.get_stat(atks)
        defense = defender.get_stat(defs)
        abs_atk_buffs = 1.0 + 0.5 * abs(attacker.get_stage(atks))
        abs_def_buffs = 1.0 + 0.5 * abs(defender.get_stage(defs))
        atk_stage_multiplier = abs_atk_buffs if attacker.get_stage(atks) > 0 else 1 / abs_atk_buffs
        def_stage_multiplier = abs_def_buffs if defender.get_stage(defs) > 0 else 1 / abs_def_buffs
        def_type = 1
        move_type = self.type
        name = self.name
        power = self.power(gamestate, who)
        other = 1.0 * atk_stage_multiplier / def_stage_multiplier
        old_ability = defender.ability
        if (attacker.ability == "Mold Breaker" or attacker.ability == "Turboblaze" or attacker.ability == "Teravolt") and defender.ability in self.pokedata.moldbreaker:
            defender.ability = None
        if attacker.ability == "Pixilate":
            if move_type == "Normal":
                move_type = "Fairy"
                other *= 1.3
        if attacker.ability == "Aerilate":
            if move_type == "Normal":
                move_type = "Flying"
                other *= 1.3
        if attacker.ability == "Protean":
            attacker.typing = [move_type]
        if (defender.ability == "Levitate" or defender.item == "Air Balloon") and move_type == "Ground":
            other *= 0
        if attacker.ability == "Technician" and power <= 60:
            other *= 1.5
        if defender.ability == "Thick Fat" and (move_type == "Fire" or move_type == "Ice"):
            other *= 0.5


        if self.name == "Knock Off" and defender.item is not None:
            other *= 1.5

        if attacker.item in set(["Choice Scarf", "Choice Band", "Choice Specs"]):
            attacker.choiced = True
            attacker.move_choice = name
        if attacker.item == "Choice Band" and self.category == "Physical":
            other *= 1.5
        if attacker.item == "Choice Specs" and self.category == "Special":
            other *= 1.5
        if defender.item == "Assault Vest" and self.category == "Special":
            defense *= 1.5
        if defender.item == "Eviolite":
            defense *= 1.5
        if attacker.status == "burn" and self.category == "Physical":
            if attacker.ability == "Guts":
                other *= 1.5
            else:
                other /= 2.0
        stab = 1.5 if move_type in attacker.typing else 1
        if attacker.ability == "Adaptability" and stab == 1.5:
            stab = 2
        if move_type == "Water" and (defender.ability == "Water Absorb" or defender.ability == "Dry Skin"):
            other *= 0
            defender.heal(0.25)
        if move_type == "Fire" and defender.ability == "Dry Skin":
            other *= 1.25
        if move_type == "Water" and defender.ability == "Storm Drain":
            other *= 0
            defender.increase_stage('spatk', 1)
        if move_type == "Electric" and defender.ability == "Volt Absorb":
            other *= 0
            defender.heal(0.25)
        if move_type == "Electric" and defender.ability == "Lightning Rod":
            other *= 0
            defender.increase_stage('spatk', 1)
        if move_type == "Electric" and defender.ability == "Motor Drive":
            other *= 0
            defender.increase_stage('spe', 1)
        if move_type == "Fire" and defender.ability == "Flash Fire":
            other *= 0
        if move_type == "Electric" and "Ground" in defender.typing:
            other *= 0
        type_multipliers = [get_multiplier(x, move_type, attacker.ability=="Scrappy") for x in defender.typing]
        for x in type_multipliers:
            def_type *= x
        critical = 1
        r = 1
        modifier = stab * def_type * critical * other * r
        if attacker.ability == "Huge Power" or attacker.ability == "Pure Power":
            attack *= 2
        damage = (((42.0) * attack/defense * power)/50 + 2) * modifier

        defender.damage(damage)

        self.handler(gamestate, damage, who)
        defender.ability = old_ability
        return damage