Sudoku Programmers Forum Index

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in          Games  Calendar

Log in to check your private messagesLog in to check your private messages   

Pattern based generator (VB6 code available)

 
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku
View previous topic :: View next topic  
Author Message
Lunatic

Joined: 11 Mar 2007
Posts: 166
:
Location: Ghent - Belgium

Items
PostPosted: Thu Apr 03, 2008 6:41 pm    Post subject: Pattern based generator (VB6 code available) Reply with quote

For anyone interested, i've been updating my pattern based sudoku generator recently and is now downloadable, just click here. Visual Basic source code is available too.
Since there's no Help file, i will provide some information here...

This is the interface:



How to generate sudokus:
-Choose a base pattern (using "Next" or "Previous" buttons, or create a new one by toggling the cells on/off with the mousecursor. The red cells are those where the givens are to be generated.
-Choose the required modifications, there are only two sorts of modifications possible. The first one, Limited to "Very Hard" will limit the generated sudokus to the "Very Hard" level. With the other option you can make the generator try to expand the base pattern with 1, 2 or 3 extra givens which will only occur if the base pattern has multiple solutions making attempts to find a unique solution. By default, this option is set to "Don't expand, seek sequential". This default option will seek for the first unique sudoku from a maximum of 250 sequential attempts based on the first randomly generated givens. If no unique sudoku is found within 250 attempts, the givens are randomly regenerated, and so on.
[EDIT 1 = April 12th 2008]
- Added the possibility to change the number of sequential attempts
- Added the posibility to request Minimal check for both generator and uniqueness test, this means that all clues are needed to have a unique solution
[END EDIT 1]
[EDIT 5 = October 6th 2008]
- Added the possibility to generate with randomly choosen patterns from those allready available
[END EDIT 5]

The whole generator is based on my pseudo-dancing links brute force solver written in Visual Basic. See topic "DANCING LINKS and VISUAL BASIC"

The patterns have some restrictions...
-a minimum of 20 givens is required
-more than one empty row within the same band is not allowed
-more than one empty column in the same stack is not allowed
-more then four empty boxes are not allowed

About the randomly generated givens...
-the given cells are adressed in random order (by using a randomly re-ordered GivenMap-array)
-each given cell will recieve the available candidates in random order (by using a randomly re-ordered multiple CandidateMap-array)

About the levels...
1) Very Easy - Sudokus requiring only hidden singles
2) Easy - Sudokus also requiring naked singles
3) Medium - Sudokus also requiring box-line reductions and/or pointing pairs
4) Hard - Sudokus also requiring naked subsets
5) Very hard - Sudokus also requiring hidden subsets

Generated sudokus not answering to these levels are called "others".
[EDIT 2 = April 12th 2008]
- switched hidden and naked singles from level.
The basic solve techniques "Crosshatching" and "Slicing & dicing" normally spots hidden singles. Naked singles are easier to spot if you use pencilmarks. Since pencilmarks are normally needed for higher levels, i changed the order for the easy levels.
[END EDIT 2]

[EDIT 3 = April 27th 2008]
Output files:
The following output file types are available:

1) MPQ Sudoku file type
Very Easy: Sudoku_Very_Easy.sds
Easy: Sudoku_Easy.sds
Medium: Sudoku_Medium.sds
Hard: Sudoku_Hard.sds
Very Hard: Sudoku_Very_Hard.sds
Others: Sudoku_Others.sds

Each file can hold multiple sudokus, format is built up this way:
There's no file-header, and each sudoku is saved in a 166 bytes long record. The first 81 bytes are reserved for the sudoku to be solved, and are saved in binary format. The following 81 bytes are holding the solution, also in binary format. The last 4 bytes of each sudoku record are reserved for keeping the best solving time for that sudoku, 2 bytes (in fact, an integer value) for the minutes, and another integer value for the seconds.
To import them with MPQ Sudoku, see the help file topic MPQ Sudoku – File Check and Import (only for advanced users)

