Esempio n. 1
0
 def handleFinalKeyInput(self, move):
     print("Move: " + move)
     self.combos.append(move)
     print("Combos: ")
     print(self.combos)
     print(self.moveset_tree.getNumber())
     if self.moveset_tree.getNumber() == 6:
         print("Attack ready to be executed!")
         print(self.combos)
         hand = self.combos[1]
         magnitude = self.combos[2]
         region = self.combos[3]
         if region == "Target: head" or region == "Target: torso":
             specRegion = None
             isSpecAttack = False
             move = self.combos[4]
         else:
             specRegion = self.combos[4]
             isSpecAttack = False
             move = self.combos[5]
         statEffectBonus = False
         attack = Attack(self.player, self.enemy, hand, magnitude, region, specRegion, isSpecAttack, move)
         #self.logAttack(attack)
         #self.attackVisuals()
         self.newMethod(attack)
         damage = attack.calculateDamage()
         #self.logDamage(damage, attack.player.name, attack.enemy.name)
         self.logAttack(attack, damage)
         self.game.callUpdateStatusBar(-1 * damage, 2)
         self.moveset_tree.resetCurrentTree()
         self.eraseCurrentTree()
         self.displayCurrentMoves()
         self.displayCurrentKeyCombos()
         self.combos = []
     elif self.moveset_tree.getNumber() == 4:
         print("Blocked!")
         if self.pendingAttack != None:
             isValidBlock = False
             if self.pendingAttack.region == "Target: head" or self.pendingAttack.region == "Target: torso":
                 if self.combos[3] == "High block":
                     isValidBlock = True
             elif self.pendingAttack.region == "Target: arms" or self.pendingAttack.region == "Target: legs":
                 if self.combos[3] == "Low block":
                     isValidBlock = True
             if isValidBlock == True:
                 self.blockAttack()
             self.moveset_tree.resetCurrentTree()
    def expand_state(self, stateToExpand):
        if stateToExpand in self.pokemonGraph:
            return ()
        whoseTurn = stateToExpand[-1]
        whoseNextTurn = int(1 - whoseTurn)
        activePokemons = (stateToExpand[0][-1], stateToExpand[1][-1])

        # If the current move pokemon is alive, total out edge = 4(moves of current pokemon) + numPokemonAlive(switches to the rest alive pokemon)
        if stateToExpand[whoseTurn][activePokemons[whoseTurn]] > 0:
            nextStates = [0] * (4 +
                                CONSTANTS.Constants.NUM_POKEMON_PER_PLAYER - 1)

            for i in range(4 + CONSTANTS.Constants.NUM_POKEMON_PER_PLAYER - 1):
                damageList = [
                    Attack.calculateDamage(
                        self.pokemons[whoseTurn][
                            activePokemons[whoseTurn]].getMove1().getName(),
                        self.pokemons[whoseTurn][activePokemons[whoseTurn]],
                        self.pokemons[whoseNextTurn][
                            activePokemons[whoseNextTurn]]),
                    Attack.calculateDamage(
                        self.pokemons[whoseTurn][
                            activePokemons[whoseTurn]].getMove2().getName(),
                        self.pokemons[whoseTurn][activePokemons[whoseTurn]],
                        self.pokemons[whoseNextTurn][
                            activePokemons[whoseNextTurn]]),
                    Attack.calculateDamage(
                        self.pokemons[whoseTurn][
                            activePokemons[whoseTurn]].getMove3().getName(),
                        self.pokemons[whoseTurn][activePokemons[whoseTurn]],
                        self.pokemons[whoseNextTurn][
                            activePokemons[whoseNextTurn]]),
                    Attack.calculateDamage(
                        self.pokemons[whoseTurn][
                            activePokemons[whoseTurn]].getMove4().getName(),
                        self.pokemons[whoseTurn][activePokemons[whoseTurn]],
                        self.pokemons[whoseNextTurn][
                            activePokemons[whoseNextTurn]])
                ]

                # Create next states for the cases when current team chooses a move
                for j in range(4):
                    modifiedOtherTeamState = list(
                        deepcopy(stateToExpand[whoseNextTurn]))
                    modifiedOtherTeamState[activePokemons[whoseNextTurn]] = max(
                        0,
                        modifiedOtherTeamState[activePokemons[whoseNextTurn]] -
                        damageList[j]
                    )  # Set the new HP of the pokemon being attacked
                    nextStates[j] = [0] * 3
                    nextStates[j][whoseNextTurn] = tuple(
                        modifiedOtherTeamState)
                    nextStates[j][whoseTurn] = stateToExpand[whoseTurn]
                    nextStates[j][2] = whoseNextTurn
                    nextStates[j] = tuple(nextStates[j])

                # Create next states for the cases when current team switches to another ALIVE pokemon
                pokemonToSwitch = list(
                    range(CONSTANTS.Constants.NUM_POKEMON_PER_PLAYER))
                for pokemonNum in range(
                        CONSTANTS.Constants.NUM_POKEMON_PER_PLAYER):
                    if pokemonNum == activePokemons[whoseTurn] or (
                            stateToExpand[whoseTurn][pokemonNum] == 0):
                        pokemonToSwitch.remove(pokemonNum)
                extraCount = 0
                for j in range(len(pokemonToSwitch)):
                    pokemonToSwitchChosen = pokemonToSwitch[j]
                    modifiedCurrentTeamState = list(
                        deepcopy(stateToExpand[whoseTurn]))
                    modifiedCurrentTeamState[-1] = pokemonToSwitchChosen
                    nextStates[4 + j] = [0] * 3
                    nextStates[4 +
                               j][whoseNextTurn] = stateToExpand[whoseNextTurn]
                    nextStates[4 +
                               j][whoseTurn] = tuple(modifiedCurrentTeamState)
                    nextStates[4 + j][2] = whoseNextTurn
                    nextStates[4 + j] = tuple(nextStates[4 + j])
                    extraCount += 1

            nextStates = nextStates[:4 + extraCount]

            # if player 2 (AI)'s turn has finished, every player's active pokemon loses 5% max HP
            if whoseTurn == 1:
                processedNextStates = self.end_term_process(nextStates)
                nextStates = processedNextStates
            nextStates = tuple(nextStates)
            self.pokemonGraph[stateToExpand] = nextStates
            return nextStates

        # If the current move pokemon is dead, total out edge = numPokemonAlive(switches to the rest alive pokemon)
        else:
            nextStates = [0] * (CONSTANTS.Constants.NUM_POKEMON_PER_PLAYER - 1)

            # Create next states for the cases when current team switches to another ALIVE pokemon
            pokemonToSwitch = list(
                range(CONSTANTS.Constants.NUM_POKEMON_PER_PLAYER))
            for pokemonNum in range(
                    CONSTANTS.Constants.NUM_POKEMON_PER_PLAYER):
                if pokemonNum == activePokemons[whoseTurn] or (
                        stateToExpand[whoseTurn][pokemonNum] == 0):
                    pokemonToSwitch.remove(pokemonNum)

            # If all dead, return nothing
            if len(pokemonToSwitch) == 0:
                print("player {}'s pokemons all dead!".format(whoseTurn))
                return (["dead"])

            extraCount = 0
            for j in range(len(pokemonToSwitch)):
                pokemonToSwitchChosen = pokemonToSwitch[j]
                modifiedCurrentTeamState = list(
                    deepcopy(stateToExpand[whoseTurn]))
                modifiedCurrentTeamState[-1] = pokemonToSwitchChosen
                nextStates[j] = [0] * 3
                nextStates[j][whoseNextTurn] = stateToExpand[whoseNextTurn]
                nextStates[j][whoseTurn] = tuple(modifiedCurrentTeamState)
                nextStates[j][2] = whoseNextTurn
                nextStates[j] = tuple(nextStates[j])
                extraCount += 1

            nextStates = nextStates[:extraCount]

            # if player 2 (AI)'s turn has finished, every player's active pokemon loses 5% max HP
            if whoseTurn == 1:
                processedNextStates = self.end_term_process(nextStates)
                nextStates = processedNextStates
            nextStates = tuple(nextStates)
            self.pokemonGraph[stateToExpand] = nextStates
            return nextStates