Sudoku Generator banner

Sudoku Generator

15 devlogs
28h 35m 29s

use math and algorithms (and C++) to make sudoku, my fav game :D

Repository

Loading README...

Rei

I’ve worked on the backend, now you can play (kinda lol) in the website! I’ve also updated the sudoku generation code so that it saves the solution yayayayayay

I know it looks ugly, I’m gonna polish it once I finish the backend okig

And I think I love Crow ms-crow

Changelog

Attachment
Attachment
0
Rei

Im using crow now! Here’s the plan:

Browser

HTML / JS

Crow (C++ server)

Sudoku generator

Installing crow was really annoying tbh. I got TOO MANY errors cryin
Now I’m kinda excited bcz i havent coded in JavaScript for a while

Changelog

this is the 4x4 logic

Attachment
2

Comments

maverickroneal
maverickroneal about 1 month ago

cool

Rei
Rei about 1 month ago

thanks hu-thanks

Rei

After finishing the 6x6 sudoku generator, I’m working now on making it generate 4x4 puzzles. I don’t think this is really hard but for some reason (still figuring it out) it doesn’t generate 4x4 hard puzzles cryin

It generates easy and medium puzzles well tho.
Let’s be real, 4x4 puzzles can’t be hard, bcz they are sooo small (16 num). So I’m gonna:
A. Try to solve this problem
B. Leave it bcz 4x4 hard sudokus dont exist. (I’m gonna do this probably)

See this ugly error I get when I try to generate 4x4 hard puzzles -

Attachment
0
Rei

I’ve added some improvements joy-dance :

  1. candLog isn’t global anymore (this solves a couple of problems and make everything safer)

  2. Added emptyCells, so instead of scanning the whole grid every time I need to know if the sudoku is complete or not, I just check the emptyCells var.

  3. Added a new function, rebuildStateFromGrid, which does:

    • Rebuilds row/col/box masks
    • Validates duplicates
    • Recomputes candidates
    • Ensures no zero-candidate cells
      Which is useful for hasUniqueSolution
  4. Added safety checks in place and clearAll
    Btw the generator is now fast again yayayaya, see ⬇️

  • 29601 hard puzzle/min
  • 94701 easy puzzle/min
  • 66011 medium puzzle/min.
Attachment
Attachment
Attachment
0
Rei

I Found Out Why Hard Puzzles Are NOT Hard :D

A 6x6 sudoku grid is small, so adding techniques like pointing pairs, naked pairs, etc. is stupid and a waste of time tbh

The gird is so small, so the difficulty mainly depends on guesses, when they start, and backtracks. No need for many techniques, they are useless

So I removed some techniques and now I’m cleaning the code after removing 300+ lines of code pf + trying to make it faster gotta-go-fast
Check this puzzle downdoot

Attachment
0
Rei

I’m going mad bcz whatever I do the HARD puzzles remain medium-easy. I reduced the clues, added more techniques, and added lots of stuff but it doesnt work cryin

I will reread the code, and try to figure it out -

look at this puzzle, its supposed to be hard cryin

Attachment
0
Rei

I remove remove function, replaced it with undo and clearAll bcz remove is very very expensive.

I also finished the applyNakedPairs, applyNakedSingles, applyHiddenSingles functions. But the HARD puzzles still not hard enough sadge

Attachment
0
Rei

To make the sudoku hard for humans devious-ahh, I’m adding things like naked singles, hidden singles, naked pairs, pointing pairs, and box-line reduction.

Instead of determining the difficulty by the number of clues in the puzzle 3kcursed, or how hard it was for the generator to make hu-hmmmmmmm, I chose to determine the difficulty by what techniques you need to solve it hehepepe

Right now, I’m working on the applyNakedPairs function coding-racoon

Soooo, I know it have been a while since the last devlog (27 days ago) sad-rat
I was busy with my mid-year exams so I didnt code much sollyyy okig

Attachment
0
Rei

The generator now is less fast ; - ;
Now the solver stores candidates per cell and updates them incrementally every time I place or remove a number. No more recomputing everything, the board actually remembers things now yaya

Another big change: instead of generating a puzzle then checking the difficulty, the generator now filters the clues while removing them. But this part is still under work :D

Difficulty will probably be based on these:

Attachment
1

Comments

Rei
Rei 2 months ago

*maxGuessDepth, a typo

Rei

Now there is HARD 6x6 sudoku generation too! (alongside MEDIUM and EASY).

i doubt it’s hard, but it’s 6x6 sudoku so what can i expect lol?

i had tooo many errors, especially with loops. Next im going to make this generator faster, next im going to visualize it yaya :D

here is a hard 6x6 sudoku puzzle :0

Attachment
0
Rei

I replaced naive backtracking with constraint-based solving >w<

Before, the generator would place a number into a cell (like at (r, c)), check if it’s valid, and if not, backtrack and brute-try every number from 1 to 6.

Now it first figures out which numbers actually make sense for that cell and only tries those. No more pointless checks. It’s faster, cleaner, and way smarter :3

Here’s a 6x6 sudoku, try it, it’s fun :D

Attachment
0
Rei

Fixed the bug (turns out I was using the same rng every time), so I kept getting identical puzzles. Now that’s sorted, and I’ve upgraded the whole thing. I’m using bitmasks now, which makes the generator faster than before (wayyy faster), plus I tossed in a few extra improvements :D

Testing it was actually pretty fun — the puzzles I’m getting all have unique solutions. This is a 6×6 Sudoku generator (grid is either 2×3 or 3×2), so naturally I had to try giving it some cursed dimensions like 3×3, 4×8, etc… just to see what happens hehehe

This is the answer I got: (this was funniest part lol)
It crashes and outputs nth js in one case: 3x3 ⬇️

Attachment
Attachment
0
Rei

I think I broke smth when I tided the code a lil, idk Im rlly sleepy so Good Night People UwU

Gotta fix the code (tmr)

Here’s a 6x6 (3, 2) sudoku enjoy solving it Ov<*

Attachment
2

Comments

Laney
Laney 3 months ago

3 4 | 6 5 | 1 2
5 1 | 3 2 | 6 4
2 6 | 4 1 | 3 5

6 3 | 2 4 | 5 1
1 2 | 5 6 | 4 3
4 5 | 1 3 | 2 6

Fun puzzle! I did enjoy solving it

Rei
Rei 3 months ago

Ohh I’m glad to hear that :D

Rei

I think the 6x6 sudoku generator is ready, all I have to do is to:

  1. make sure the outputted sudoku is always correct.
  2. clean the code (cuz I got many errors and commented a lot of stuff).

Then I can commit it OwO

Here (down ⬇️) is an easy 6x6 sudoku (3, 2) with solution

Attachment
Attachment
0
Rei

So, uhem uhem, I’ve wasted an hour trying to figure out why I get these red lines in my code even tho everything is right, no syntax errors, but VS Code keeps showing up these red lines. The code compiles and works perfectly, whyyyy the red linessss. And because I have OCD, I couldn’t work. It seems like the problem is from VS Code, so I installed Dev cpp, but tbh it sucks, like all cpp editors. Now I gave up (temporarily), gonna js work on my proj till I figure it out.

I coded the 4x4 sudoku generator like 2 months ago, now I’m working on the 6x6 sudoku generator :D

Attachment
0