diff --git a/CHANGES.md b/CHANGES.md index 1552592..f95d2c5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +Changes in version 2016-03-03 (20160302) +------------------------------------------------------------------ +- New: Max compute time in crossword and cryptex + Changes in version 2016-02-14 (20160214) ------------------------------------------------------------------ - Fix syntax error (missed fullstop for concatenation) diff --git a/cross/cross_class.php b/cross/cross_class.php index 86206bc..fcc44d5 100755 --- a/cross/cross_class.php +++ b/cross/cross_class.php @@ -28,7 +28,7 @@ class Cross public $minputanswers; // Contains the words and the answers. public $mwords; // The words that will be used. - public $mtimelimit = 30; + public $mtimelimit = 3; // Computed by computenextcross. public $mbestcrosspos; // The best puzzle. @@ -119,7 +119,7 @@ class Cross } } - public function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords) { + public function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords, $mtimelimit=3) { $t1 = time(); $ctries = 0; @@ -129,6 +129,9 @@ class Cross $mbestn20 = 0; $nochange = 0; + $this->mtimelimit = $mtimelimit; + if( $this->mtimelimit == 30) + $this->mtimelimit = 27; for (;;) { // Selects the size of the cross. $n20 = mt_rand( $this->mn20min, $this->mn20max); @@ -139,7 +142,7 @@ class Cross $ctries++; - if (time() - $t1 > $this->mtimelimit - 3) { + if (time() - $t1 > $this->mtimelimit) { break; } @@ -202,9 +205,6 @@ class Cross } } } - if (time() - $t1 > $this->mtimelimit - 3) { - return false; - } } $nwords = count( $crossword); diff --git a/cross/play.php b/cross/play.php index ad3098b..547640f 100755 --- a/cross/play.php +++ b/cross/play.php @@ -80,7 +80,7 @@ function game_cross_new( $game, $attemptid, &$crossm) { // The game->param4 is minimum words in crossword. // The game->param2 is maximum words in crossword. - if ($cross->computedata( $crossm, $crossd, $lettets, $game->param4, $game->param2)) { + if ($cross->computedata( $crossm, $crossd, $lettets, $game->param4, $game->param2, $game->param8)) { $newcrossd = array(); foreach ($crossd as $rec) { $info = $infos[ $rec->answertext]; @@ -96,7 +96,7 @@ function game_cross_new( $game, $attemptid, &$crossm) { } if (count( $crossd) == 0) { - print_error( 'game_cross_continue: '.get_string( 'no_words', 'game')); + print_error( 'game_cross_continue: '.get_string( 'no_words', 'game').$game->id); } } diff --git a/cryptex/cryptexdb_class.php b/cryptex/cryptexdb_class.php index b64ce6f..111b6c3 100755 --- a/cryptex/cryptexdb_class.php +++ b/cryptex/cryptexdb_class.php @@ -208,8 +208,8 @@ class CryptexDB extends CrossDB { return Cross::setwords( $answers, $maxcols, $reps); } - public function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords) { - if (!cross::computedata( $crossm, $crossd, $letters, $minwords, $maxwords)) { + public function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords, $mtimelimit=3) { + if (!cross::computedata( $crossm, $crossd, $letters, $minwords, $maxwords, $mtimelimit)) { return false; } diff --git a/cryptex/play.php b/cryptex/play.php index 0d88e11..2a3e37b 100755 --- a/cryptex/play.php +++ b/cryptex/play.php @@ -76,7 +76,7 @@ function game_cryptex_continue( $id, $game, $attempt, $cryptexrec, $endofgame, $ // The game->param4 is minimum words. // The game->param2 is maximum words. - if ($cryptex->computedata( $crossm, $crossd, $letters, $game->param4, $game->param2)) { + if ($cryptex->computedata( $crossm, $crossd, $letters, $game->param4, $game->param2, $game->param3)) { $newcrossd = array(); foreach ($crossd as $rec) { if (array_key_exists( $rec->answertext, $infos)) { diff --git a/mod_form.php b/mod_form.php index 5a48e01..84441dd 100755 --- a/mod_form.php +++ b/mod_form.php @@ -259,6 +259,8 @@ class mod_game_mod_form extends moodleform_mod { $mform->addElement('select', 'param3', get_string('cross_layout', 'game'), $crosslayoutoptions); $mform->setType('param5', PARAM_INT); $mform->addElement('selectyesno', 'param6', get_string('cross_disabletransformuppercase', 'game')); + $mform->addElement('text', 'param8', get_string('cross_maxcomputetime', 'game')); + $mform->setType('param8', PARAM_INT); } // Cryptex options. @@ -273,6 +275,8 @@ class mod_game_mod_form extends moodleform_mod { $mform->addElement('selectyesno', 'param7', get_string('hangman_allowspaces', 'game')); $mform->addElement('text', 'param8', get_string('cryptex_maxtries', 'game')); $mform->setType('param8', PARAM_INT); + $mform->addElement('text', 'param3', get_string('cross_maxcomputetime', 'game')); + $mform->setType('param3', PARAM_INT); } // Millionaire options. @@ -450,7 +454,7 @@ class mod_game_mod_form extends moodleform_mod { if ($defaultvalues->param5 == null) { $defaultvalues->param5 = 1; } - } + } if ($defaultvalues->gamekind == 'snakes') { if (isset( $defaultvalues->param9)) { @@ -483,6 +487,14 @@ class mod_game_mod_form extends moodleform_mod { $defaultvalues->snakes_footery = $rec->footery; } } + } else if ($defaultvalues->gamekind == 'cross') { + if (!isset( $defaultvalues->param8)) { + $defaultvalues->param8 = 2; + } + } else if ($defaultvalues->gamekind == 'cryptex') { + if (!isset( $defaultvalues->param3)) { + $defaultvalues->param3 = 2; + } } parent::set_data($defaultvalues); diff --git a/version.php b/version.php index 2be7f87..bd599c4 100755 --- a/version.php +++ b/version.php @@ -36,10 +36,10 @@ if (!isset( $plugin)) { } $plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics). -$plugin->version = 2016021401; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2016030201; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2010112400; // Requires Moodle 2.0. $plugin->cron = 0; // Period for cron to check this module (secs). -$plugin->release = '2016-02-14'; +$plugin->release = '2016-03-02'; if ($useplugin != 2) { $module = $plugin;