/* * Copyright (C) 2022 Camden Dixie O'Brien * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public * License along with this program. If not, see * . */ #ifndef SUD_H #define SUD_H #include #define SIDELEN 9 #define SEGLEN 3 #define NDIGITS 9 struct cellstate { bool det; union { unsigned val; bool pvals[NDIGITS]; }; }; struct sudoku { struct cellstate cells[SIDELEN][SIDELEN]; }; enum update_res { NOT_ALLOWED, ALREADY_DET, OK }; /** * Populate the sudoku with some random values. */ void gen(struct sudoku *sud); /** * Attempt to update the cell at row `r`, column `c` to have the value * `val`. Returns `OK` on success, `ALREADY_DET` if the cell is * already determined or `NOT_ALLOWED` if the cell being `val` would * violate the sudoku rules. */ enum update_res update(struct sudoku *sud, unsigned r, unsigned c, unsigned val); /** * Print a string representation of the sudoku to stdout. */ void print(const struct sudoku *sud); #endif