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   

Creating a grid

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

Joined: 04 Oct 2005
Posts: 4
:

Items
PostPosted: Sat Oct 08, 2005 11:19 am    Post subject: Creating a grid Reply with quote

Hi,
Right after my post, with the completed grid, I figured that my method for creating a sudoku grid (all numbers filled) was kinda crappy. Even though it was a legal grid, ther was this repeating lines in there which made it look unreal (hard to explain, just take from me it sucked Wink)

fyi, I'm using Flash to code this Rolling Eyes

So I'm not rewriting the grid using a totaly different approach.
Here's what I'm doing in short terms:
- The first cell [0,0] is filled the 9 numbers, each at a random position.
- The second cell [0,1] will be filled while taking care of the numbers on the first cell
- The tirth cell will be filled with the numbers that are left when looking at the numbers on the rows from cell [0,0] and [0,1]. And will randomly be placed.
- This will also be repeated for vertical

So then I get the folowing (so far so good) grid:
Code:
348|729|516
195|468|237
267|531|429
---+---+---
652|***|***
879|***|***
431|***|***
---+---+---
926|***|***
383|***|***
514|***|***

Although, the problem is that I don't know how to continue.
When I try to fill cell [1,1] I get the folowing problem:
When filling the cell while taking care of horizontonal and vertical numbers, and I get to the last block (lowest right in the cell). There is a big chance that I end up with a number that is already in the horizontal, or vertical row corresponding to it.

What would be the best way to go around this? Or what methods are you guys using to create a grid? Are there any articles or posts available covering this?

Thanks for you help,
~Sph
Back to top
View user's profile Send private message
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Sat Oct 08, 2005 11:42 am    Post subject: Reply with quote

Hi SaphuA,

I did use the same method you use, and ran into similar problems. There are a few topics in the Setting Sudoku section that cover this subject, but they're a bit hard to find.

This is how I circumvented the problem:

1. Abandon the box-by-box approach. Just randomly place digits in the grid.
2. Keep track of the number of candidates left for each cell after placing a digit. No advance logic or anything, just cells blocking eachother out.
3. Sort the remaining cells by number of candidates. If there's any cell with no candidates left, you must either backtrack or restart.
4. To avoid bias (creating the same solution every time), assign a random number to each cell when you start this process. Then sort on available candidates and random number when 2 cell have the same number of candidates.

This must give you a good solution within 1-3 attemps (faster when you implement backtracking in stead of restart)

Good luck
Back to top
View user's profile Send private message Visit poster's website
SaphuA

Joined: 04 Oct 2005
Posts: 4
:

Items
PostPosted: Sun Oct 09, 2005 2:22 pm    Post subject: Reply with quote

Just thought I might notify you guys, Ruud has been helping me over PM for the last two days, and I finaly did it Smile I'm pretty happy about this, since I was using totaly wrong approaches for the last 2 weeks, which all ended up worthless. So after 4 engines I finaly did it Wink

Here are some results (please note that it was made in Flash, hence the speed Wink ):
Code:
Map created in 281ms, rebuild 1 times.
328|164|579
519|827|634
647|593|128
---+---+---
164|785|392
973|241|865
852|936|741
---+---+---
786|459|213
291|378|456
435|612|987

Map created in 282ms, rebuild 1 times.
587|642|391
463|189|275
219|537|486
---+---+---
645|728|913
872|913|654
931|465|827
---+---+---
358|276|149
724|391|568
196|854|732

Map created in 634ms, rebuild 3 times.
857|941|632
413|276|895
296|538|714
---+---+---
521|367|489
364|829|571
978|154|263
---+---+---
649|712|358
132|685|947
785|493|126

Map created in 285ms, rebuild 1 times.
792|856|431
186|743|529
534|129|687
---+---+---
627|498|315
418|235|796
953|617|248
---+---+---
269|584|173
371|962|854
845|371|962
Now onto the puzzle creating Smile
Any tips and articles are appreaciated.

~Sph
Back to top
View user's profile Send private message
mo_vengeance

Joined: 19 Dec 2005
Posts: 1
:
Location: Chicago

Items
PostPosted: Mon Dec 19, 2005 11:10 pm    Post subject: generating grid Reply with quote

So would you mind sharing the code you used to generate these grids? I'm trying to make an image-based Sudoku-like game (vs. number-based) using movie clips, and I fear I'm in over my head! Grid-generator code would be most helpful!
Back to top
View user's profile Send private message
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