4.9 KiB
4.9 KiB
TBG (J) — frame timing of the battle state machine
Measured from four 20 000-frame recordings (re/lua/ai2_rec.lua, 2 KiB WRAM/frame, random P1 vs COM,
difficulty 0–3: re/runs/ai2/rec_d{0..3}/), level 0. Tools: re/tools/ai2_states.py (state runs),
re/tools/ai2_stats.py (histograms), re/tools/ai2_window.py (both players over a frame range).
[C] = observed (counts in brackets), [I] = from code. Player state = DP $0B ($020D / $046D).
Each frame the battle loop (81:A548) runs P1 then P2 — P1 wins ties for the contested queue. [C]
Piece cycle
| state | meaning | frames |
|---|---|---|
| 05 | falling (input processed here only) | — |
| 06 → 16 | rotate (06 applies it, 16 settles) then back to 05 | 1 + 1 [C 1150/1181] |
| 07 / 08 | slide left / right (outside the entry period) | 2 [C 267/293] |
| 09 | lock (cells written) | 1 [C 568] |
| 0E | generic 1-frame transition | 1 [C 1743] |
| 0A | full-row scan | 1 |
| 0B ↔ 0E | line-clear flash, 7 times | 14 |
| 0C | collapse | lines + 1 (2/3/4/5) [C] |
| 00 | cycle start: garbage delivery happens here | 1 if nothing incoming |
| 0F → 10 → 0E → 00 | one garbage row: rise animation 7, insert (81:D48E) 1, 1, 1 | 10 per row, repeated per row [C 45 single, 6 double] |
| 01 / 02 / 03 / 04 | queue animation (piece travels from the preview into the field) | 17 / 17 / 16 / 1–2 [C ~550 each] |
- Lock → next piece falling, no clear: 09 0E 0A 0E (4) + 00 (1) + 01–04 (51–52) = 56–57 frames. [C]
00 → 05alone is 52 (×237) or 53 (×241); +1 outliers in 01/02/03 (17→18) are rare (~5 %). - Line clear: from the first 0B to the next 00 = 18 + lines frames (1: 19 ×55, 2: 20 ×5, 3: 21, 4: 22). [C] Full sequence: 09 0E 0A (0B 0E)×7 0C×(n+1) 0E 0A 0E 00.
- Garbage: +10 frames per incoming row at the victim's state 00, before its queue animation. [C]
- The M1/M2 placeholder
spawn_delay = 10should be 52 (00→05) on top of the 4-frame lock tail, plus 18+n for clears and 10 per garbage row.
Falling-piece details
- Gravity:
$40·(g+1)8.8 px/frame (level 0: 1 px / 4 frames, 32 frames per row). Row = (y>>3)+1; when y is not a multiple of 8, DP $0A holds the second row and collision tests both rows, so a piece never overlaps; on landing, 81:B5D3 snaps y down to a multiple of 8 (y -= y mod 8). [C data + code] - Lock delay (81:B5B7, grounded in state 05): two counters, both reloaded only when the piece falls a pixel
(81:B312):
- Down held (
$0134): DP $1C counts from DP $7A = 4 → lock on the 4th grounded frame [C 138]. - Down not held: DP $1B counts from DP $79 = 16 at level 0 (32 at L1, 48 at L2, 58 at L3–4, 48 at L5, 32 at L6–7). [C 16–18 frame locks in human play]
- Each counter only ticks on frames where its condition holds (the other pauses). Rotating or sliding does not reset them (frames in 06/07/08/16 just don't tick). [C]
- Down held (
- Slide (07/08): the logical column (DP $08) changes on the first frame; pixel X catches up over 3 frames (+3, +4, +1 px at 3.5 px/frame), 2 frames in 07/08, then back to 05. Gravity is suspended while sliding (y unchanged in 07/08). The 07/08 handlers (81:B323 / 81:B352) don't process rotation — no rotate mid-slide [I].
- Entry period DP $1D (7 for humans from DP $7C, 12 for the COM): horizontal moves are instant (8 px, stay in 05, one column per frame); it counts down on idle 05 frames and pressing Down zeroes it. [C]
- Soft drop (81:9F46): on a new Down press
$0159+player= DP $7F (2 at levels 0–4, 3 at 5–7); while it counts, normal gravity; then 8 px = 1 row per frame. Difficulty-1 COM sometimes starts at 80–111 (see AI notes). [C]
Powers, rounds
- Cast: Up while falling → caster state 13 for 122–125 frames (cut-in; rare 131/154) [C 11/13]; meter
reset to 0 on the first frame; the opponent is frozen in whatever state it was in (its piece doesn't
move). Then both players sit in 00 while the effect runs (
DP $27= power ID from the frame after 13 ends until the effect finishes; e.g. Pentris 247 frames); both then continue; the caster restarts its cycle with 01. [C] What happens to the caster's in-flight piece is not determined [I]. - Round end: the loser's last lock stays in 0A for 181 frames (win counter
DP $22of the winner rises ~10–18 frames in); the winner is frozen. Then the winner shows FE for 2 frames, both boards are cleared and both players run 03 for 213 frames (READY/GO + first queue animation), 04 (1–2), 05. Losing lock → next piece falling ≈ 397 frames. Match end: FF (results screen). [C 9 rounds]
Open questions
- Whether the +1 frame outliers in 01/02/03 come from the shared queue (both players animating) or lag.
- State 00 sometimes lasts 2–15 frames with no garbage (waiting on the opponent's clear/cut-in?) — not isolated.
- Lock-delay variant DP $7B/$7D during the entry period (81:A02E).