partly managing difficulty

master
Fabien Benetou 14 years ago
parent 03c37db619
commit deee57aa01
  1. 36
      pmwiki_recipes/exercises.php

@ -23,14 +23,16 @@ SDV($HandleAuth['Exercises'],'read');
function Exercises($pagename, $auth){
$type = $_GET["type"];
$counter = (int) $_GET["counter"];
$difficulty = (int) $_GET["difficulty"];
list($group,$page) = explode(".",$pagename);
$availableexercisetypes = array("pagelink", "expressioninpage");
$availableexercisetypes = array("pagelink", "expressioninpage", "pagehasexpression");
if ($type=="random")
$type= $availableexercisetypes[rand(0,count($availableexercisetypes)-1)];
switch ($type){
case "pagelink":
list($group,$page) = explode(".",$pagename);
// the pattern should be improve, e.g. remove PmWiki. , RecentChanges, GroupFooter, GroupHeader, Template, ...
if ($group == "AllPages"){
// equivalent to getting ALL pages
@ -53,27 +55,31 @@ function Exercises($pagename, $auth){
//consider pilling up potential in $answers[]
//randomly pick a page amongst the linked pages
$pageA = $links_array[rand(0,count($links_array)-1)];
$answers[] = $links_array[rand(0,count($links_array)-1)];
unset($pages[array_search($pageA,$links_array)]);
unset($pages[array_search($pageA,$pages)]);
//randomly pick 2 others pages which are not amongst the list of linked page
$pageB = $pages[rand(0,count($pages)-1)];
unset($pages[array_search($pageB,$pages)]);
$pageC = $pages[rand(0,count($pages)-1)];
unset($pages[array_search($pageC,$pages)]);
unset($pages[array_search($answers[0],$links_array)]);
unset($pages[array_search($answers[0],$pages)]);
//randomly pick n-1 others pages which may not be amongst the list of linked page
// n should be based on $difficulty, e.g. n=2+$difficulty or n=2^$difficulty
$n=3;
for ($i=1;$i<$n;$i++) {
$answers[] = $pages[rand(0,count($pages)-1)];
unset($pages[array_search($answers[$i],$pages)]);
}
//display
$result .="Is page [[$sourcepage]] linked to ";
$counter = (int) $_GET["counter"];
$counterparam = "";
if ( $counter > 0) {
$counterparam = "counter=$counter&";
}
$answers = array ($pageA,$pageB,$pageC);
// there should now be at least 1 needle in the haystack, the first one
// note that there might be more but this is not a problem as long as the question is stated clearly.
shuffle($answers);
for ($i=0;$i<count($answers);$i++) {
if ($answers[$i] != "") {
if ( $i == count($answers) -1 )
@ -92,9 +98,13 @@ function Exercises($pagename, $auth){
$result .="? ";
$result .="\n\nClick on the answer.";
break;
case "pagehasexpression":
// explode content by line "%0a" or word " "
$result .= "Does the page 'PAGE' has expression 'EXPRESSIONA', 'EXPRESSIONB' or 'EXPRESSIONC?";
break;
case "expressioninpage":
// explode content by line "%0a" or word " "
$result .= "Does the expression 'EXPRESSION' come from PAGEA PAGEB or PAGEC?";
$result .= "Does the expression 'EXPRESSION' come from PAGEA, PAGEB or PAGEC?";
break;
default:
$result .= "Exercise type unknown.";

Loading…
Cancel
Save