P1.1: pure-sx Gem & Board model with seeded, match-free init
Add board.sx, the headless Phase-1 match-3 core: - Gem enum (6 types, ordinal 0..5) + single-char dump alphabet. - Rng: a 32-bit LCG carried in s64, masked to 32 bits each step, so the stream is host-width independent and valid for any seed. - Board (8x8, row-major) with idx/at/set accessors and a seeded init that fills row-major, excluding any gem that would complete a 3-in-a-row with the two cells to the left or above — so the result has zero pre-existing matches. Single RNG draw per cell, always terminates. - board_dump: deterministic one-row-per-line textual snapshot. tests/board_init.sx seeds with a fixed seed, dumps the board, and asserts zero horizontal/vertical 3-in-a-row runs via an independent scan. Output and exit code are locked as goldens. App ios-sim build is unaffected (main.sx does not import the model yet).
This commit is contained in:
39
tests/board_init.sx
Normal file
39
tests/board_init.sx
Normal file
@@ -0,0 +1,39 @@
|
||||
// Board-state golden: seed the board deterministically, dump it, and assert
|
||||
// the no-pre-existing-match invariant (zero horizontal/vertical 3-in-a-rows).
|
||||
// The dump is locked as a snapshot so the seeded board state can't drift.
|
||||
#import "modules/std.sx";
|
||||
#import "board.sx";
|
||||
t :: #import "test.sx";
|
||||
|
||||
SEED :: 1337;
|
||||
|
||||
// Count every horizontal or vertical window of three consecutive same-type
|
||||
// gems. A correctly initialized board has zero. This walks the finished board
|
||||
// independently of the placement logic, so it's a real check, not a tautology.
|
||||
count_three_runs :: (b: *Board) -> s32 {
|
||||
runs : s32 = 0;
|
||||
for 0..BOARD_ROWS: (row) {
|
||||
for 0..(BOARD_COLS - 2): (col) {
|
||||
g := b.at(col, row);
|
||||
if g == b.at(col + 1, row) and g == b.at(col + 2, row) { runs += 1; }
|
||||
}
|
||||
}
|
||||
for 0..(BOARD_ROWS - 2): (row) {
|
||||
for 0..BOARD_COLS: (col) {
|
||||
g := b.at(col, row);
|
||||
if g == b.at(col, row + 1) and g == b.at(col, row + 2) { runs += 1; }
|
||||
}
|
||||
}
|
||||
runs
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
board : Board = ---;
|
||||
board.init(SEED);
|
||||
|
||||
out(board_dump(@board));
|
||||
|
||||
t.expect(count_three_runs(@board) == 0, "seeded board has no 3-in-a-row runs");
|
||||
print("ok: board_init no-match invariant holds\n");
|
||||
return 0;
|
||||
}
|
||||
1
tests/expected/board_init.exit
Normal file
1
tests/expected/board_init.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
9
tests/expected/board_init.stdout
Normal file
9
tests/expected/board_init.stdout
Normal file
@@ -0,0 +1,9 @@
|
||||
RRPPOGRG
|
||||
PGPOPRRO
|
||||
YYBBYRYB
|
||||
GBYYRGGP
|
||||
OGBRRORY
|
||||
BYRRPRBG
|
||||
YOYYROBB
|
||||
OROBPPRB
|
||||
ok: board_init no-match invariant holds
|
||||
Reference in New Issue
Block a user