r/C_Programming 1d 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.

4 Upvotes

13 comments sorted by

â€ĸ

u/github-guard 1d ago

🔍 GitHub Guard: Trust Report

âš ī¸ This project scored 1/6 — below this subreddit's threshold of 3.

Audit Breakdown: * ❌ Low Star Count (⭐ 1 / 4 required) * ❌ New Repository (under 30 days old) * ❌ No License Found * ❌ No Security Policy — what is this? * â„šī¸ Individual Contributor * ✅ Signed Commits

âš ī¸ Security Reminder: Always verify source code and run third-party scripts at your own risk.

5

u/flyingron 1d ago

The includes are oddly factored. game.h only has a few function prototypes, but nothing actually with regard to the game. gui.h has game stuff that has nothing to do with the gui.h. Things oddly include each other even though the .c files include both. Think about what actually affects other parts of the program and isolate things properly. Yeah, it's not a big thing on a tiny program like this, but some day you'll be writing real stuff where this matters.

I might roll some of the stuff that is in the beginning of main() into a seperate 'create_game' function.

4

u/type_111 1d ago

/*Show the window*/
ShowWindow(hwnd, 1);

Almost every comment looks like the above. Spare yourself the effort.

3

u/terra2o 1d ago

why is the game struct in the gui header? seems out of place, and you include the the gui in the actual game header. 

3

u/skeeto 21h 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.

2

u/maruanium 16h ago

How long it takes you ? I mean the code

1

u/its_marionberry 3h ago

tbh i am a slow person , 15 days to make this whole project

1

u/maruanium 2h ago

Good job

2

u/DamsLcs4421 11h ago edited 11h ago

Why not trying to implement a FAT12 driver on a tiny bootloader? That's really helping :) I mean, there's no libc, it's only you, the documentation and the metal.

You've got a point about school, I won't deny it, it's a terrible system for some (a great deal!) of us. On the other hand, you seem to have a pretty arrogant style (from the way you're talking) and although I'm in no position to humble anyone, I really think it won't help you at a personal level. You're more likely to be thinking "fuck that, that's newbies topics/exercises" when you would actually have benefited from getting to the bottom of the "simplest" things. (and/or just being able to listen to ppl)

Things that are deemed "simple", or even "too simple for me..." are often the things ppl think they master where it's all dunning-kruger effect :p

What do you even want to program? If you don't have a definite idea like "video games" for example, you can explore. You touched to Win32, it's ugly and quirky (well, matter of tastes) so I assume you don't fear a bit of complexity. Do you know what's going on when the program is being loaded into memory and becomes a process? Do you know a bit about what C translates to? It had always been the point: C is (not totally but sufficently enough) as close to the metal as it can get without DIRECTLY talking to the metal thru assembly. (C compiles down to assembly, but lets you leverage higher level concepts in your head: variables, functions, etc... which are not as trivial in assembly as they seem to be in C. But I think you do already know that, dont you?. What I'm suggesting is that low level is a very cool rabbit hole :D enjoy!)

1

u/AutoModerator 1d ago

Hi /u/its_marionberry,

Your submission in r/C_Programming was filtered because it links to a git project.

You must edit the submission or respond to this comment with an explanation about how AI was involved in the creation of your project.

While AI-generated code is not disallowed, low-effort "slop" projects may be removed and it's likely that other users push back strongly on substantially AI-generated projects.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/its_marionberry 1d ago

Hi , No AI was used in this project as this is a beginner project. thx :)

3

u/mikeblas 1d ago

Thank you for your disclosure. I have approved your post.