Browse Source

New: Max compute time in crossword and cryptex

MOODLE_20_STABLE
Vasilis Daloukas 9 years ago
parent
commit
8c2daeafea
  1. 4
      CHANGES.md
  2. 12
      cross/cross_class.php
  3. 4
      cross/play.php
  4. 4
      cryptex/cryptexdb_class.php
  5. 2
      cryptex/play.php
  6. 14
      mod_form.php
  7. 4
      version.php

4
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) Changes in version 2016-02-14 (20160214)
------------------------------------------------------------------ ------------------------------------------------------------------
- Fix syntax error (missed fullstop for concatenation) - Fix syntax error (missed fullstop for concatenation)

12
cross/cross_class.php

@ -28,7 +28,7 @@ class Cross
public $minputanswers; // Contains the words and the answers. public $minputanswers; // Contains the words and the answers.
public $mwords; // The words that will be used. public $mwords; // The words that will be used.
public $mtimelimit = 30; public $mtimelimit = 3;
// Computed by computenextcross. // Computed by computenextcross.
public $mbestcrosspos; // The best puzzle. 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(); $t1 = time();
$ctries = 0; $ctries = 0;
@ -129,6 +129,9 @@ class Cross
$mbestn20 = 0; $mbestn20 = 0;
$nochange = 0; $nochange = 0;
$this->mtimelimit = $mtimelimit;
if( $this->mtimelimit == 30)
$this->mtimelimit = 27;
for (;;) { for (;;) {
// Selects the size of the cross. // Selects the size of the cross.
$n20 = mt_rand( $this->mn20min, $this->mn20max); $n20 = mt_rand( $this->mn20min, $this->mn20max);
@ -139,7 +142,7 @@ class Cross
$ctries++; $ctries++;
if (time() - $t1 > $this->mtimelimit - 3) { if (time() - $t1 > $this->mtimelimit) {
break; break;
} }
@ -202,9 +205,6 @@ class Cross
} }
} }
} }
if (time() - $t1 > $this->mtimelimit - 3) {
return false;
}
} }
$nwords = count( $crossword); $nwords = count( $crossword);

4
cross/play.php

@ -80,7 +80,7 @@ function game_cross_new( $game, $attemptid, &$crossm) {
// The game->param4 is minimum words in crossword. // The game->param4 is minimum words in crossword.
// The game->param2 is maximum 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(); $newcrossd = array();
foreach ($crossd as $rec) { foreach ($crossd as $rec) {
$info = $infos[ $rec->answertext]; $info = $infos[ $rec->answertext];
@ -96,7 +96,7 @@ function game_cross_new( $game, $attemptid, &$crossm) {
} }
if (count( $crossd) == 0) { 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);
} }
} }

4
cryptex/cryptexdb_class.php

@ -208,8 +208,8 @@ class CryptexDB extends CrossDB {
return Cross::setwords( $answers, $maxcols, $reps); return Cross::setwords( $answers, $maxcols, $reps);
} }
public function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords) { public function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords, $mtimelimit=3) {
if (!cross::computedata( $crossm, $crossd, $letters, $minwords, $maxwords)) { if (!cross::computedata( $crossm, $crossd, $letters, $minwords, $maxwords, $mtimelimit)) {
return false; return false;
} }

2
cryptex/play.php

@ -76,7 +76,7 @@ function game_cryptex_continue( $id, $game, $attempt, $cryptexrec, $endofgame, $
// The game->param4 is minimum words. // The game->param4 is minimum words.
// The game->param2 is maximum 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(); $newcrossd = array();
foreach ($crossd as $rec) { foreach ($crossd as $rec) {
if (array_key_exists( $rec->answertext, $infos)) { if (array_key_exists( $rec->answertext, $infos)) {

14
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->addElement('select', 'param3', get_string('cross_layout', 'game'), $crosslayoutoptions);
$mform->setType('param5', PARAM_INT); $mform->setType('param5', PARAM_INT);
$mform->addElement('selectyesno', 'param6', get_string('cross_disabletransformuppercase', 'game')); $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. // 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('selectyesno', 'param7', get_string('hangman_allowspaces', 'game'));
$mform->addElement('text', 'param8', get_string('cryptex_maxtries', 'game')); $mform->addElement('text', 'param8', get_string('cryptex_maxtries', 'game'));
$mform->setType('param8', PARAM_INT); $mform->setType('param8', PARAM_INT);
$mform->addElement('text', 'param3', get_string('cross_maxcomputetime', 'game'));
$mform->setType('param3', PARAM_INT);
} }
// Millionaire options. // Millionaire options.
@ -450,7 +454,7 @@ class mod_game_mod_form extends moodleform_mod {
if ($defaultvalues->param5 == null) { if ($defaultvalues->param5 == null) {
$defaultvalues->param5 = 1; $defaultvalues->param5 = 1;
} }
} }
if ($defaultvalues->gamekind == 'snakes') { if ($defaultvalues->gamekind == 'snakes') {
if (isset( $defaultvalues->param9)) { if (isset( $defaultvalues->param9)) {
@ -483,6 +487,14 @@ class mod_game_mod_form extends moodleform_mod {
$defaultvalues->snakes_footery = $rec->footery; $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); parent::set_data($defaultvalues);

4
version.php

@ -36,10 +36,10 @@ if (!isset( $plugin)) {
} }
$plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics). $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->requires = 2010112400; // Requires Moodle 2.0.
$plugin->cron = 0; // Period for cron to check this module (secs). $plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->release = '2016-02-14'; $plugin->release = '2016-03-02';
if ($useplugin != 2) { if ($useplugin != 2) {
$module = $plugin; $module = $plugin;

Loading…
Cancel
Save