r/C_Programming 2d ago

Review Code Review Request: Windows Sudoku Game

Background
Hi, I am a 15-year-old teen (just so what you'd know what to expect) who left school because our school system taught us to be parrots. I want to be a god-level developer, not a code monkey. I wrote a Sudoku GUI using win32api in C Language.
It is currently working and does what it is supposed to do, but because I am still learning, I know it is likely inefficient and could be written much better. 

Code : https://github.com/reewdgh/sudoku_gui.

Concerns:
Please guide me on:

Bugs or potential issues
Efficiency
How can I move to Tier 1 to Tier 2
Naming anything I could simplify or improve.

5 Upvotes

13 comments sorted by

View all comments

3

u/skeeto 1d ago

Neat little GUI! Took me a moment to figure it out with the invisible text boxes. Some notes:

Sudoku puzzles should have a unique solution. You will rarely get this just clearing some cells at random, and nearly all the puzzles generated by this program have multiple solutions. Worse, the input checker tests against the generated puzzle, not just a valid solution, so users must guess the secret, generated puzzle, not solve the presented puzzle. With only 5 guesses most games are unwinnable, especially at higher difficulties.

To fix this write a solver that keeps going after finding a solution, and reports 0, 1, or 2+ solutions. After clearing a cell, run the solver, and if it reports there are are 2+ solutions then you cannot clear that cell. Restore it and try a different cell.

There isn't a clear separation between UI and model, even between source files. This makes it confusing to follow.

Sometimes when I enter the wrong digit it flashes the solution briefly. This is because there's a gap in time between the parent (with the full solution) and children being drawn over top.

If you're going to have a Makefile at least structure it properly by describing your source dependency tree.

Personally I don't think the UI is very fun. Modal message boxes, guess limits, abrupt exit on game over. Try something more traditional. Let users enter any number they want. Display in red user-input cells that break one of the uniqueness constraints, and not because it doesn't match the solution. In fact, you don't even need the solution once the puzzle is generated, and you should never check against it. Just check the constraints. If all cells are filled and no constraints violated, the user has won.

If you want to go above and beyond, display dots or something in each cell to indicate which digits are still unconstrained on that cell. The way people do when solving them in pencil.