News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Sudoku

Started by PBrennick, February 06, 2009, 11:10:09 PM

Previous topic - Next topic

PBrennick

Hi there,

New version: 02/16/09:16:03

Show A Hint:
------------
Insert the correct character into the Cell that currently has the Focus. The Cell must be empty or an error message will be displayed. Before this happens, the Puzzle is checked for errors. If there are errors, a report on the first error is made and a Hint is NOT shown.

Paul


[attachment deleted by admin]
The GeneSys Project is available from:
The Repository or My crappy website

Farabi

Hi PB, long time no see. Sudoku is very popular on my country a year ago, and I guess it still got many fans these day.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

PBrennick

In the ShowBoard Procedure,

    invoke  Random, 500

needs to be changed to:

    invoke  Random, 499

Otherwise, if 500 is returned, as it will occasionally, the program will crash. I am not uploading a revised version with this change right now because I am almost finished implimenting Raymond Filiatreault's excellent Solver Procedure. I will post later today with both things done. At that point, I would like some feedback about the various options I am using - especially the Solver options - to make sure that my concept is acceptable.

Thank you, Ray, for the kewl Solver. It is totally dependable and the lag time is very acceptable. I have other versions of Sudoku and I noticed right away that your implimentation (brute force) has LESS lag time than other implimentations.

I am, and always have been, a Sudoku fanatic and belong to several clubs. Are any of you guys also Sudoku fanatics? If so, I definitely need feedback from you. I wrote this program because I have many versions with differing options. My desire was to use the best options from each implimentation into one program. I wonder if I should include a Solver option where a user can crank in Puzzles that are found in newspapers, etc. and test if they will solve. Maybe add them to a 'user' archive.

Any thoughts?

Paul
The GeneSys Project is available from:
The Repository or My crappy website

FORTRANS

Hi,

   Fanatic?  Maybe...  I tried writing a sudoku generator (FORTRAN 77),
and had problems making it generate difficult puzzles.  Herbert Kleebauer
posted a solver in alt.lang.asm.  32-bit and 992 bytes.  He also explained
the basis for his algorithm.  Other solvers, like those in the Hugi Compo,
were recursive or not well explained.  I translated his program to 16-bit
in order to understand the algorithm.  (Well sort of, I had bugs for a long
time as the 32-bit code did some non-obvious things that need to be done
explicitly with my 16-bit code.)

   After that I used the algorithm in my generator to clear out more numbers
in the puzzle.  It went from ~34 to ~24.  Most of the puzzles are still not
very difficult though.  Obviously, something better than brute force
elimination is required to generate a good puzzle consistently.

Oh well,

Steve N.

PBrennick

Yeah, well I have 20,000 Puzzles in my archive as I stated somewhere. They will become a DLL very soon, now. As far as generating Puzzles go, I do not understand your use of the term, 'brute force.' Are you referring to Ray's Solver? A generator and a solver are two different animals and his code is very nice.

As far as generating Puzzles go, I started with a solution (build your grid with 1-9, 9 times and then scramble it carefully to avoid generating errors. I used a swapping algo. Once you have a solution, all you have to do is selectively remove some of the numbers until you generate a Puzzle needing to be solved. The more numbers you remove, the higher the difficulty rating.

In other words, I generate a Puzzle by working backwards, you should consider doing the same - it is extremely easy to do it that way.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

FORTRANS

Quote from: PBrennick on February 12, 2009, 09:55:33 PM
Yeah, well I have 20,000 Puzzles in my archive as I stated somewhere. They will become a DLL very soon, now. As far as generating Puzzles go, I do not understand your use of the term, 'brute force.' Are you referring to Ray's Solver? A generator and a solver are two different animals and his code is very nice.
Not Ray's solver, unless he uses the same algorithm.  'Brute force' means I
use the solver to eliminate numbers rather than a nice formula.  Kill a number,
feed the potential puzzle to the solver, if it is solved, carry on,  If not, restore
the number and try again.  I tried various formulas to eliminate positions, but
couldn't get good results

   If you have a pointer to his code, it would be nice to see if it would be any
better than the one I am now using.

Quote
As far as generating Puzzles go, I started with a solution (build your grid with 1-9, 9 times and then scramble it carefully to avoid generating errors. I used a swapping algo. Once you have a solution, all you have to do is selectively remove some of the numbers until you generate a Puzzle needing to be solved. The more numbers you remove, the higher the difficulty rating.
Yep, that's it for me as well.  Currently only four seed matrices, but I'll bump
that up sometime.

Quote
In other words, I generate a Puzzle by working backwards, you should consider doing the same - it is extremely easy to do it that way.
Well 'easy' but the puzzles I generate are a bit too easy (maybe).

Regards,

Steve N.

Jimg

That's a terrible addiction, and you won't get me hooked again.   :snooty: You won't.  wont...  well, maybe I'll just peek at your code...........

PBrennick

Oh, oh, all is lost, you will get hooked again. The version with the solvewr will be posted later today. I am just finalizing the 'look and feel.'

Paul
The GeneSys Project is available from:
The Repository or My crappy website

PBrennick

#8
New upload at the top. The solver is now functioning. It is done in the way that my club wished it to be done. This means that the Puzzle will not be solved for you but, if you desire, you can see what the solution is in the Report Window. The feature can be turned ON/OFF from the menu and persists via the INI file. Tell me what you think.

I could not get a clear consensus as to whether there should be a HINT feature that would be enabled IF the Show Solution option is OFF. Got a lot of purists in the club, some of them where against allowing the solution to be seen at all. They felt that its only purpose should be to verify that the Puzzle is solvable. What I have done is to achieve a compromise.

Anyway, take a look at your Solver in action, Ray. It works very well!

Paul
The GeneSys Project is available from:
The Repository or My crappy website

PBrennick

Gentlemen,

I need some advice. I have added the Solver and a 'Show Solution' option. If the 'Show Solution' option is not enabled should I make an error checker available? This would, of course, be a different thing than the 'Check for Duplication errors' option.

I do not want the app to turn into a pig but, I want to make it a fun thing to use.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Vortex

Hi Paul,

Adding an error checker is a nice idea.

PBrennick

New Upload at the top. Error checking has been added and I fixed the Restart option to deal with 'Show solution' correctly. Previous version merrily ignored the setting.

I sure am getting a lot of mileage out of that Report Window!

Paul
The GeneSys Project is available from:
The Repository or My crappy website

raymond

QuoteAnyway, take a look at your Solver in action, Ray. It works very well!

I tried it on a few of the hard ones. It seems pretty well instantaneous.

Nitpicking: I noticed that in the possibilities window, some of the numbers are often not separated by a space, and in other cases they may be separated by more than one space. There didn't seem to be any pattern with the few attempts I made.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

PBrennick

I suppose I could do something about that, but there IS a pattern. If there is no 5, for instance, there will be a space there instead. If there is no 5 and 6, there will be two spaces. In other words, each number has its own place and is never anywhere else, seemed natural to me. Because of the font, a space does not have the same weight as a character so it may look odd. Should I switch to a mono-spaced font? IIRC, it is MS Sans Serif right now.

I just uploaded a test version that switches the font in that label to Courier, 16pt., Normal. The results should be more apparent to you. Do you like this better?

Paul
The GeneSys Project is available from:
The Repository or My crappy website

raymond

Quotebut there IS a pattern.
You're right. My fault. :red :( I should have picked up that pattern if I had paid just a little more attention to it.

It now makes sense and no need to waste time to fix something that's not broken. :U
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com