add some basic code for the sudoku processing

This commit is contained in:
2025-07-28 09:33:30 +02:00
parent a55da88ec2
commit 13be9261ac
2 changed files with 64 additions and 0 deletions

37
src/sudoku.c Normal file
View File

@@ -0,0 +1,37 @@
// Copyright (c) 2025 Quinn
// Licensed under the MIT Licence. See LICENSE for details
#include "sudoku.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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");
}
}

27
src/sudoku.h Normal file
View File

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