Battle objects

class poke_env.environment.abstract_battle.AbstractBattle(battle_tag: str, username: str, logger: aiologger.logger.Logger)

Bases: abc.ABC

MESSAGES_TO_IGNORE = {'-anim', '-block', '-burst', '-center', '-combine', '-crit', '-fail', '-fieldactivate', '-hint', '-hitcount', '-immune', '-message', '-miss', '-notarget', '-nothing', '-ohko', '-resisted', '-singlemove', '-singleturn', '-supereffective', '-waiting', '-zbroken', 'askreg', 'c', 'cant', 'crit', 'debug', 'deinit', 'gametype', 'gen', 'html', 'immune', 'inactive', 'j', 'l', 'n', 'rated', 'resisted', 'supereffective', 'tier', 'upkeep', 'zbroken'}
active_pokemon
all_active_pokemons
available_moves
available_switches
battle_tag
Returns:The battle identifier.
Return type:str
can_mega_evolve
can_z_move
dynamax_turns_left
Returns:How many turns of dynamax are left. None if dynamax is not active
Return type:int, optional
end_turn(turn: int) → None
fields
Returns:A dict mapping fields to the turn they have been activated.
Return type:Dict[Field, int]
finished
Returns:A boolean indicating whether the battle is finished.
Return type:Optional[bool]
force_switch
get_pokemon(identifier: str, force_self_team: bool = False, details: str = '', request: Optional[dict] = None) → poke_env.environment.pokemon.Pokemon

Returns the Pokemon object corresponding to given identifier. Can force to return object from the player’s team if force_self_team is True. If the Pokemon object does not exist, it will be created. Details can be given, which is necessary to initialize alternate forms (eg. alolan pokemons) properly.

Parameters:
  • identifier (str) – The identifier to use to retrieve the pokemon.
  • force_self_team (bool, optional, defaults to False) – Wheter to force returning a Pokemon from the player’s team. Defaults to False.
  • details (str, optional) – Detailled information about the pokemon. Defaults to ‘’.
Returns:

The corresponding pokemon object.

Return type:

Pokemon

Raises:

AssertionError – If the team has too many pokemons, as determined by the teamsize component of battle initialisation.

logger
lost
Returns:If the battle is finished, a boolean indicating whether the battle is lost. Otherwise None.
Return type:Optional[bool]
max_team_size
Returns:The maximum acceptable size of the team to return in teampreview, if applicable.
Return type:int, optional
maybe_trapped
move_on_next_request
Returns:Wheter the next received request should yield a move order directly. This can happen when a switch is forced, or an error is encountered.
Return type:bool
opponent_active_pokemon
opponent_can_dynamax
opponent_dynamax_turns_left
Returns:How many turns of dynamax are left for the opponent’s pokemon. None if dynamax is not active
Return type:Optional[int]
opponent_rating

Opponent’s rating after the end of the battle, if it was received.

Returns:The opponent’s rating after the end of the battle.
Return type:int, optional
opponent_role
Returns:Opponent’s role in given battle. p1/p2
Return type:str, optional
opponent_side_conditions
Returns:The opponent’s side conditions. Keys are SideCondition objects, values are the number of layers of the side condition.
Return type:Dict[SideCondition, int]
opponent_team

During teampreview, keys are not definitive: please rely on values.

Returns:The opponent’s team. Keys are identifiers, values are pokemon objects.
Return type:Dict[str, Pokemon]
opponent_username
Returns:The opponent’s username, or None if unknown.
Return type:str, optional.
player_role
Returns:Player’s role in given battle. p1/p2
Return type:str, optional
player_username
Returns:The player’s username.
Return type:str
players
Returns:The pair of players’ usernames.
Return type:Tuple[str, str]
rating

Player’s rating after the end of the battle, if it was received.

Returns:The player’s rating after the end of the battle.
Return type:int, optional
rqid

Should not be used.