2) Simple Sudoku file type
Very Easy: Very_Easy_0001.ss, Very_Easy_0002.ss, ...
Easy: Easy_0001.ss, Easy_0002.ss, ...
Medium: Medium_0001.ss, Medium_0002.ss, ...
Hard: Hard_0001.ss, Hard_0002.ss, ...
Very Hard: Very_Hard_0001.ss, Very_Hard_0002.ss, ...
Others: Others_0001.ss, Others_0002.ss, ...
Each file holds one sudoku, format is built up this way:
There's no file-header, and each sudoku is saved in text-format like this example:
Code:
...|123|...
..1|...|4..
.5.|...|.6.
-----------
7..|..5|..3
8..|...|..9
2..|7..|..6
-----------
.3.|...|.5.
..7|...|2..
...|948|...


3) SudoCue file type
Very Easy: Very_Easy_0001.sdk, Very_Easy_0002.sdk, ...
Easy: Easy_0001.sdk, Easy_0002.sdk, ...
Medium: Medium_0001.sdk, Medium_0002.sdk, ...
Hard: Hard_0001.sdk, Hard_0002.sdk, ...
Very Hard: Very_Hard_0001.sdk, Very_Hard_0002.sdk, ...
Others: Others_0001.sdk, Others_0002.sdk, ...
Each file holds one sudoku, format is built up this way:
There's no file-header, and each sudoku is saved in text-format like this example:
Code:
...123...
..1...4..
.5.....6.
7....5..3
8.......9
2..7....6
.3.....5.
..7...2..
...948...


4) Into Sudoku file type
Very Easy: Very_Easy_0001.sud, Very_Easy_0002.sud, ...
Easy: Easy_0001.sud, Easy_0002.sud, ...
Medium: Medium_0001.sud, Medium_0002.sud, ...
Hard: Hard_0001.sud, Hard_0002.sud, ...
Very Hard: Very_Hard_0001.sud, Very_Hard_0002.sud, ...
Others: Others_0001.sud, Others_0002.sud, ...
Each file holds one sudoku, format is built up this way:
There's no file-header, and each sudoku is saved in text-format like this example:
Code:
000123000
001000400
050000060
700005003
800000009
200700006
030000050
007000200
000948000


5) Sudoku Explainer file type
Very Easy: Very_Easy_0001.txt, Very_Easy_0002.txt, ...
Easy: Easy_0001.txt, Easy_0002.txt, ...
Medium: Medium_0001.txt, Medium_0002.txt, ...
Hard: Hard_0001.txt, Hard_0002.txt, ...
Very Hard: Very_Hard_0001.txt, Very_Hard_0002.txt, ...
Others: Others_0001.txt, Others_0002.txt, ...
Each file holds one sudoku, format is built up this way:
There's no file-header, and each sudoku is saved in text-format like this example:
Code:
...123...
..1...4..
.5.....6.
7....5..3
8.......9
2..7....6
.3.....5.
..7...2..
...948...


6) 81 character text string (.)
Very Easy: Sudoku_Very_Easy.txt
Easy: Sudoku_Easy.txt
Medium: Sudoku_Medium.txt
Hard: Sudoku_Hard.txt
Very Hard: Sudoku_Very_Hard.txt
Others: Sudoku_Others.txt
Each file holds multiple sudokus, format is built up this way:
There's no file-header, and each sudoku is saved in text-format like this example:
Code:
...123.....1...4...5.....6.7....5..38.......92..7....6.3.....5...7...2.....948...


7) 81 character text string (0)
Very Easy: Sudoku_Very_Easy_0.txt
Easy: Sudoku_Easy_0.txt
Medium: Sudoku_Medium_0.txt
Hard: Sudoku_Hard_0.txt
Very Hard: Sudoku_Very_Hard_0.txt
Others: Sudoku_Others_0.txt
Each file holds multiple sudokus, format is built up this way:
There's no file-header, and each sudoku is saved in text-format like this example:
Code:
000123000001000400050000060700005003800000009200700006030000050007000200000948000

[END EDIT 3]

[EDIT 4 = may 11th 2008]
For each output filetype there will be a subfolder created in the application folder

Pattern files:
Each base pattern is saved as a record within a file called Pattern.rec and this file is kept in the application folder. The old pattern filetypes are still distributed, but are converted to the new filetype the first time you will run the program along with your own or imported pattern files.
[END EDIT 4]

A pattern browser is under the "Pick" button.
You can, under some restrictions, import patterns from the original MPQ Sudoku files as well with the "Import" button.

