P5.2: swipe commits legal swap / reverts illegal (sx, iOS sim)
Wire touch input into the model in BoardView.handle_event. A press records the drag start (new DragInput, heap-allocated so it survives the per-frame BoardView rebuild between mouse_down and mouse_up); the release resolves the gesture against the same layout it was drawn with. A swipe — start→end mapped by swipe_intent to an adjacent-swap intent — is fed straight into commit_swap: a legal swap applies, cascades (clear→collapse→refill), accrues score and spends a move; an illegal one reverts, no move. A sub-threshold / off-board drag carries no intent and falls back to the tap behaviour (toggle/clear selection). The next frame re-renders board + HUD from the model. Reuses swipe.sx + board_layout.sx + commit_swap unchanged — this is wiring, not new legality/cascade logic. tests/swipe_commit.sx (new golden) drives the full path on the seeded board (SEED 1337): a rightward swipe (0,0)->(1,0) is illegal (two reds) and reverts byte-for-byte with no score/move; (5,4)->(6,4) is legal, completes R,R,R on row 4, awards 30, spends one move. Sim evidence (iPhone 17, iOS 26.0): goldens/p5_swap_before.png (SCORE 0, MOVES 30/30) and goldens/p5_swap_after.png (SCORE 30, MOVES 29/30) bracket a real idb-injected swipe at (276,475)->(327,475) pt = cell (5,4)->(6,4); the three reds clear and the board matches the model's resolved state.
This commit is contained in:
24
tests/expected/swipe_commit.stdout
Normal file
24
tests/expected/swipe_commit.stdout
Normal file
@@ -0,0 +1,24 @@
|
||||
== illegal swipe reverts ==
|
||||
RRPPOGRG
|
||||
PGPOPRRO
|
||||
YYBBYRYB
|
||||
GBYYRGGP
|
||||
OGBRRORY
|
||||
BYRRPRBG
|
||||
YOYYROBB
|
||||
OROBPPRB
|
||||
intent (0,0)->(1,0)
|
||||
legal false awarded 0 score 0 moves_made 0 moves_remaining 30
|
||||
== legal swipe commits ==
|
||||
intent (5,4)->(6,4)
|
||||
legal true depth 1 awarded 30 score 30 moves_made 1 moves_remaining 29
|
||||
after:
|
||||
RRPBORRG
|
||||
PGPPOGRO
|
||||
YYBOPRYB
|
||||
GBYBYRGP
|
||||
OGBYRGOY
|
||||
BYRRPRBG
|
||||
YOYYROBB
|
||||
OROBPPRB
|
||||
ok: swipe reverts illegal, commits legal
|
||||
Reference in New Issue
Block a user