
View previous topic :: View next topic 
Author 
Message 
 SaphuA
 Joined: 04 Oct 2005  Posts: 4  :   Items 

Posted: Sat Oct 08, 2005 11:19 am Post subject: Creating a grid 


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 )
fyi, I'm using Flash to code this
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:  348729516
195468237
267531429
++
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 


 Ruud Site Admin
 Joined: 17 Sep 2005  Posts: 708  :  Location: Netherlands  Items 

Posted: Sat Oct 08, 2005 11:42 am Post subject: 


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 boxbybox 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 13 attemps (faster when you implement backtracking in stead of restart)
Good luck 

Back to top 


 SaphuA
 Joined: 04 Oct 2005  Posts: 4  :   Items 

Posted: Sun Oct 09, 2005 2:22 pm Post subject: 


Just thought I might notify you guys, Ruud has been helping me over PM for the last two days, and I finaly did it 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
Here are some results (please note that it was made in Flash, hence the speed ): Code:  Map created in 281ms, rebuild 1 times.
328164579
519827634
647593128
++
164785392
973241865
852936741
++
786459213
291378456
435612987
Map created in 282ms, rebuild 1 times.
587642391
463189275
219537486
++
645728913
872913654
931465827
++
358276149
724391568
196854732
Map created in 634ms, rebuild 3 times.
857941632
413276895
296538714
++
521367489
364829571
978154263
++
649712358
132685947
785493126
Map created in 285ms, rebuild 1 times.
792856431
186743529
534129687
++
627498315
418235796
953617248
++
269584173
371962854
845371962  Now onto the puzzle creating
Any tips and articles are appreaciated.
~Sph 

Back to top 


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

Posted: Mon Dec 19, 2005 11:10 pm Post subject: generating grid 


So would you mind sharing the code you used to generate these grids? I'm trying to make an imagebased Sudokulike game (vs. numberbased) using movie clips, and I fear I'm in over my head! Gridgenerator code would be most helpful! 

Back to top 




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

Powered by phpBB © 2001, 2005 phpBB Group
Igloo Theme Version 1.0 :: Created By: Andrew Charron