And last but not least, you can check sudokus for uniqueness (see explanation in the textbox at the interface)
_________________
Marc
~~~<><~~~<><~~~<><~~~<><~~~


Last edited by Lunatic on Mon Apr 20, 2009 4:02 pm; edited 10 times in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
gsf

Joined: 18 Aug 2005
Posts: 411
:
Location: NJ USA

Items
PostPosted: Thu Apr 03, 2008 6:59 pm    Post subject: Re: Pattern based generator Reply with quote

Lunatic wrote:
For anyone interested, i've been updating my pattern based sudoku generator recently and is now downloadable

have you tried your generator on any of the player's forum patterns game patterns?
Back to top
View user's profile Send private message Visit poster's website
Lunatic

Joined: 11 Mar 2007
Posts: 166
:
Location: Ghent - Belgium

Items
PostPosted: Thu Apr 03, 2008 7:07 pm    Post subject: Re: Pattern based generator Reply with quote

gsf wrote:
have you tried your generator on any of the player's forum patterns game patterns?


No, what do you mean ? Any links ?
_________________
Marc
~~~<><~~~<><~~~<><~~~<><~~~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
gsf

Joined: 18 Aug 2005
Posts: 411
:
Location: NJ USA

Items
PostPosted: Thu Apr 03, 2008 8:00 pm    Post subject: Re: Pattern based generator Reply with quote

Lunatic wrote:
gsf wrote:
have you tried your generator on any of the player's forum patterns game patterns?

No, what do you mean ? Any links ?

http://www.sudoku.com/boards/viewtopic.php?t=5760
Back to top
View user's profile Send private message Visit poster's website
Lunatic

Joined: 11 Mar 2007
Posts: 166
:
Location: Ghent - Belgium

Items
PostPosted: Fri Apr 11, 2008 4:39 pm    Post subject: Re: Pattern based generator Reply with quote

gsf wrote:
Lunatic wrote:
gsf wrote:
have you tried your generator on any of the player's forum patterns game patterns?

No, what do you mean ? Any links ?

http://www.sudoku.com/boards/viewtopic.php?t=5760


I've been looking at it, but how to participate ?

I have downloaded Sudoku Explainer 1.2.1 but how to get those ratings like ED=6.5/1.2/1.2 ?
I can use the "Analize" function but that only gives me a Hint rating.

For the current pattern (game 0026) i have (for example) a valid grid

000000000004908700060501080018000560000000000037000890080309050003704200000000000

with hint rate 6,6

Do I need another program, to get the right output ?
_________________
Marc
~~~<><~~~<><~~~<><~~~<><~~~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
gsf

Joined: 18 Aug 2005
Posts: 411
:
Location: NJ USA

Items
PostPosted: Fri Apr 11, 2008 5:56 pm    Post subject: Re: Pattern based generator Reply with quote

Lunatic wrote:
gsf wrote:

http://www.sudoku.com/boards/viewtopic.php?t=5760

I have downloaded Sudoku Explainer 1.2.1 but how to get those ratings like ED=6.5/1.2/1.2 ?

use SE from the command line

look at the ratings section in the url above
the serate(1) link has the command line invocation in the INVOCATION section
pass the 81-char puzzle as the operand on the command line invocation
Back to top
View user's profile Send private message Visit poster's website
Lunatic

Joined: 11 Mar 2007
Posts: 166
:
Location: Ghent - Belgium

Items
PostPosted: Sat Apr 12, 2008 9:55 am    Post subject: Reply with quote

Allmost there......

Downloaded SudokuExplainer.jar and put it in folder C:\SUDPAT

My generated sudokus are in the same folder in file GAMEXXXX.txt where XXXX = the number of the game (currently 0026)

I use following command (with arguments):
java -Xrs -Xmx500m -cp C:\SUDPAT\SudokuExplainer.jar diuf.sudoku.test.serate -f%g/%r/%p/%d -iC:\SUDPAT\GAME0026.txt -oC:\SUDPAT\RATE0026.txt

Works fine !

Now, to submit puzzles, they must have following properties:

