Sudoku Arcade
- 2 Devlogs
- 3 Total hours
Sudoku Arcade
Sudoku Arcade
Updated the Sudoku game. It now allows users to play the game themself. The other option is to watch the bot solver using the algorithm described in the previous devlog. The next option is to race against the bot. The last option is to quit the game.
I first built a Sudoku game using Python and Pygame. Sudoku is a number-based logic puzzle played on a 9x9 grid where the goal is to fill every row, column, and 3x3 section with numbers 1 through 9 without repeating any digit.
To make the computer solve puzzles automatically, I built a backtracking solver.
Think of the bot like a person walking through a maze. Since it can’t see the whole maze at once, it has to remember every step it takes. My two stacks (stack_empty and stack_av) act like a trail of breadcrumbs and a list of backup choices at every fork in the road.
Here is how the logic works step-by-step:
Taking a Step Forward:
The bot looks for an empty spot, checks what numbers are allowed using the valid function, and picks the first legal number.
stack_empty) with the spot’s location, and saves its leftover backup numbers in a pocket (stack_av).Hitting a Dead End:
Sometimes, the bot fills up the board, but a later spot gets completely stuck because no numbers are legal.
0.Backtracking (Rewinding):
It looks at its last breadcrumb (stack_empty) and checks its backup pocket (stack_av) to see if it has any untried numbers left for that spot. If that spot is also out of options, it deletes it, erases it back to 0, and steps back even further up the stack.
Once it finds a spot that still has a backup number waiting, it plays that new number and starts moving forward again. In short, the stacks let the bot undo its mistakes one step at a time instead of starting over from scratch!