write code to initialise the sudoku board

This commit is contained in:
2025-07-29 11:46:18 +02:00
parent 13be9261ac
commit a5b6c52053
2 changed files with 13 additions and 2 deletions

View File

@@ -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);

View File

@@ -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);