From 6a117da888202d2abdb2e32c5e490a78755c4b4d Mon Sep 17 00:00:00 2001 From: bdaloukas Date: Sat, 13 Jul 2013 13:18:13 +0300 Subject: [PATCH] New: Cross,Cryptex can set the minimum number of words that a cross/cryptex can have --- cross/cross_class.php | 17 ++++++++++++----- cross/play.php | 3 ++- cryptex/cryptexdb_class.php | 4 ++-- cryptex/play.php | 4 +++- lang/en/game.php | 9 ++++----- mod_form.php | 8 ++++++-- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/cross/cross_class.php b/cross/cross_class.php index 5c968db..fc1c738 100755 --- a/cross/cross_class.php +++ b/cross/cross_class.php @@ -105,7 +105,7 @@ class Cross } } - function computedata( &$crossm, &$crossd, &$letters, $maxwords) + function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords) { $t1 = time(); @@ -121,9 +121,9 @@ class Cross //selects the size of the cross $N20 = mt_rand( $this->m_N20min, $this->m_N20max); - if( !$this->computenextcross( $N20, $t1, $ctries, $maxwords, $nochange)) + if( !$this->computenextcross( $N20, $t1, $ctries, $minwords, $maxwords, $nochange)) break; - + $ctries++; if (time() - $t1 > $this->m_time_limit - 3){ @@ -140,7 +140,7 @@ class Cross return $this->savepuzzle( $crossm, $crossd, $ctries, time()-$t1); } - function computenextcross( $N20, $t1, $ctries, $maxwords, &$nochange) + function computenextcross( $N20, $t1, $ctries, $minwords, $maxwords, &$nochange) { $MAXW = $N20; @@ -186,7 +186,8 @@ class Cross if ($this->scan_pos($p[0], $p[1], false, $puzzle, $words, $magics, $poss, $cross_pos, $cross_dir, $cross_word, $N20)){ $n_words = count( $cross_word); - if( $maxwords){ + if( $maxwords) + { if( $n_words >= $maxwords){ break; } @@ -198,6 +199,12 @@ class Cross } $n_words = count( $cross_word); + if( $minwords) + { + if( $n_words < $minwords) + return true; + } + $score = $this->computescore( $puzzle, $N20, $N22, $N2222, $n_words, $n_connectors, $n_filleds, $cSpaces, $cross_word); if ($score > $this->m_best_score) diff --git a/cross/play.php b/cross/play.php index c669ebb..fcf743f 100755 --- a/cross/play.php +++ b/cross/play.php @@ -62,8 +62,9 @@ function game_cross_new( $game, $attemptid, &$crossm) $cross->setwords( $answers, $game->param1, $reps); + //game->param4 is minimum words in crossword //game->param2 is maximum words in crossword - if( $cross->computedata( $crossm, $crossd, $lettets, $game->param2)){ + if( $cross->computedata( $crossm, $crossd, $lettets, $game->param4, $game->param2)){ $new_crossd = array(); foreach( $crossd as $rec) { diff --git a/cryptex/cryptexdb_class.php b/cryptex/cryptexdb_class.php index d2d3ea4..dbee26f 100755 --- a/cryptex/cryptexdb_class.php +++ b/cryptex/cryptexdb_class.php @@ -214,9 +214,9 @@ class CryptexDB extends CrossDB return Cross::setwords( $answers, $maxcols, $reps); } - function computedata( &$crossm, &$crossd, &$letters, $maxwords) + function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords) { - if( !cross::computedata( $crossm, $crossd, $letters, $maxwords)){ + if( !cross::computedata( $crossm, $crossd, $letters, $minwords, $maxwords)){ return false; } diff --git a/cryptex/play.php b/cryptex/play.php index 7603957..842f715 100755 --- a/cryptex/play.php +++ b/cryptex/play.php @@ -59,7 +59,9 @@ function game_cryptex_continue( $id, $game, $attempt, $cryptexrec, $endofgame, $ $cryptex->setwords( $answers, $game->param1, $reps); - if( $cryptex->computedata( $crossm, $crossd, $letters, $game->param2)){ + //game->param4 is minimum words + //game->param2 is maximum words + if( $cryptex->computedata( $crossm, $crossd, $letters, $game->param4, $game->param2)){ $new_crossd = array(); foreach( $crossd as $rec) { diff --git a/lang/en/game.php b/lang/en/game.php index bad1784..0db7ba5 100755 --- a/lang/en/game.php +++ b/lang/en/game.php @@ -209,13 +209,12 @@ $string[ 'bottomtext'] = 'Text at the bottom of page'; $string[ 'cross_layout'] = 'Layout'; $string[ 'cross_layout0'] = 'Phrases on the bottom of cross'; $string[ 'cross_layout1'] = 'Phrases on the right of cross'; -$string[ 'cross_maxcols'] = 'Maximum number of cols of crossword'; -$string[ 'cross_maxwords'] = 'Maximum number of words of crossword'; +$string[ 'cross_maxcols'] = 'Maximum number of cols/rows'; +$string[ 'cross_maxwords'] = 'Maximum number of words'; +$string[ 'cross_minwords'] = 'Minimum number of words'; $string[ 'cross_options'] = 'Crossword options'; -$string[ 'cryptex_maxcols'] = 'Maximum number of cols/rows in cryptex'; $string[ 'cryptex_maxtries'] = 'Max tries'; -$string[ 'cryptex_maxwords'] = 'Maximum number of words in cryptex'; -$string[ 'cryptex_options'] = 'Cryptex ofptions'; +$string[ 'cryptex_options'] = 'Cryptex options'; $string[ 'gameclose'] = 'Close the game'; $string[ 'gameopen'] = 'Open the game'; $string[ 'grademethod'] = 'Grading method'; diff --git a/mod_form.php b/mod_form.php index 7f1cf43..f74c26d 100755 --- a/mod_form.php +++ b/mod_form.php @@ -224,6 +224,8 @@ class mod_game_mod_form extends moodleform_mod { $mform->addElement('header', 'cross', get_string( 'cross_options', 'game')); $mform->addElement('text', 'param1', get_string('cross_maxcols', 'game')); $mform->setType('param1', PARAM_INT); + $mform->addElement('text', 'param4', get_string('cross_minwords', 'game')); + $mform->setType('param4', PARAM_INT); $mform->addElement('text', 'param2', get_string('cross_maxwords', 'game')); $mform->setType('param2', PARAM_INT); $mform->addElement('selectyesno', 'param7', get_string('hangman_allowspaces','game')); @@ -238,9 +240,11 @@ class mod_game_mod_form extends moodleform_mod { if($gamekind == 'cryptex'){ $mform->addElement('header', 'cryptex', get_string( 'cryptex_options', 'game')); - $mform->addElement('text', 'param1', get_string('cryptex_maxcols', 'game')); + $mform->addElement('text', 'param1', get_string('cross_maxcols', 'game')); $mform->setType('param1', PARAM_INT); - $mform->addElement('text', 'param2', get_string('cryptex_maxwords', 'game')); + $mform->addElement('text', 'param4', get_string('cross_minwords', 'game')); + $mform->setType('param4', PARAM_INT); + $mform->addElement('text', 'param2', get_string('cross_maxwords', 'game')); $mform->setType('param2', PARAM_INT); $mform->addElement('selectyesno', 'param7', get_string('hangman_allowspaces','game')); $mform->addElement('text', 'param8', get_string('cryptex_maxtries','game'));