Returns:The last request’s rqid.
Return type:Tuple[str, str]
side_conditions
Returns:The player’s side conditions. Keys are SideCondition objects, values are the number of layers of the side condition.
Return type:Dict[SideCondition, int]
team
Returns:The player’s team. Keys are identifiers, values are pokemon objects.
Return type:Dict[str, Pokemon]
team_size
Returns:The number of Pokemon in the player’s team.
Return type:int
teampreview
Returns:Wheter the battle is awaiting a teampreview order.
Return type:bool
trapped
turn
Returns:The current battle turn.
Return type:int
weather
Returns:The battle’s weather or None if no weather is active.
Return type:Optional[Weather]
won
Returns:If the battle is finished, a boolean indicating whether the battle is won. Otherwise None.
Return type:Optional[bool]
class poke_env.environment.battle.Battle(battle_tag: str, username: str, logger: aiologger.logger.Logger)

Bases: poke_env.environment.abstract_battle.AbstractBattle

active_pokemon
Returns:The active pokemon
Return type:Optional[Pokemon]
all_active_pokemons
Returns:A list containing all active pokemons and/or Nones.
Return type:List[Optional[Pokemon]]
available_moves
Returns:The list of moves the player can use during the current move request.
Return type:List[Move]
available_switches
Returns:The list of switches the player can do during the current move request.
Return type:List[Pokemon]
can_dynamax
Returns:Wheter of not the current active pokemon can dynamax
Return type:bool
can_mega_evolve
Returns:Wheter of not the current active pokemon can mega evolve.
Return type:bool
can_z_move
Returns:Wheter of not the current active pokemon can z-move.
Return type:bool
force_switch
Returns:A boolean indicating whether the active pokemon is forced to switch out.
Return type:Optional[bool]
maybe_trapped
Returns:A boolean indicating whether the active pokemon is maybe trapped by the opponent.
Return type:bool
opponent_active_pokemon
Returns:The opponent active pokemon
Return type:Pokemon
opponent_can_dynamax
Returns:Wheter of not opponent’s current active pokemon can dynamax
Return type:bool
trapped
Returns:A boolean indicating whether the active pokemon is trapped, either by the opponent or as a side effect of one your moves.
Return type:bool
class poke_env.environment.double_battle.DoubleBattle(battle_tag: str, username: str, logger: aiologger.logger.Logger)

Bases: poke_env.environment.abstract_battle.AbstractBattle

EMPTY_TARGET_POSITION = 0
OPPONENT_1_POSITION = 1
OPPONENT_2_POSITION = 2
POKEMON_1_POSITION = -1
POKEMON_2_POSITION = -2
active_pokemon
Returns:The active pokemon, always at least one is not None
Return type:List[Optional[Pokemon]]
all_active_pokemons
Returns:A list containing all active pokemons and/or Nones.
Return type:List[Optional[Pokemon]]
available_moves
Returns:A list of two lists of moves the player can use during the current move request for each Pokemon.
Return type:List[List[Move]]
available_switches
Returns:The list of two lists of switches the player can do during the current move request for each active pokemon
Return type:List[List[Pokemon]]
can_dynamax
Returns:Wheter of not the current active pokemon can dynamax
Return type:List[bool]
can_mega_evolve
Returns:Whether of not either current active pokemon can mega evolve.
Return type:List[bool]
can_z_move
Returns:Wheter of not the current active pokemon can z-move.
Return type:List[bool]
force_switch
Returns:A boolean indicating whether the active pokemon is forced to switch out.
Return type:List[bool]
get_possible_showdown_targets(move: poke_env.environment.move.Move, pokemon: poke_env.environment.pokemon.Pokemon, dynamax=False) → List[int]

Given move of an ALLY Pokemon, returns a list of possible Pokemon Showdown targets for it. This is smart enough so that it figures whether the Pokemon is already dynamaxed. :param move: Move instance for which possible targets should be returned :type move: Move :param dynamax: whether given move also STARTS dynamax for its user :return: a list of integers indicating Pokemon Showdown targets:

-1, -2, 1, 2 or self.EMPTY_TARGET_POSITION that indicates “no target”
Return type:List[int]
maybe_trapped
Returns:A boolean indicating whether either active pokemon is maybe trapped by the opponent.
Return type:List[bool]
opponent_active_pokemon
Returns:The opponent active pokemon, always at least one is not None
Return type:List[Optional[Pokemon]]
opponent_can_dynamax
Returns:Wheter of not opponent’s current active pokemon can dynamax
Return type:List[bool]
trapped
Returns:A boolean indicating whether either active pokemon is trapped by the opponent.
Return type:List[bool]