[alicebot-style] Multiple choice quiz in AIML

John Campbell alicebot-style@list.alicebot.org
Fri, 08 Jul 2005 10:13:13 +0100


My technique is to use topic and a _ to catch everything.

As a multi choice test, it's not quite right, as you only proceed to the next question if the 
get the current one right!

I have tested it with Sylvie ( http://www.jesus.org.uk/bot ) on Pandorabots and it works.

Here you go:

<?xml version="1.0" encoding="ISO-8859-1"?>
<aiml>
<!-- Free software Copyright &copy; ALICE A.I. Foundation. -->
<!-- This program is open source code released under -->
<!-- the terms of the GNU General Public License     -->
<!-- as published by the Free Software Foundation.   -->
<!-- Complies with AIML 1.0.1 Tag Set Specification -->
<!-- as adopted by the ALICE A.I. Foundation.  -->
<!-- Annotated Version updated 8 July 2005 -->
<!-- Revision Multiple 0.04 -->

<category>
<pattern>MULTIPLE CHOICE TEST</pattern>
<template>
<think>
    <set name="topic">QUESTIONS</set>
</think>
<srai>QUESTION I</srai>
</template>
</category>

<category>
<pattern>QUESTION I</pattern>
<template>Who is the best robot? <br/>
A. R2D2.<br/>
B. ALICE.<br/>
C. HAL 9000.<br/>

<think>
    <set name="topic">
       QUESTION I 
    </set>
</think>
</template>
</category>

 
<topic name="QUESTION I"> 

<category> 
<template>
<pattern>_</pattern>
<think>
	<set name="star"><star /></set>
	<set name="topic">QUESTIONS</set>
</think>
<condition>
<li name="star" value="A">Wrong! Try again!<br /><srai>QUESTION I</srai> </li>
<li name="star" value="B">This is the correct answer!<br /><srai>QUESTION II</srai> </li>
<li name="star" value="C">Wrong! Try again!<br /><srai>QUESTION I</srai> </li>
<li>Please answer with just A, B or C. Try again!<br /><srai>QUESTION I</srai> </li>
</condition>
</template> 
</category> 

</topic> 

<category>
<pattern>QUESTION II</pattern>
<template>Who was the first president? <br/>
A. George Washington.<br/>
B. Thomas Jefferson.<br/>
C. George Bush.<br/>
<think>
    <set name="topic">
       QUESTION II 
    </set>
</think>
</template>
</category>

<topic name="QUESTION II"> 

<category> 
<pattern>_</pattern>
<template>
<think>
	<set name="star"><star /></set>
	<set name="topic">QUESTIONS</set>
</think>

<condition>
<li name="star" value="A">This is the correct answer!<br /><srai>QUESTION III</srai> </li>
<li name="star" value="B">Wrong! Try again!<br /><srai>QUESTION II</srai> </li>
<li name="star" value="C">Wrong! Try again!<br /><srai>QUESTION II</srai> </li>
<li>Please answer with just A, B or C. Try again!<br /><srai>QUESTION II</srai> </li>
</condition>
</template> 
</category> 
</topic>

<category>
<pattern>QUESTION III</pattern>
<template>What was the first state? <br/>
A. Virginia.<br/>
B. Pennsylvania.<br/>
C. Delaware.<br/>
<think>
    <set name="topic">
       QUESTION III 
    </set>
</think>
</template>
</category>

<topic name="QUESTION III"> 

<category> 
<pattern>_</pattern>
<template>
<think>
	<set name="star"><star /></set>
	<set name="topic">QUESTIONS</set>
</think>

<condition>
<li name="star" value="A">Wrong! Try again!<br /><srai>QUESTION III</srai> </li>
<li name="star" value="B">This is the correct answer!<br /><srai>QUIZ FINISHED</srai> </li>
<li name="star" value="C">Wrong! Try again!<br /><srai>QUESTION III</srai> </li>
<li>Please answer with A, B or C. Try again!<br /><srai>QUESTION III</srai> </li>
</condition>
</template> 
</category> 
</topic>

<category>
<pattern>QUIZ FINISHED</pattern>
<template>
<think>
	<set name="topic">QUESTIONS</set>
</think>
Congratulations, you have finished the quiz!
</template>
</category>
 
</aiml>


Regards

John Campbell

Sylvie on the web at http://www.jesus.org.uk/bot
Chat to Sylviebot on AIM