diff --git a/src/sudoku.c b/src/sudoku.c new file mode 100644 index 0000000..af93562 --- /dev/null +++ b/src/sudoku.c @@ -0,0 +1,37 @@ +// Copyright (c) 2025 Quinn +// Licensed under the MIT Licence. See LICENSE for details +#include "sudoku.h" + +#include +#include +#include + +#include "util/intdef.h" + +void sudoku_solve_step(u16 *board) { + u16 bmask[SUDOKU_DEPTH_2]; // board mask + memcpy(bmask, board, SUDOKU_DEPTH_2 * 2); + // TODO: first, we must somehow loop through the columns + // TODO: then, we must write to the bmask or do *magic* for the bits designating to 1-9 to be unset if ONLY one of them is set +} + +void sudoku_print(const u16 *board) { + for (uint i = 0; i < SUDOKU_DEPTH_2; i++) { + char tile; + switch (board[i]) { + case SUDOKU_1: tile = '1'; break; + case SUDOKU_2: tile = '2'; break; + case SUDOKU_3: tile = '3'; break; + case SUDOKU_4: tile = '4'; break; + case SUDOKU_5: tile = '5'; break; + case SUDOKU_6: tile = '6'; break; + case SUDOKU_7: tile = '7'; break; + case SUDOKU_8: tile = '8'; break; + case SUDOKU_9: tile = '9'; break; + default: tile = ' '; break; + }; + + printf("|%c ", tile); + if (i % 9 == 8) printf("|\n"); + } +} diff --git a/src/sudoku.h b/src/sudoku.h new file mode 100644 index 0000000..61ed3d8 --- /dev/null +++ b/src/sudoku.h @@ -0,0 +1,27 @@ +// Copyright (c) 2025 Quinn +// Licensed under the MIT Licence. See LICENSE for details +#pragma once + +#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 + +/* bitmask */ +enum sudoku_bitmask { + SUDOKU_1 = 0x001, + SUDOKU_2 = 0x002, + SUDOKU_3 = 0x004, + SUDOKU_4 = 0x008, + SUDOKU_5 = 0x010, + SUDOKU_6 = 0x020, + SUDOKU_7 = 0x040, + SUDOKU_8 = 0x080, + SUDOKU_9 = 0x100, +}; + +/* TODO: write documentation */ +void sudoku_solve_step(u16 *board); + +/* TODO: write documentation */ +void sudoku_print(const u16 *board);