cooldude832 Posted July 30, 2007 Share Posted July 30, 2007 This idea just came to me(i don't know its like a gift (guess what movie that's from)) making a sudoku (single level) off php. Anyone got a logical idea on doing it, I know i need to generate 81 random numbers and then compare it to values, but i have a feeling since its is a top down sort of system i will get to the last squares and it will never find a match and end up making dead puzzles any ideas? Quote Link to comment Share on other sites More sharing options...
Humpty Posted July 30, 2007 Share Posted July 30, 2007 Doing the if then or switch (select case) statements is probably the easiest thing to do. Then the next would be the displaying. I think perhaps you were looking for some magical formula or equation or algorithm or similar. Why not keep it simplistic and make the puzzle howyou would by hand, check this out: http://www.sudokuonline.us/make_your_own_sudoku_puzzle.php I know that once you've done it I would be interested in the code. Sounds like a fun thing to actually create too. May I suggest perhaps AJAX or JS for the actual game play. Can't wait to see your finished product Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 30, 2007 Author Share Posted July 30, 2007 I got it going except i want to define the 3x3 boxes as i go and i'm having trouble figuring out how to do it in logic, this is what i got <?php <?php DEFINE("MAX", 9); $board = array(); $colored = 0; while($colored <=27){ $temp1 = rand(1,MAX); $temp2 = rand(1,MAX); $square = $temp1."_".$temp2; if(empty($board[$square])){ $board[$square] = "colored"; $colored++; } } $i = 1; while($i <=MAX){ $j = 1; while($j <=MAX){ $temp = $j."_".$i; if(empty($board[$temp])){ $board[$temp] = "empty"; } $j++; } $i++; } ?> <html> <head> <style type="text/css"> td{ width: 48px; height: 40px; border-style: solid; } td.filled{ background-color: #0066CC; } tr.third{ border-style: double; } </style> </head> <body> <CENTER> <table width="600"> <?php $i = 1; while($i <=MAX){ if($i%3 == 0){ echo "<tr class=\"third\">\n"; } else{ echo "<tr>\n"; } $j = 1; while($j <=MAX){ $temp = $j."_".$i; if($board[$temp] == "colored"){ echo "<td class=\"filled\">".$temp."</td>"; } else{ echo "<td>".$temp."</td>"; } $j++; } echo "\n</tr>\n"; $i++; } ?> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 30, 2007 Author Share Posted July 30, 2007 I reworked it with a lot of while loops to get the 28 blocked out squares so to speak of <?php DEFINE("MAX", 9); $board = array(); $colored = 0; while($colored <=27){ $temp1 = rand(1,MAX); $temp2 = rand(1,MAX); $square = $temp1."_".$temp2; if(empty($board[$square])){ $board[$square] = "colored"; $colored++; } } $i = 1; while($i <=MAX){ $j = 1; while($j <=MAX){ $temp = $j."_".$i; if(empty($board[$temp])){ $board[$temp] = "empty"; } $j++; } $i++; } ?> <html> <head> <style type="text/css"> table.grid td{ width: 48px; height: 40px; border-style: solid; } td.filled{ background-color: #0066CC; } </style> </head> <body> <CENTER> <table width="600" cellspace="5"> <?php $x = 1; $y = 1; $rows = 1; while($rows <=3){ echo "<tr>"; $cols = 1; while($cols <=3){ echo "<td>\n<table class=\"grid\">\n"; $i = 1; while($i <=3){ echo "<tr>\n"; $j = 1; while($j <=3){ $temp = $x."_".$y; if($board[$temp] == "colored"){ echo "<td class=\"filled\">".$temp."</td>\n"; } else{ echo "<td>".$temp."</td>\n"; } $j++; if($x <9){$x++;} else{$x = 1;} } echo "</tr>\n"; $i++; if($y <9){$y++;} else{$y = 1;} } echo "</table>\n\n</td>"; $cols++; } echo "</tr>"; $rows++; } ?> </table> it echos a nice table with the 3x3 all there Quote Link to comment Share on other sites More sharing options...
tippy_102 Posted July 30, 2007 Share Posted July 30, 2007 FYI - there is a Sudoku programmers forum at http://www.setbb.com/phpbb/ Quote Link to comment Share on other sites More sharing options...
Humpty Posted July 30, 2007 Share Posted July 30, 2007 or this link even, it works: http://www.setbb.com/phpbb/?mforum=sudoku Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 30, 2007 Author Share Posted July 30, 2007 Thanks for that, I was kind of trying to write my own algorthims to make boards so that I can learn some stuff about it, but if i get stuck i'll go there. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.