Battle engine¶
Single 1v1 battle simulation at Level 100, capped at 60 turns.
Uses the Gen 6 damage formula by default. Pass gen1_mode=True to switch to
the Gen 1 stat and damage formula. See run_battle for full parameter details.
battle ¶
Battle engine -- runs a single 1v1 Pokemon battle.
Implements: - Generation-accurate damage formula and type chart via BattleRules - Deterministic AI: always picks the highest expected-damage move - Status moves used when they confer a concrete battle advantage - All status conditions (burn, paralysis, poison, sleep, freeze) - Stat stage tracking - Type effectiveness, STAB, accuracy-weighted damage - No random miss rolls, no critical hits, no damage noise - 60-turn timeout resolved by HP percentage
BattleResult
dataclass
¶
BattleResult(
winner: str,
loser: str,
turns: int,
timeout: bool,
winner_hp_remaining: int,
winner_hp_max: int,
winner_hp_pct: float,
attacker_had_advantage: bool = False,
)
Outcome of a single 1v1 battle.
run_battle ¶
run_battle(
pokemon_a: Pokemon,
pokemon_b: Pokemon,
level: int = 100,
rand_ivs: bool = False,
rng: Random | None = None,
rules: BattleRules | None = None,
) -> BattleResult
Run a single battle between two Pokemon. Returns a BattleResult with winner, turns, and HP data. Pokemon instances are not mutated -- deep copies are used internally.
The battle is fully deterministic when rand_ivs=False (the default). With rand_ivs=True an rng is used only for IV generation at the start; all in-battle decisions remain deterministic.
rules defaults to Gen6Rules() when not provided.
Source code in pokerena/engine/battle.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |