Making The Game – Teil 14: Wissensbasis und Fragenauswahl / Arbeiten mit XML

xml

The knowledge- or question-base is at the heart of the program. Here are all questions and answers listed by category. Because it should not be required to create audio files for each of these databases, the first lines of the XML file tells the program if the questions are read aloud in the game or only appear textually.

 

  1.  <CATALOG>
  2.     <BASICSETTINGS>
  3.         <ITEM name=“audio”>trueITEM>
  4.     BASICSETTINGS>
  5.  

 

(Note: The application and the decision to record all audio parts manually now are six months old. If I would create this app now, I would try a different approach and fall back to a TTS-API, such as the unofficial Google TTS-API.)

 

Each question in the catalog is marked by a unique identification number. Whith the ID the question could be accessed directly in an authoring tool. She is also an indicator how many questions already have been created in a category.

 

The possible number of points for the question reflects the difficulty. The lowest value that can be given for a question is 1000 points, which corresponds to the players level 1. Higher levels are valued with 2000, 3000, … Points. There is no upper limit at the points classification but it should be avoided to create questions higher than 4000 points, as the player loses points from incorrect answers, which could quickly lead to high levels of frustration.
The most important entities in the XML file are the question, the answers and the number of the correct answer. It includes the question text, which appears in the animated program, and the four possible answers.

 

  1.  <CATEGORY name=“Das Internet? Gibts den Blödsinn immer noch?”>
  2.  <CATEGORYAUDIO>
  3.     <ITEM name=“category”>catalog/cat/cat7.mp3ITEM>
  4.  CATEGORYAUDIO>
  5.  
  6.  …
  7.  <QUESTION id=“3”>
  8.      <ITEM name=“points”>2000ITEM>
  9.      <ITEM name=“text”>Wie nennt man die Pauschalgebühr für eine
  10.                         Internet oder Telefonverbindung?ITEM>
  11.      <ITEM name=“a1”>OverrateITEM>
  12.      <ITEM name=“a2”>ConnectionrateITEM>
  13.      <ITEM name=“a3”>FlatrateITEM>
  14.      <ITEM name=“a4”>FreiminutenITEM>
  15.      <ITEM name=“correct”>3ITEM>
  16.      <AUDIOFILES>
  17.         <ITEM name=“pretalk”>ITEM>
  18.         <ITEM name=“text”>catalog/ID005/q_3_0.mp3ITEM>
  19.         <ITEM name=“a1”>catalog/ID005/q_3_1.mp3ITEM>    
  20.         <ITEM name=“a2”>catalog/ID005/q_3_2.mp3ITEM>
  21.         <ITEM name=“a3”>catalog/ID005/q_3_3.mp3ITEM>
  22.         <ITEM name=“a4”>catalog/ID005/q_3_4.mp3ITEM>    
  23.         <ITEM name=“correct”>catalog/ID005/q_3_5.mp3ITEM>
  24.      AUDIOFILES>
  25.  QUESTION>  
  26.  …

 

As seen in the extract from the general knowledge database, the linking of the individual audio components is a large part of the structure.
(Note: And actually, I should have used a fixed convention to determine how the files are named so that thay could automatically, so that I could call them without entry in the XML-file … -.-)

 

The name of the individual audio items correspond to the textual parts, so it is easy to see which sound file corresponds to a text section.
The only exceptions to this are the entries “pretalk” and “correct”. The recording tells the information of the “correct” entry, but also gives an expanded explanation of why the answer is correct. In the game the audio is played, once the solution of the answer appears.
By using the “pretalk” entry the lead author of the questionnaire can add a brief description of the actual question to set the scene. The entry is optional and must not be used.

 

The random selection of a question during the game is done automatically by calling the function selectQuestion() (see code below). This verifies if a game is played at the moment or whether it is requested outside of the game, which happens for example in the training mode. Is a game round currently in progress, the current player level for subsequent validation checks is taken.

 

From a random category a random question is taken. To ensure that the question is in the range of player level it is checked against the current level value. In the next instance it is determined whether the ID is part of the list of already asked questions.
Is the question outside the player levels, or was it already called ​ a new question will be selected at random. This process is repeated until a question has been found that satisfies both conditions.

 

  1.  function selectQuestion():XML{
  2.     var lvl:int = 999;
  3.     // get current player level if we are in a match
  4.     if(questionNumber>0){
  5.         lvl = game_level;
  6.     }
  7.    
  8.     var categorySelected:int;
  9.     var questionSelected:int;
  10.     var simpleCounter:int = 0;
  11.    
  12.     do {
  13.         simpleCounter++;
  14.    
  15.         // GET NUMBER OF CATEGORIES
  16.         var categoryAmmount:int = basicXMLCatalog.CATEGORY.length();
  17.  
  18.         // select one category randomly
  19.         categorySelected = randomNumber(1,categoryAmmount);
  20.        
  21.         // GET NUMBER OF QUESTIONS IN THE CATEGORY
  22.         var questionAmmount:int =
  23.              basicXMLCatalog.CATEGORY[categorySelected1].
  24.              QUESTION.length();
  25.  
  26.         // select one question randomly
  27.         questionSelected = randomNumber(1, questionAmmount);
  28.        
  29.         // check if the question is in the current level-range
  30.         var possiblePoints =
  31.                 basicXMLCatalog.CATEGORY[categorySelected1].
  32.                 QUESTION[questionSelected1].ITEM.(@name==“points”);
  33.         var outOfRange:Boolean = true;
  34.         if(possiblePoints <= lvl*1000){ outOfRange = false; }
  35.        
  36.         // check if the question was already asked
  37.         // if indexOf == -1 –> not asked
  38.         var alreadyAsked:Boolean = true;
  39.         if((questionIDStore.indexOf(categorySelected +
  40.             “-“ + questionSelected)) < 0){
  41.             alreadyAsked = false;
  42.         }
  43.        
  44.         // failsafe… no questions… go out of level-range
  45.         if(simpleCounter > 20){ outOfRange = false; }
  46.        
  47.         // failsafe #2… just ask a question again
  48.         if(simpleCounter > 40){ alreadyAsked = false; }
  49.        
  50.     // search until the question was not already asked
  51.     } while (outOfRange || alreadyAsked);
  52.  
  53.     // at this point we have a question selected!
  54.     // save the question ID – we dont want to ask it again
  55.     questionIDStore.push(categorySelected + “-“ + questionSelected);
  56.  
  57.     // save the question data
  58.     question_currentXML =
  59.              basicXMLCatalog.CATEGORY[categorySelected1].
  60.              QUESTION[questionSelected1];
  61.  
  62.     // return the xml-data
  63.     return question_currentXML;
  64.  }

 

As it can not be ensured by the program that sufficient questions are stored in the knowledge base, an emergency strategy must be selected. Thus, to find after twenty fruitless passes, an appropriate question outside of the player’s levelis chosen.
If no question could be found for another twenty runs also questions, which were already asked, were also allowed again. This will ensure that the game could be played through with badly created knowledge bases.

 
If a question has been chosen and it is rated as suitable, its ID is added to the list of asked questions, all relevant data is read from the XML file, and cached for future use.

 
 
 

Upcoming blog entries
Making The Game – Part 15: Game stages
Making The Game – Part 16: Mini-Games
Making The Game – Part 17: Evaluation and deployment of the application
Making The Game – Part 18: Concept for school use and outlook

 
 
 

Leave a Reply