// 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;
}
