:

data = PackSudoku( $si, $sp); if( strlen( $newrec->data) != 81){ return 0; } $newrec->level = $level; $newrec->opened = GetOpened( $si); insert_record( "game_sudoku_database", $newrec, true); $level++; if( $level > $level2){ $level = $level1; } echo get_string( 'sudoku_creating', 'game', $i)."
\r\n"; } } function PackSudoku( $si, $sp) { $data = ""; for ($i = 1; $i <= 9; $i++) { for ($j = 1; $j <= 9; $j++) { $c = &$sp->theSquares[$i]; $c = &$c->getCell($j) ; $solution = $c->asString( false); $c = &$si->theSquares[$i] ; $c = &$c->getCell($j) ; $theSolvedState = $c->solvedState() ; if( $theSolvedState == 1) { //hint $solution = substr( "ABCDEFGHI", $c->asString( false) - 1, 1); } $data .= $solution; } } return $data; } function create( &$si, &$sp, $level=1) { for( $i=1; $i <= 40; $i++) { set_time_limit( 30); $sp = new Sudoku() ; $theInitialPosition = $sp->generatePuzzle( 10, 50, $level) ; if( count( $theInitialPosition)){ break; } } if( $i > 40){ return false; } $si = new Sudoku() ; $si->initializePuzzleFromArray($theInitialPosition); //$si->printSolution(); //$sp->printSolution(); return true; } function GetOpened( $si) { $count = 0; for ($i = 1; $i <= 9; $i++) { for ($j = 1; $j <= 9; $j++) { $c = &$si->theSquares[$i] ; $c = &$c->getCell($j) ; $theSolvedState = $c->solvedState() ; if( $theSolvedState == 1) //hint $count++; } } return $count; }