The Battle object
- class poke_env.environment.abstract_battle.AbstractBattle(battle_tag: str, username: str, logger: Logger, save_replays: str | bool, gen: int)
Bases:
ABC
- MESSAGES_TO_IGNORE = {'-anim', '-block', '-burst', '-center', '-combine', '-crit', '-fail', '-fieldactivate', '-hint', '-hitcount', '-miss', '-notarget', '-nothing', '-ohko', '-resisted', '-singlemove', '-singleturn', '-supereffective', '-waiting', '-zbroken', 'J', 'L', 'askreg', 'c', 'chat', 'crit', 'debug', 'deinit', 'gametype', 'gen', 'html', 'immune', 'init', 'j', 'join', 'l', 'leave', 'n', 'name', 'rated', 'resisted', 'split', 'supereffective', 'teampreview', 'tier', 'uhtml', 'upkeep', 'zbroken'}
- abstract property active_pokemon: Any
- abstract property available_moves: Any
- abstract property available_switches: Any
- property battle_tag: str
- Returns:
The battle identifier.
- Return type:
str
- abstract property can_dynamax: Any
- abstract property can_mega_evolve: Any
- abstract property can_tera: Any
- abstract property can_z_move: Any
- abstract clear_all_boosts()
- property dynamax_turns_left: int | None
- Returns:
How many turns of dynamax are left. None if dynamax is not active
- Return type:
int, optional
- abstract end_illusion(pokemon_name: str, details: str)
- end_turn(turn: int)
- field_start(field_str: str)
- property fields: Dict[Field, int]
- Returns:
A Dict mapping fields to the turn they have been activated.
- Return type:
Dict[Field, int]
- property finished: bool
- Returns:
A boolean indicating whether the battle is finished.
- Return type:
Optional[bool]
- abstract property force_switch: Any
- get_pokemon(identifier: str, force_self_team: bool = False, details: str = '', request: Dict[str, Any] | None = None) 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:
- Raises:
ValueError – If the team has too many pokemons, as determined by the teamsize component of battle initialisation.
- in_team_preview: bool
- logger: Logger | None
- property lost: bool | None
- Returns:
If the battle is finished, a boolean indicating whether the battle is lost. Otherwise None.
- Return type:
Optional[bool]
- property max_team_size: int | None
- Returns:
The maximum acceptable size of the team to return in teampreview, if applicable.
- Return type:
int, optional
- abstract property maybe_trapped: Any
- property move_on_next_request: bool
- 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
- abstract property opponent_active_pokemon: Any
- abstract property opponent_can_dynamax: Any
- property opponent_dynamax_turns_left: int | None
- Returns:
How many turns of dynamax are left for the opponent’s pokemon. None if dynamax is not active
- Return type:
int | None
- property opponent_rating: int | None
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
- property opponent_role: str | None
- Returns:
Opponent’s role in given battle. p1/p2
- Return type:
str, optional
- property opponent_side_conditions: Dict[SideCondition, int]
- Returns:
The opponent’s side conditions. Keys are SideCondition objects, values are:
- the number of layers of the SideCondition if the side condition is
stackable
the turn where the SideCondition was setup otherwise
- Return type:
Dict[SideCondition, int]
- property opponent_team: Dict[str, Pokemon]
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]
- property opponent_username: str | None
- Returns:
The opponent’s username, or None if unknown.
- Return type:
str, optional.
- parse_message(split_message: List[str])
- abstract parse_request(request: Dict[str, Any])
- property player_role: str | None
- Returns:
Player’s role in given battle. p1/p2
- Return type:
str, optional
- property player_username: str
- Returns:
The player’s username.
- Return type:
str
- property players: Tuple[str, str]
- Returns:
The pair of players’ usernames.
- Return type:
Tuple[str, str]
- property rating: int | None
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
- property reviving: bool
- property rqid: int
Should not be used.
- Returns:
The last request’s rqid.
- Return type:
Tuple[str, str]
- rules: List[str]
- property side_conditions: Dict[SideCondition, int]
- Returns:
The player’s side conditions. Keys are SideCondition objects, values are:
- the number of layers of the side condition if the side condition is
stackable
the turn where the SideCondition was setup otherwise
- Return type:
Dict[SideCondition, int]
- side_end(side: str, condition_str: str)
- abstract switch(pokemon_str: str, details: str, hp_status: str)
- property team: Dict[str, Pokemon]
- Returns:
The player’s team. Keys are identifiers, values are pokemon objects.
- Return type:
Dict[str, Pokemon]
- property team_size: int
- Returns:
The number of Pokemon in the player’s team.
- Return type:
int
- property teampreview: bool
- Returns:
Wheter the battle is awaiting a teampreview order.
- Return type:
bool
- tied()
- abstract property trapped: Any
- property turn: int
- Returns:
The current battle turn.
- Return type:
int
- property weather: Dict[Weather, int]
- Returns:
A Dict mapping the battle’s weather (if any) to its starting turn
- Return type:
Dict[Weather, int]
- property won: bool | None
- Returns:
If the battle is finished, a boolean indicating whether the battle is won. Otherwise None.
- Return type:
Optional[bool]
- won_by(player_name: str)
- class poke_env.environment.battle.Battle(battle_tag: str, username: str, logger: Logger, gen: int, save_replays: str | bool = False)
Bases:
AbstractBattle
- property all_active_pokemons: List[Pokemon | None]
- Returns:
A list containing all active pokemons and/or Nones.
- Return type:
List[Optional[Pokemon]]
- property available_moves: List[Move]
- Returns:
The list of moves the player can use during the current move request.
- Return type:
List[Move]
- property available_switches: List[Pokemon]
- Returns:
The list of switches the player can do during the current move request.
- Return type:
List[Pokemon]
- property can_dynamax: bool
- Returns:
Whether or not the current active pokemon can dynamax
- Return type:
bool
- property can_mega_evolve: bool
- Returns:
Whether or not the current active pokemon can mega evolve.
- Return type:
bool
- property can_tera: PokemonType | None
- Returns:
None, or the type the active pokemon can terastallize into.
- Return type:
PokemonType, optional
- property can_z_move: bool
- Returns:
Whether or not the current active pokemon can z-move.
- Return type:
bool
- clear_all_boosts()
- end_illusion(pokemon_name: str, details: str)
- property force_switch: bool
- Returns:
A boolean indicating whether the active pokemon is forced to switch out.
- Return type:
Optional[bool]
- in_team_preview: bool
- logger: Logger | None
- property maybe_trapped: bool
- Returns:
A boolean indicating whether the active pokemon is maybe trapped by the opponent.
- Return type:
bool
- property opponent_can_dynamax: bool
- Returns:
Whether or not opponent’s current active pokemon can dynamax
- Return type:
bool
- property opponent_can_mega_evolve: bool
- Returns:
Whether or not opponent’s current active pokemon can mega-evolve
- Return type:
bool
- property opponent_can_tera: bool
- Returns:
Whether or not opponent’s current active pokemon can terastallize
- Return type:
bool
- property opponent_can_z_move: bool
- Returns:
Whether or not opponent’s current active pokemon can z-move
- Return type:
bool
- parse_request(request: Dict[str, Any]) None
Update the object from a request. The player’s pokemon are all updated, as well as available moves, switches and other related information (z move, mega evolution, forced switch…).
- Parameters:
request (dict) – Parsed JSON request object.
- rules: List[str]
- switch(pokemon_str: str, details: str, hp_status: str)
- property trapped: bool
- 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: Logger, gen: int, save_replays: str | bool = False)
Bases:
AbstractBattle
- EMPTY_TARGET_POSITION = 0
- OPPONENT_1_POSITION = 1
- OPPONENT_2_POSITION = 2
- POKEMON_1_POSITION = -1
- POKEMON_2_POSITION = -2
- property active_pokemon: List[Pokemon | None]
- Returns:
The active pokemon, always at least one is not None
- Return type:
List[Optional[Pokemon]]
- property all_active_pokemons: List[Pokemon | None]
- Returns:
A list containing all active pokemons and/or Nones.
- Return type:
List[Optional[Pokemon]]
- property available_moves: List[List[Move]]
- 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]]
- property available_switches: List[List[Pokemon]]
- 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]]
- property can_dynamax: List[bool]
- Returns:
Whether or not the current active pokemon can dynamax
- Return type:
List[bool]
- property can_mega_evolve: List[bool]
- Returns:
Whether or not either current active pokemon can mega evolve.
- Return type:
List[bool]
- property can_tera: List[bool | PokemonType]
- Returns:
Whether or not the current active pokemon can terastallize. If yes, will be a PokemonType.
- Return type:
List[Union[bool, PokemonType]]
- property can_z_move: List[bool]
- Returns:
Whether or not the current active pokemon can z-move.
- Return type:
List[bool]
- clear_all_boosts()
- end_illusion(pokemon_name: str, details: str)
- property force_switch: List[bool]
- Returns:
A boolean indicating whether the active pokemon is forced to switch out.
- Return type:
List[bool]
- get_possible_showdown_targets(move: Move, pokemon: Pokemon, dynamax: bool = 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.
- Parameters:
move (Move) – Move instance for which possible targets should be returned
dynamax – whether given move also STARTS dynamax for its user
- Returns:
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]
- in_team_preview: bool
- logger: Logger | None
- property maybe_trapped: List[bool]
- Returns:
A boolean indicating whether either active pokemon is maybe trapped by the opponent.
- Return type:
List[bool]
- property opponent_active_pokemon: List[Pokemon | None]
- Returns:
The opponent active pokemon, always at least one is not None
- Return type:
List[Optional[Pokemon]]
- property opponent_can_dynamax: List[bool]
- Returns:
Whether or not opponent’s current active pokemons can dynamax
- Return type:
List[bool]
- property opponent_can_mega_evolve: List[bool]
- Returns:
Whether or not opponent’s current active pokemons can mega evolve
- Return type:
List[bool]
- property opponent_can_z_move: List[bool]
- Returns:
Whether or not opponent’s current active pokemons can z-move
- Return type:
List[bool]
- parse_request(request: Dict[str, Any]) None
Update the object from a request. The player’s pokemon are all updated, as well as available moves, switches and other related information (z move, mega evolution, forced switch…).
- Parameters:
request (dict) – Parsed JSON request object.
- property reviving: bool
- Returns:
Whether or not any of the player’s Pokemon is reviving.
- Return type:
bool
- rules: List[str]
- switch(pokemon_str: str, details: str, hp_status: str)
- to_showdown_target(move: Move, target_mon: Pokemon) int
Returns the correct Showdown target of the Pokemon to be targeted. It will return 0 if no target is needed or if the target_mon is not an active pokemon; this is meaningless in showdown
- Parameters:
move (Move) – the move to be used against the target_mon
target_mon (as implemented in poke-env) – the Pokemon that is to be targeted
- Returns:
The corresponding showdown target if needed, otherwise 0
- Return type:
int
- property trapped: List[bool]
- Returns:
A boolean indicating whether either active pokemon is trapped by the opponent.
- Return type:
List[bool]