Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Chart causing a KeyError only containing a type as the error message #484

Open
i4D4 opened this issue Jan 8, 2024 · 1 comment
Open

Comments

@i4D4
Copy link

i4D4 commented Jan 8, 2024

Hey there, I can't seem to get random battles to work with the bot because the type chart isn't working. This is the error message I get:

Message='ELECTRIC'
Source=C:\Users\i4D4\Downloads\poke-env-master\poke-env-master\AItest.py
StackTrace:
File "C:\Users\i4D4\Downloads\poke-env-master\poke-env-master\AItest.py", line 61, in embed_battle (Current frame)
moves_dmg_multiplier[i] = move.type.damage_multiplier(
KeyError: 'ELECTRIC'

The type changes every time I run it because I'm running random battles.

This is the part of the code causing issues:

  def embed_battle(self, battle: AbstractBattle) -> ObsType:
      # -1 indicates that the move does not have a base power
      # or is not available
      moves_base_power = -np.ones(4)
      moves_dmg_multiplier = np.ones(4)
      for i, move in enumerate(battle.available_moves):
          moves_base_power[i] = (
              move.base_power / 100
          )  # Simple rescaling to facilitate learning
          if move.type:
              moves_dmg_multiplier[i] = move.type.damage_multiplier(
                  battle.opponent_active_pokemon.type_1,
                  battle.opponent_active_pokemon.type_2,
              )

      # We count how many pokemons have fainted in each team
      fainted_mon_team = len([mon for mon in battle.team.values() if mon.fainted]) / 6
      fainted_mon_opponent = (
          len([mon for mon in battle.opponent_team.values() if mon.fainted]) / 6
      )
      ...
      ```
@i4D4 i4D4 changed the title Type Chart causing issues Type Chart causing a KeyError only containing a type as the error message Jan 8, 2024
@wogikaze
Copy link

wogikaze commented Jan 8, 2024

move.type.damage_multiplier function need type chart, but move.type.damage_multiplier need not it, so I'm using

if move.type:
    moves_dmg_multiplier[i] = battle.opponent_active_pokemon.damage_multiplier(move)

insted of

if move.type:
    moves_dmg_multiplier[i] = move.type.damage_multiplier(
        battle.opponent_active_pokemon.type_1,
        battle.opponent_active_pokemon.type_2,
    )

good luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants