Overview
TheBattle class is the core of Pokemon Showdown’s battle simulation engine. It manages the battle state, processes actions, and handles all battle mechanics.
Constructor
Battle configuration options
Key Properties
Current turn number
Player 1’s side
Player 2’s side
The battle field state
The action queue
The battle format rules
The data access layer for this format
The pseudorandom number generator
Whether the battle has ended
The winning side ID, or empty string if no winner
Core Methods
setPlayer()
Set up a player and their team.Player identifier
choose()
Make a choice for a player.Player making the choice
The choice string (e.g., “move 1”, “switch 2”)
start()
Start the battle.destroy()
Clean up the battle and free resources.Battle State Methods
makeChoices()
Process choices for all players simultaneously.commitChoices()
Commit and execute the queued choices.clearChoice()
Clear a player’s pending choice.setTurn()
Advance to the next turn.Message Methods
add()
Add a message to the battle log.addSplit()
Add a message with public and private variants.hint()
Add a hint message for debugging.Damage Calculation
getDamage()
Calculate damage from an attack.The attacking Pokemon
The defending Pokemon
The move being used
Whether to suppress damage messages
Damage amount, false if attack fails, undefined for special handling
Utility Methods
randomChance()
Test for a random chance.sample()
Randomly select from an array.random()
Generate a random integer.Example Usage
Related APIs
BattleStream
Stream interface for battles
Pokemon
Pokemon class
Side
Side class
Simulator Usage
Using the simulator