valid (obvious)
same pattern (obvious)
minimal (have to implement this check in my generator)
not isomorphic to any previous puzzle in the current game
So, I must keep track of all posted puzzles in the current game, and find out if my puzzles are not isomorphic to them.
Why ?

If my puzzle is isomorphic to any previous posted one, should i not expect the same ratings ? In other words, if i get other/higher ratings, is my puzzle then not by definition non-isomorphic ?
_________________
Marc
~~~<><~~~<><~~~<><~~~<><~~~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
tarek

Joined: 31 Dec 2005
Posts: 153
:
Location: London, UK

Items
PostPosted: Sat Apr 12, 2008 11:01 am    Post subject: Reply with quote

Lunatic wrote:

not isomorphic to any previous puzzle in the current game
So, I must keep track of all posted puzzles in the current game, and find out if my puzzles are not isomorphic to them.
Why ?

If my puzzle is isomorphic to any previous posted one, should i not expect the same ratings ? In other words, if i get other/higher ratings, is my puzzle then not by definition non-isomorphic ?

there are occasions when Sudoku Explainer has rated 2 isomorphic versions of the same puzzle differently.

Therefore, relying on rating alone wouldn't prevent a possible isomorph from sneaking in.

tarek
Back to top
View user's profile Send private message
JPF

Joined: 05 Dec 2005
Posts: 29
:
Location: Paris

Items
PostPosted: Sat Apr 12, 2008 1:10 pm    Post subject: Reply with quote

Right, see here.
The current SE 1.2.1 still has this bug.

JPF
Back to top
View user's profile Send private message
gsf

Joined: 18 Aug 2005
Posts: 411
:
Location: NJ USA

Items
PostPosted: Sat Apr 12, 2008 1:55 pm    Post subject: Reply with quote

Lunatic wrote:

So, I must keep track of all posted puzzles in the current game, and find out if my puzzles are not isomorphic to them.
Why ?

If my puzzle is isomorphic to any previous posted one, should i not expect the same ratings ? In other words, if i get other/higher ratings, is my puzzle then not by definition non-isomorphic ?

you will probably be safe not checking for isomorphs within the confines of one game
we're not sure how often SE hits this bug
right now we only have 1 example over the last year
maybe we should consider adding a knuth-ian bonus for any isomorphic grid with a different SE rating
just to see how rare they really are
Back to top
View user's profile Send private message Visit poster's website
Lunatic

Joined: 11 Mar 2007
Posts: 166
:
Location: Ghent - Belgium

Items
PostPosted: Sat Apr 12, 2008 9:04 pm    Post subject: Reply with quote

JPF wrote:
The current SE 1.2.1 still has this bug.

Bugs Shocked , hmmm, sounds familiar Rolling Eyes

Reminds me at that "programmers drinking song"...

One little bug in the code ?
One little bug in the code !
Fix one bug, compile it again...
...two little bugs in the code !

Two little bugs in the code ?
Two little bugs in the code !
Fix one bug, compile it again...
...three little bugs in the code !

and so on... Laughing
_________________
Marc
~~~<><~~~<><~~~<><~~~<><~~~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Lunatic

Joined: 11 Mar 2007
Posts: 166
:
Location: Ghent - Belgium

Items
PostPosted: Sun Apr 27, 2008 7:20 pm    Post subject: Reply with quote

April 27th 2008:

Update now available with following new features:

Added a pattern browser under the new "Pick button".
Included a selection list to choose from different output file-types.
Fixed some bugs...

See [EDIT 3] section at first post of this topic for more details

Please remove any previous version before installing the new one !!!

Regards,
Lunatic.
_________________
Marc
~~~<><~~~<><~~~<><~~~<><~~~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Lunatic

Joined: 11 Mar 2007
Posts: 166
:
Location: Ghent - Belgium

Items
PostPosted: Mon Oct 06, 2008 5:56 pm    Post subject: Reply with quote

October 6th 2008:

Update now available with following new feature:

- Added the option to generate sudokus using randomly choosen patterns from those allready available.

See [EDIT 5] section at first post

Please remove any previous version before installing the new one !!!

Regards,
Lunatic.
_________________
Marc
~~~<><~~~<><~~~<><~~~<><~~~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Sudoku Programmers topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group

Igloo Theme Version 1.0 :: Created By: Andrew Charron