Skip to content

Battle simulator: rules checked against PTCG Live's engine and the official rulings - #357

Merged
cheyras merged 4 commits into
mainfrom
sim/rules-complete
Oct 18, 2026
Merged

cheyras merged 4 commits into
mainfrom
sim/rules-complete

Conversation

@cheyras

@cheyras cheyras commented Oct 18, 2026

Copy link
Copy Markdown
Owner

The battle simulator's rules engine, checked against PTCG Live's own match engine and the official rulings, and made to follow them.

PTCG Live's engine (MatchLogic.dll, read with REA for type, enum and method names only) was used as a checklist of the mechanics the real game models. The rulebook, card text and the Rulings Compendium still decide behaviour. No PTCG Live code, data or text is in this PR, and ruling text stays on the Compendium. Full record: decisions/2026/2026-10-17-battle-simulator-the-core-rules-checked-against-ptcg-live-s-engine-and-the-gener.md.

Engine

  • Timed effects wait for their turn. "During your (opponent's) next turn" covers that turn only, counted for the player whose card made it. "Until the end of your next turn" is a new duration (Overwriting Bolt).
  • Attack-damage steps are for attacks only: Weakness/Resistance, damage boosts and reductions, prevention, and the Tera Bench rule.
  • Prize cards are taken one at a time (#809): a face-up Prize card is a choice.
  • Retreat may be paid with up to the cost in cards (#2127). A free retreat asks nothing.
  • Checkup: the player whose turn is next flips first (#867).
  • Stadium: once per turn belongs to the card (#926).
  • Hidden information: a card from the discard pile, Lost Zone or play into the hand stays known (#787).
  • Sudden Death for tied games (rulebook; PTCG Live's MatchMode.SuddenDeath), instead of a recorded draw.
  • Deck searches for a kind of card may find none (#903). "Up to" otherwise stays at least 1 (#2301).
  • #668: a Special Energy that provides its type only while attached is no type off a Pokémon.
  • #1823: a Trainer can't switch out a protected Active.
  • Gusts: an attack or Ability that switches in a Benched Pokémon no longer checks the Active's protection (ruling 2155). This was found by replaying a real game: Heave-Ho Catcher vs Hide 'n' Sneak.

Tests and tools

  • 99 general Compendium rulings newly pinned (532 of 1,944 now have a DeckPal summary).
  • New rule tests: rules-timing, rules-attack-damage, rules-checklist, rulings-general-*.
  • PTCG Live log replay now completes all 36 real games tried (26 of the owner's logs, which are not committed, plus the 10 fixtures), up from 18, with every winner matching. Fixes are in src/replay/*, each pinned by a synthetic log in replay-log-fixes.test.ts.
  • simulate_battles: a pasted list that breaks the 4-copy, ACE SPEC or Basic Pokémon rules gets a note, and is still simulated.
  • rules_lookup: a new "Effects that last a turn" entry, and Sudden Death replaces "draw" in the winning rules.

Verification

  • @deckpal/sim: 3,231 tests pass.
  • deckpal-api test:deck: 261 pass. @deckpal/agent-tools: 398 pass.
  • tsc --noEmit is clean in every workspace.
  • determinism.test.ts re-pinned: 14 of the 40 seeded games now play differently, from the retreat, Stadium, #787 and Checkup changes.

Still open

  • The CPU always chooses to go first.
  • Games that hit the 60-turn cap count as draws.
  • A few replay choices that the log doesn't record are guessed (for example Ninja Spinner's optional bonus). None changes a result.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MKj6CMZ1kKCNaVjKSHgJpx

cheyras and others added 4 commits October 17, 2026 20:05
…he general Compendium rulings

Timed effects wait for their turn; attack-damage steps apply to attacks only;
Prize cards taken one at a time with a face-up choice (#809); retreat paid with
up to the cost in cards (#2127); next player flips first in Checkup (#867);
Stadium once-per-turn belongs to the card (#926); cards from public zones into
the hand stay known (#787). 98 general rulings newly pinned (531 of 1,944).

On-Behalf-Of: @cheyras
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MKj6CMZ1kKCNaVjKSHgJpx
… nothing, legality notes for pasted lists

A tie starts a sudden-death game (1 Prize card each, new coin flip) instead of
a recorded draw, as the rulebook and PTCG Live's MatchMode.SuddenDeath do. A
search of your own deck for a kind of card may find none (Compendium #903); a
search for any card or a discard-pile pick keeps its minimum (#2301). Lists
passed straight to simulate_battles get a note when they break the 4-copy,
ACE SPEC or Basic Pokémon rules, and are still simulated.

On-Behalf-Of: @cheyras
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MKj6CMZ1kKCNaVjKSHgJpx
… protected Active, and the log replay fixed

#668: a Special Energy that provides its type only while attached is no type
off a Pokemon. #1823: a Trainer switching out a protected Active does nothing.
An attack or Ability that switches in a Benched Pokemon no longer checks the
Active's protection (ruling 2155; Heave-Ho Catcher vs Hide 'n' Sneak, found by
replaying a real game). The PTCG Live log replay now completes all 36 real
games (was 18): hidden-hand cards proven by detail lines, spread-attack
targets, multi-coin flips, Judge draws, moved counters, codeless printings and
more, each pinned by a synthetic log test.

On-Behalf-Of: @cheyras
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MKj6CMZ1kKCNaVjKSHgJpx
@vercel

vercel Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
deckpal Ready Ready Preview Oct 18, 2026 11:12pm UTC

Request Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved automatically: authored by the repository owner, from a branch in this repo. GitHub forbids self-approval, so this stands in for it (AGENTS.md B12). Required status checks still apply — this does not merge anything.

@cheyras
cheyras merged commit 5a7f0a5 into main Oct 18, 2026
16 checks passed
@cheyras
cheyras deleted the sim/rules-complete branch October 18, 2026 23:23
cheyras added a commit that referenced this pull request Oct 20, 2026
…d Tournament Rules (#359)

This follows up #357. Everything that pass left on purpose was checked
against the **Advanced Player's Rulebook v3.4 (2025)** and the **Play!
Pokémon Tournament Rules Handbook**. The five items that break the rules
now follow them. Decision:
`decisions/2026/2026-10-19-battle-simulator-turn-timing-and-the-end-of-a-game-follow-the-advanced-player-s.md`.

- **Tiebreaker game with 6 Prize cards**, won by the first player to
have fewer Prize cards left (APR "Games can result in a tie"; Tournament
Rules 5.8.3.1). This corrects #357's 1-Prize sudden death, which
followed older wording.
- **"During this turn / your next turn / your opponent's next turn"
effects end before Pokémon Checkup**, because Checkup is in neither
player's turn (APR E-02). "Until the end of your next turn" still
applies in it (E-22, E-23).
- **Knock Outs from end-of-turn effects are resolved before Checkup.** A
Knock Out is checked whenever HP becomes zero (APR D), so Checkup
healing can no longer save a Pokémon already at 0.
- **Setup is face down.** Both players' Active and Bench choices stay
hidden in hand and go into play together when the game starts (APR G,
steps 5–8).
- **The turn cap is time being called.** The turn is finished, 3 more
are played, then the player with fewer Prize cards left wins (reason
`time`). Level, play goes on until one player is ahead (Tournament Rules
5.8.3). Only a long stalemate stays a `turn limit` draw.

Not changed, because they break no rule: the CPU choosing to go first,
and Energy/damage-counter moves written per card.

## Verification
- `@deckpal/sim`: 3,242 tests pass. New rule tests in `rules-timing` and
`rules-checklist`; each new behavioural test fails with its fix
disabled.
- All 36 real PTCG Live games (26 of the owner's logs, which are not
committed, plus the 10 fixtures) still replay to the end with matching
winners.
- Fuzz: 4,000 random games, 0 failures. The 90 former turn-limit draws
now end by `time` (40) or a tiebreaker game (6).
- `deckpal-api test:deck` 261, `@deckpal/agent-tools` 398, and `tsc
--noEmit` across workspaces are clean.
- `determinism.test.ts` re-pinned: 18 of 40 seeded games change, mostly
because setup events are now ordered by the face-down reveal.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01MKj6CMZ1kKCNaVjKSHgJpx

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 53cc4049 Deployed Oct 18, 2026 by vercel[bot]
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

Successfully merging this pull request may close these issues.

1 participant