function updatecrossquestions(&$rec, &$g, &$pos, &$correctletters, &$wrongletters, &$restletters, $game, $attempt, $crossrec)
 {
     global $DB, $USER;
     $textlib = textlib_get_instance();
     $word = $rec->answertext;
     $len = $textlib->strlen($word);
     $guess = $textlib->substr($g, $pos, $len);
     $len_guess = $textlib->strlen($guess);
     $pos += $len;
     $is_empty = true;
     for ($i = 0; $i < $len; $i++) {
         if ($i < $len_guess) {
             $letterguess = $textlib->substr($guess, $i, 1);
         } else {
             $letterguess = " ";
         }
         if ($letterguess != ' ') {
             $is_empty = false;
         }
         $letterword = $textlib->substr($word, $i, 1);
         if ($letterword != $letterguess) {
             if ($letterguess != ' ' and $letterguess != '_' or $letterword == ' ') {
                 $wrongletters++;
             }
             game_setchar($guess, $i, '_');
             $restletters++;
         } else {
             if ($letterguess == ' ') {
                 if ($guess == $word) {
                     $correctletters++;
                 } else {
                     $wrongletters++;
                     game_setchar($guess, $i, '_');
                 }
             } else {
                 $correctletters++;
             }
         }
     }
     if ($is_empty) {
         return;
     }
     if ($rec->studentanswer == $guess) {
         return;
     }
     $rec->studentanswer = $guess;
     $updrec->studentanswer = $guess;
     $updrec->id = $rec->id;
     if (!$DB->update_record('game_queries', $updrec, $rec->id)) {
         print_error('Update game_queries: not updated');
     }
     $score = $correctletters / $len;
     game_update_queries($game, $attempt, $rec, $score, $guess);
 }
 function load($crossm, &$mask, &$corrects, &$language)
 {
     global $DB;
     $textlib = textlib_get_instance();
     $questions = array();
     $corrects = array();
     $mask = str_repeat('0', $crossm->cols * $crossm->rows);
     if ($recs = $DB->get_records('game_queries', array('attemptid' => $crossm->id))) {
         foreach ($recs as $rec) {
             if ($rec->questiontext == '') {
                 $rec->questiontext = ' ';
             }
             $key = $this->gethash($rec->questiontext) . '-' . $rec->answertext . '-' . $rec->id;
             $questions[$key] = $rec;
             $word = $rec->answertext;
             $pos = $crossm->cols * ($rec->row - 1) + ($rec->col - 1);
             $len = $textlib->strlen($word);
             $found = $rec->answertext == $rec->studentanswer;
             for ($i = 0; $i < $len; $i++) {
                 $c = $found ? '1' : '2';
                 if ($textlib->substr($mask, $pos, 1) != '1') {
                     game_setchar($mask, $pos, $c);
                 }
                 $pos += $rec->horizontal ? 1 : $crossm->cols;
             }
             if ($found) {
                 $corrects[$rec->id] = 1;
             }
             if ($language == '') {
                 $language = game_detectlanguage($rec->answertext);
             }
         }
         ksort($questions);
     }
     return $questions;
 }
function game_sudoku_check_number($id, $game, $attempt, $sudoku, $pos, $num, $context)
{
    global $DB;
    $correct = game_substr($sudoku->data, $pos - 1, 1);
    if ($correct != $num) {
        game_sudoku_play($id, $game, $attempt, $sudoku, false, false, $context);
        return;
    }
    $leng = game_strlen($sudoku->guess);
    $lend = game_strlen($sudoku->data);
    if ($leng < $lend) {
        $sudoku->guess .= str_repeat(' ', $lend - $leng);
    }
    game_setchar($sudoku->guess, $pos - 1, $correct);
    if (!$DB->set_field_select('game_sudoku', 'guess', $sudoku->guess, "id={$sudoku->id}")) {
        print_error('game_sudoku_check_number: Cannot update table game_sudoku');
    }
    game_sudoku_play($id, $game, $attempt, $sudoku, false, false, $context);
}
function game_sudoku_check_number($id, $game, $attempt, $sudoku, $pos, $num)
{
    $textlib = textlib_get_instance();
    $correct = $textlib->substr($sudoku->data, $pos - 1, 1);
    if ($correct != $num) {
        game_sudoku_play($id, $game, $attempt, $sudoku);
        return;
    }
    $leng = $textlib->strlen($sudoku->guess);
    $lend = $textlib->strlen($sudoku->data);
    if ($leng < $lend) {
        $sudoku->guess .= str_repeat(' ', $lend - $leng);
    }
    game_setchar($sudoku->guess, $pos - 1, $correct);
    if (!set_field_select('game_sudoku', 'guess', $sudoku->guess, "id={$sudoku->id}")) {
        error('game_sudoku_check_number: Cannot update table game_sudoku');
    }
    game_sudoku_play($id, $game, $attempt, $sudoku);
}