From a5b6c520532ea05bd7714efd847bf9e8e7f0d429 Mon Sep 17 00:00:00 2001 From: Quinn Date: Tue, 29 Jul 2025 11:46:18 +0200 Subject: [PATCH] write code to initialise the sudoku board --- src/sudoku.c | 6 ++++++ src/sudoku.h | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/sudoku.c b/src/sudoku.c index af93562..4b0ebb1 100644 --- a/src/sudoku.c +++ b/src/sudoku.c @@ -8,6 +8,12 @@ #include "util/intdef.h" +void sudoku_init(u16 *board) { + for (uint i = 0; i < SUDOKU_DEPTH_2; i++) { + board[i] |= SUDOKU_ALL & -!board[i]; + } +} + void sudoku_solve_step(u16 *board) { u16 bmask[SUDOKU_DEPTH_2]; // board mask memcpy(bmask, board, SUDOKU_DEPTH_2 * 2); diff --git a/src/sudoku.h b/src/sudoku.h index 61ed3d8..f42a165 100644 --- a/src/sudoku.h +++ b/src/sudoku.h @@ -4,8 +4,9 @@ #include "util/intdef.h" -#define SUDOKU_DEPTH 9 // defines the "depth" of the puzzle. -#define SUDOKU_DEPTH_2 (SUDOKU_DEPTH * SUDOKU_DEPTH) // computes how many squares there are +#define SUDOKU_DEPTH_SQRT 3 +#define SUDOKU_DEPTH (SUDOKU_DEPTH_SQRT * SUDOKU_DEPTH_SQRT) +#define SUDOKU_DEPTH_2 (SUDOKU_DEPTH * SUDOKU_DEPTH) /* bitmask */ enum sudoku_bitmask { @@ -18,8 +19,12 @@ enum sudoku_bitmask { SUDOKU_7 = 0x040, SUDOKU_8 = 0x080, SUDOKU_9 = 0x100, + SUDOKU_ALL = 0x01FF, }; +/* initialises the sudoku board to `SUDOKU_ALL`. (if the tile is empty) */ +void sudoku_init(u16 *board); + /* TODO: write documentation */ void sudoku_solve_step(u16 *board);