コード例 #1
0
ファイル: state.py プロジェクト: resonancellc/pkmn-ai
    def mutate(self, *actions):
        team1 = deepcopy(self.team1)
        team2 = deepcopy(self.team2)

        if actions[0] >= Action.SWITCH_OFFSET and actions[
                1] >= Action.SWITCH_OFFSET:
            # double switch
            team1.curpkmn = actions[0] - Action.SWITCH_OFFSET
            team2.curpkmn = actions[1] - Action.SWITCH_OFFSET

        elif actions[0] >= Action.SWITCH_OFFSET and actions[
                1] < Action.SWITCH_OFFSET:
            # team1 switches, then team2 attack
            # TODO: account for Pursuit
            team1.curpkmn = actions[0] - Action.SWITCH_OFFSET
            team2.pkmn[team2.curpkmn] = attack(team2.get_cur_pkmn(),
                                               team1.get_cur_pkmn(),
                                               actions[1])
            if team2.get_cur_pkmn().curhp == 0:
                # TODO: Implement proper switching
                team1.curpkmn = team1.get_next_pkmn()

        elif actions[0] < Action.SWITCH_OFFSET and actions[
                1] >= Action.SWITCH_OFFSET:
            # team2 switches, then team1 attacks
            # TODO: account for Pursuit
            team2.curpkmn = actions[1] - Action.SWITCH_OFFSET
            team1.pkmn[team1.curpkmn] = attack(team1.get_cur_pkmn(),
                                               team2.get_cur_pkmn(),
                                               actions[0])
            if team1.get_cur_pkmn().curhp == 0:
                # TODO: Implement proper switching
                team1.curpkmn = team1.get_next_pkmn()

        else:  # both teams attack
            t1p = team1.get_cur_pkmn()
            t2p = team2.get_cur_pkmn()

            if t1p.moves[actions[0]].priority < t2p.moves[actions[1]].priority:
                team1, team2 = self.team2_attacks_first(team1, team2, actions)
            elif t1p.moves[actions[0]].priority > t2p.moves[
                    actions[1]].priority:
                team1, team2 = self.team1_attacks_first(team1, team2, actions)
            else:
                if t1p.spd > t2p.spd:
                    team1, team2 = self.team1_attacks_first(
                        team1, team2, actions)
                elif t1p.spd < t2p.spd:
                    team1, team2 = self.team2_attacks_first(
                        team1, team2, actions)
                else:
                    # speed tie; assume team2 always wins
                    # TODO: change this to a coin flip with 50% chances
                    team1, team2 = self.team2_attacks_first(
                        team1, team2, actions)

        return PkmnState(team1, team2)
コード例 #2
0
ファイル: ai.py プロジェクト: jpcjr/pkmn-ai
    def team2_attacks_first(self, team1, team2, actions):
        t1p = team1.get_cur_pkmn()
        t2p = team2.get_cur_pkmn()

        team1.pkmn[team1.curpkmn] = attack(t2p, t1p, actions[1], True)
        if t1p.curhp == 0:
            # TODO: Implement proper switching
            team1.curpkmn = team1.get_next_pkmn()
        else:
            team2.pkmn[team2.curpkmn] = attack(t1p, t2p, actions[0])
            team2.curpkmn = team2.get_next_pkmn() if t2p.curhp == 0 else team2.curpkmn
        return (team1, team2)
コード例 #3
0
ファイル: state.py プロジェクト: resonancellc/pkmn-ai
    def team2_attacks_first(self, team1, team2, actions):
        t1p = team1.get_cur_pkmn()
        t2p = team2.get_cur_pkmn()

        team1.pkmn[team1.curpkmn] = attack(t2p, t1p, actions[1], True)
        if t1p.curhp == 0:
            # TODO: Implement proper switching
            team1.curpkmn = team1.get_next_pkmn()
        else:
            team2.pkmn[team2.curpkmn] = attack(t1p, t2p, actions[0])
            team2.curpkmn = team2.get_next_pkmn(
            ) if t2p.curhp == 0 else team2.curpkmn
        return (team1, team2)
コード例 #4
0
ファイル: ai.py プロジェクト: jpcjr/pkmn-ai
    def mutate(self, *actions):
        team1 = deepcopy(self.team1)
        team2 = deepcopy(self.team2)

        if actions[0] >= Action.SWITCH_OFFSET and actions[1] >= Action.SWITCH_OFFSET:
            # double switch
            team1.curpkmn = actions[0] - Action.SWITCH_OFFSET
            team2.curpkmn = actions[1] - Action.SWITCH_OFFSET

        elif actions[0] >= Action.SWITCH_OFFSET and actions[1] < Action.SWITCH_OFFSET:
            # team1 switches, then team2 attack
            # TODO: account for Pursuit
            team1.curpkmn = actions[0] - Action.SWITCH_OFFSET
            team1.pkmn[team1.curpkmn] = attack(team2.get_cur_pkmn(), team1.get_cur_pkmn(), actions[1])
            if team1.get_cur_pkmn().curhp == 0:
                # TODO: Implement proper switching
                team1.curpkmn = team1.get_next_pkmn()

        elif actions[0] < Action.SWITCH_OFFSET and actions[1] >= Action.SWITCH_OFFSET:
            # team2 switches, then team1 attacks
            # TODO: account for Pursuit
            team2.curpkmn = actions[1] - Action.SWITCH_OFFSET
            team2.pkmn[team2.curpkmn] = attack(team1.get_cur_pkmn(), team2.get_cur_pkmn(), actions[0])
            if team2.get_cur_pkmn().curhp == 0:
                # TODO: Implement proper switching
                team2.curpkmn = team2.get_next_pkmn()

        else: # both teams attack
            t1p = team1.get_cur_pkmn()
            t2p = team2.get_cur_pkmn()

            if t1p.moves[actions[0]].priority < t2p.moves[actions[1]].priority:
                team1, team2 = self.team2_attacks_first(team1, team2, actions)
            elif t1p.moves[actions[0]].priority > t2p.moves[actions[1]].priority:
                team1, team2 = self.team1_attacks_first(team1, team2, actions)
            else:
                if t1p.spd > t2p.spd:
                    team1, team2 = self.team1_attacks_first(team1, team2, actions)
                elif t1p.spd < t2p.spd:
                    team1, team2 = self.team2_attacks_first(team1, team2, actions)
                else:
                    # speed tie; assume team2 always wins
                    # TODO: change this to a coin flip with 50% chances
                    team1, team2 = self.team2_attacks_first(team1, team2, actions)
                
        return PkmnState(team1, team2)
コード例 #5
0
from pokemon import Pokemon, showStats, attack
# Primero se pasa la vida y después el poder.
print('Este es un juego de lucha de Pokemones')
pikachu = Pokemon(100, 50, 'Pikachu')
charizard = Pokemon(100, 20, 'Charizard')

contador = 0
# ciclo que va a hacerlos pelear
while pikachu.health > 0 and charizard.health > 0:
    # Esto muestra las estadísticas de los pokemones
    showStats(pikachu, charizard)

    if contador == 0:
        # turno de pikachu
        attack(charizard, pikachu)
        contador = 1
    else:
        # turno de charizard
        attack(pikachu, charizard)
        contador = 0

    # Imrpimiendo quién ganó
    if pikachu.health <= 0:
        print('Ha ganado Charizard')
    elif charizard.health <= 0:
        print('Ha ganado Pikachu')

print('Gracias por utilizar el programa')