The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: PBrennick on February 06, 2009, 11:10:09 PM

Title: Sudoku
Post by: PBrennick on February 06, 2009, 11:10:09 PM
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]
Title: Re: Sudoku
Post by: Farabi on February 07, 2009, 03:38:01 AM
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.
Title: Re: Sudoku
Post by: PBrennick on February 12, 2009, 01:33:32 PM
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
Title: Re: Sudoku
Post by: FORTRANS on February 12, 2009, 03:02:02 PM
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.
Title: Re: Sudoku
Post by: 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.

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
Title: Re: Sudoku
Post by: FORTRANS on February 12, 2009, 11:14:57 PM
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.
Title: Re: Sudoku
Post by: Jimg on February 13, 2009, 12:53:45 AM
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...........
Title: Re: Sudoku
Post by: PBrennick on February 13, 2009, 02:50:25 PM
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
Title: Re: Sudoku
Post by: PBrennick on February 14, 2009, 02:15:02 AM
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
Title: Re: Sudoku
Post by: PBrennick on February 14, 2009, 02:18:42 PM
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
Title: Re: Sudoku
Post by: Vortex on February 14, 2009, 03:18:14 PM
Hi Paul,

Adding an error checker is a nice idea.
Title: Re: Sudoku
Post by: PBrennick on February 14, 2009, 10:10:24 PM
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
Title: Re: Sudoku
Post by: raymond on February 15, 2009, 02:37:50 AM
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.
Title: Re: Sudoku
Post by: PBrennick on February 15, 2009, 05:58:25 AM
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
Title: Re: Sudoku
Post by: raymond on February 15, 2009, 04:15:30 PM
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
Title: Re: Sudoku
Post by: PBrennick on February 15, 2009, 04:40:27 PM
Ray,
No problem. Since I 'have' made a change, could you tell me which you like better? The original was MS Sans Serif and now I am using Courier because it is monospaced which means a space is the same size as a character (no proportioning as you know).

I am working on the HINT option right now. As with other options, I will maintain my trend of using the Report Window. The Hint will be broadcast there and if the user wants to add it to the Puzzle, they can.

I will be adding your name in the Help section if you were wondering. Nobody has stepped forward with any opinions except FORTRAN so it looks like it will be the two of you. Him as a beta tester, you as a code contributor and as a beta tester. I thought I was going to get some opinions from Jimq, but he went silent, probably still trying to solve the first Puzzle.  :toothy

Paul
Title: Re: Sudoku
Post by: raymond on February 15, 2009, 05:42:25 PM
Courier looks good. Probably better than the MS.

As for your HINT option, that should be easy as you have the solver already incorporated.
- run the solver immediately after loading the problem and keep it in memory (only 81 bytes);
- use it as a lookup table if the user asks for a hint;
- no need for code to transfer the hint to the puzzle (the user can do that on its own).
Title: Re: Sudoku
Post by: PBrennick on February 15, 2009, 09:27:32 PM
Ray,
Yes, szSolution is the buffer, I keep it valid for the duration of the session. That is what I am using for the error checker and will use it for the Hint. I thought about this:

1. Get a Random Hint and reveal it in the Report Window.
2. Get a Random Hint and reveal it in the Report Window AND store it in the Puzzle (set focus to that square).
3. If the focus is on an empty cell when the User requests a Hint, put the value that belongs to that cell into the cell.
4. Allow the User to select a number from one to nine. Use that selection for Hinting.
5. Allow the User to select a number from one to nine. Fill in all occurences of the number selected.

I decided on #1, but what do you think about the other ideas? Probably feature overkill?

Paul
Title: Re: Sudoku
Post by: raymond on February 16, 2009, 02:09:41 AM
My preference would definitely go for #3 ONLY.
Title: Re: Sudoku
Post by: PBrennick on February 16, 2009, 03:40:08 AM
So be it, #3 it is. I think that is a very useful method. It is nor random but will be the most helpful. I never saw ANY other version do it in that way.

Paul
Title: Re: Sudoku
Post by: PBrennick on February 16, 2009, 09:01:42 PM
New upload at the top. This version adds the Hint option. I guess, except for the addition of the DLL, that the program is complete.

Paul
Title: Re: Sudoku
Post by: PBrennick on February 18, 2009, 02:14:53 PM
Hi there,
The Puzzle DLL has been added to Sudoku. If the DLL is found, there will be 20,000 Puzzles available. If the DLL shows up missing, the Game will revert to the 2,000 internal Puzzles.

The size of the ZIP is now almost 700,000 bytes so I can no longer upload it to this Board. If anyone wants the Game with sources (including the DLL source), send an email to pbrennick@yahoo.com (pbrennick@yahoo.com). I will, then, email it directly to you.

Paul
Title: Re: Sudoku
Post by: herge on February 19, 2009, 08:06:55 PM

Hi  PBrennick:

I have downloaded sudoku.
The game works.
I seem to be having trouble with the Control and Function keys.
They don't appear to any thing.

Regards herge.
Title: Re: Sudoku
Post by: PBrennick on February 19, 2009, 09:15:15 PM
Are you saying that none of the Control and Function Keys work on your computer? That seems odd. What is your OS? I am using XP HE with no problems.

Is anyone else having trouble with the Control keys?
Paul