Sudoku puzzle creator/solver

Just BASIC Games
uncleBen
Posts: 63
Joined: Sat Oct 29, 2005 9:03 pm

Sudoku puzzle creator/solver

Post by uncleBen »

This is a sudoku program, and by no standards a good one. (It is named after a well-known chess program, this is only self-irony.)

- Firstly, the puzzles it creates can have several solutions (it was not my aim as i started out that there be only one solution) and the difficulty rating may be irrelevant.
- Secondly, the solver uses a very primitive and mechanical algorithm and although i have refined it a bit, it still may sometimes take several minutes (or much more if you're unlucky) to find the solution. It only takes into account what cannot be in a given cell, and not what can be. More human solving methods would speed it up a lot, but i don't know how to implement them, not being much of a sudoku-solver myself.
- Thirdly, the program has a few known "bugs".
If you abort solving by pressing a menu, the computer will stop solving although the message "Please wait" is still there.
The "Show solution" feature only works after you have created a new puzzle. It doesn't work after you have given the computer a try at solving the puzzle, because all data necessary for "Show solution" to work is erased the second you press "Solve".
I haven't fixed these bugs, because they don't really hinder using the program and because the code has become so messy I myself don't always understand what a bit of it does and why it has to be as it is (although i had a very clear idea when i wrote that part of code).

The code has become so complicated that it would be easier to write the whole thing from scratch to make any significant improvements.

Otherwise this program should present no threat to you, your family or your computer.

P.S. As I don't have a printer at home, this option has not been tested yet but it should work properly.
You do not have the required permissions to view the files attached to this post.
JanetTerra
Site Admin
Posts: 117
Joined: Wed Nov 24, 2004 2:49 am

Post by JanetTerra »

Nice job. The puzzle is veryintuitive and plays well. I programmed a Sudoku (Number Place) game a few months ago. I think the algorithms are similar. My version is for Liberty BASIC, but if you rem out the 3 lines with Stylebits commands, the game will play fine in Just BASIC.
http://www.lbdownloads.com/files/download.php?id=136
It might be interesting to compare algorithms. :)
Janet
uncleBen
Posts: 63
Joined: Sat Oct 29, 2005 9:03 pm

Post by uncleBen »

The program is impressive and easy to use. And code looks much much cleaner.
I don't think the algorithms are very similar though. My program, generally speaking, creates a new random puzzle by just rambling around more or less randomly. :oops: Even the %s the "progress meter" shows may not reflect real progress :oops: (as the program may find it is easier to start over from the beginning if it keeps running into dead ends).
It took me a week to write the whole thing and I didn't almost have a clue, how to do this or that task when i started out. Ideas got clearer though, and it is also reflected in the code. However I usually avoid changing parts of code that do their job in a satisfactory way, so it is still there.
P.S I noticed extensive use of REDIM. Is it used to reset the whole array? Why on earth has it not occurred to me that you can do it with just ONE command?! :(
JanetTerra
Site Admin
Posts: 117
Joined: Wed Nov 24, 2004 2:49 am

Post by JanetTerra »

I rely upon the Redim command quite a bit to empty arrays or to change the number of array members. Your program is great! It's playable and it doesn't crash and it looks good! Most people couldn't write down the steps to solve a problem like this, much less get it into code. You should be patting yourself on the back and yellling Hooray!!! Here, I'll do it for you -- It's a WAY COOL 8) program!


. [Hooray!!]
:lol: /

I've tucked your program away in my list of favorite JB Programs.

Janet
JanetTerra
Site Admin
Posts: 117
Joined: Wed Nov 24, 2004 2:49 am

Post by JanetTerra »

I rely upon the Redim command quite a bit to empty arrays or to change the number of array members. Your program is great! It's playable and it doesn't crash and it looks good! Most people couldn't write down the steps to solve a problem like this, much less get it into code. You should be patting yourself on the back and yellling Hooray!!! Here, I'll do it for you -- It's a WAY COOL 8) program!


. [Hooray!!]
:lol: /

I've tucked your program away in my list of favorite JB Programs.

Janet
uncleBen
Posts: 63
Joined: Sat Oct 29, 2005 9:03 pm

Post by uncleBen »

I am currently working on a more challenging game (need to program a decent AI), but if I get tired of it here's my to-do list for Sudokumaster v.1.01:
- substitute array resetting loops with REDIM statements :D
- possibly remove *Check solution* (pretty useless, isn't it?) and substitute it with a *Give one more clue* feature. (The solver usually runs out of logical moves and needs to take a wild guess. Wrong guesses may make the puzzle unsolvable but you may find it out too late to trace back to the original mistake.)
Removing *Check solution* would also get rid of the timer that prevents using delsegment on controls' graphicbox updating. :lol:
- modify the clue-displaying part so that it gives a fixed number of clues for current difficulty level. (Modify difficulty choice so that you can choose the number of clues instead of "easy", "normal", "hard".)
This will also allow generating symmetrical puzzles. (Doesn't work well on this version, because the deviations from the number of clues per difficulty level tend to get even bigger.
- Possibly a score keeper (clues initially minus times of *Give more clues* pressed).

Anything else?
uncleBen
Posts: 63
Joined: Sat Oct 29, 2005 9:03 pm

Post by uncleBen »

Well, here's v.1.01

Main changes:
1) fixed number of clues (15 - 60) - players choice
(Don't use minimum though. If I remember correctly, 17 is the known minimum number of givens where the puzzle has only one solution. And you can't expect such a masterpiece to be generated randomly!)
2) replaced Solution-check with Give-A-Clue, hopefully this is a more user-friendly feature
3) made Help non-modal, updated contents.

Found a new bug in the meantime:
the solver seems to be unable to identify unsolvable puzzles (at least sometimes). Instead, it displays a solution, leaving the cells that can have no numbers blank.

I think I know what's the reason for it and I'll try to fix it.

#edit: Added another fail check and this should fix it. Enjoy!
You do not have the required permissions to view the files attached to this post.