Add swap + legality to the board model: - swap(board, a, b): in-place, self-inverse cell exchange (trial then revert). - adjacent(a, b): orthogonal-adjacency predicate (diagonal/gap = false). - swap_legal(board, a, b): legal iff adjacent AND, after the trial swap, either swapped cell participates in a 3+ match (reuses find_matches); leaves the board unchanged. Non-adjacent/diagonal rejected before any match check. - Cell/Swap structs + legal_swaps(board): all currently-legal swaps in a stable row-major, right-before-down order; dump_swaps for deterministic snapshotting. tests/swap_legality.sx asserts the predicate over hand-crafted boards (legal 3-run, no-match, non-adjacent, diagonal, only-the-other-gem-matches) and the non-mutating revert; locks legal_swaps over the seeded board as a golden.
57 lines
666 B
Plaintext
57 lines
666 B
Plaintext
== swap & legality ==
|
|
== swap revert (non-mutating) ==
|
|
before:
|
|
OGOGOGOG
|
|
GOGOGOGO
|
|
OGOGOGOG
|
|
RRBRGOGO
|
|
OGOGOGOG
|
|
GOGOGOGO
|
|
OGOGOGOG
|
|
GOGOGOGO
|
|
after:
|
|
OGOGOGOG
|
|
GOGOGOGO
|
|
OGOGOGOG
|
|
RRBRGOGO
|
|
OGOGOGOG
|
|
GOGOGOGO
|
|
OGOGOGOG
|
|
GOGOGOGO
|
|
== legal_swaps: seeded 1337 ==
|
|
RRPPOGRG
|
|
PGPOPRRO
|
|
YYBBYRYB
|
|
GBYYRGGP
|
|
OGBRRORY
|
|
BYRRPRBG
|
|
YOYYROBB
|
|
OROBPPRB
|
|
--
|
|
24 legal swaps
|
|
(3,0)-(3,1)
|
|
(4,0)-(4,1)
|
|
(5,0)-(6,0)
|
|
(1,2)-(1,3)
|
|
(2,2)-(2,3)
|
|
(4,2)-(5,2)
|
|
(4,2)-(4,3)
|
|
(5,2)-(6,2)
|
|
(1,3)-(2,3)
|
|
(3,3)-(4,3)
|
|
(4,3)-(5,3)
|
|
(2,4)-(2,5)
|
|
(4,4)-(4,5)
|
|
(5,4)-(6,4)
|
|
(5,4)-(5,5)
|
|
(1,5)-(1,6)
|
|
(3,5)-(4,5)
|
|
(4,5)-(5,5)
|
|
(4,5)-(4,6)
|
|
(6,5)-(7,5)
|
|
(0,6)-(1,6)
|
|
(1,6)-(1,7)
|
|
(3,6)-(4,6)
|
|
(6,7)-(7,7)
|
|
ok: swap legality over hand-crafted boards
|