Revision: 3818 http://vexi.svn.sourceforge.net/vexi/?rev=3818&view=rev Author: clrg Date: 2010-03-19 02:17:25 +0000 (Fri, 19 Mar 2010)
Log Message: ----------- Fix board randomization Modified Paths: -------------- trunk/xtra/org.vexi.simplysudoku/src/org/vexi/simplysudoku/board.t trunk/xtra/org.vexi.simplysudoku/src/org/vexi/simplysudoku/simple.t Modified: trunk/xtra/org.vexi.simplysudoku/src/org/vexi/simplysudoku/board.t =================================================================== --- trunk/xtra/org.vexi.simplysudoku/src/org/vexi/simplysudoku/board.t 2010-03-12 14:28:04 UTC (rev 3817) +++ trunk/xtra/org.vexi.simplysudoku/src/org/vexi/simplysudoku/board.t 2010-03-19 02:17:25 UTC (rev 3818) @@ -165,8 +165,9 @@ /** okay I implemented board generation and board * layout differently, so sue me, bad programmer */ + var floor = vexi.math.floor; var getSq = function(row, col) { - var i = 3*vexi.math.floor(row/3) + vexi.math.floor(col/3); + var i = 3*floor(row/3) + floor(col/3); var j = 3*(row%3) + col%3; return $sectors[i][j]; } Modified: trunk/xtra/org.vexi.simplysudoku/src/org/vexi/simplysudoku/simple.t =================================================================== --- trunk/xtra/org.vexi.simplysudoku/src/org/vexi/simplysudoku/simple.t 2010-03-12 14:28:04 UTC (rev 3817) +++ trunk/xtra/org.vexi.simplysudoku/src/org/vexi/simplysudoku/simple.t 2010-03-19 02:17:25 UTC (rev 3818) @@ -6,13 +6,14 @@ <notes> This is a very simple generation algorithm that is based on some basic principles - manipulations that always maintain - the integrity a the sudoku board. Starting with a common + the integrity of the sudoku board. Starting with a common starter board, we can swap any row with another row in its 3-set (so rows 1-3, 4-6, and 7-9 are swappable) and any column in its 3-set. Then we can swap any 3-set-row with another, and the same for columns, and we have a new grid. - Note that this limits us to 3!^8 final solutions. + Note that this limits us to 3!^8 permutations and fewer + final solutions (there'll be duplicates!). For illustrations and inspiration for this, see here: http://blog.forret.com/2006/08/a-sudoku-challenge-generator/ @@ -96,6 +97,20 @@ vexi.trace("==========================="); } + /** generation is done using a seed, where the seed + * is an 8 digit number: + * - 1st-3rd numbers determine what column swap to perform + * in the 3 sector columns + * - 4th-6th numbers determine what row swap to perform + * in the 3 sector rows + * - 7th number determines the sector column swap + * - 8th number determines the sector row swap + * + * for a triplet set (i.e. 3 columns or 3 sector columns) + * a seed number represents the 6 possible permutations + * of those columns: + * a,b,c a,c,b b,a,c b,c,a c,a,b c,b,a + */ var generate = function() { for (var i=0; 8>i; i++) { var off = 6>i ? 3*(i%3) : 0; @@ -107,24 +122,24 @@ 7>i ? swapRowSet : swapColSet; switch (seed.charAt(i)) { case "1": - // leave as is + // leave as is; a,b,c break; case "2": - swapf(b, c); + swapf(b, c); // a,c,b break; case "3": - swapf(a, b); + swapf(a, b); // b,a,c break; case "4": - swapf(a, b); - swapf(a, c); + swapf(a, b); // b,a,c => + swapf(b, c); // b,c,a break; case "5": - swapf(a, c); + swapf(a, c); // c,b,a => + swapf(b, c); // c,a,b break; - case "6": - swapf(a, c); - swapf(a, b); + case "6": + swapf(a, c); // c,b,a break; default: throw new vexi.js.Exception("Should not happen"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn