Monthly Archives: April 2012

Android : Radiology Quiz

Part 3 of series on gamification of a dataset.

Part 1 Part 2

A randomized multiple choice quiz which tests the players knowledge of different relationships from the RadLex Ontology.

Download and play for free on GooglePlay

https://play.google.com/store/apps/details?id=MantasCode.RadQuiz

Relationship sets used:

{“anatomical_site”, “blood_supply_of”, “branch_of”, “constitutional_part_of”, “contained_in”, “contains”, “drains_into”, “has_blood_supply”, “has_branch”, “has_constitutional_part”, “has_innervation_source”, “has_member”, “lymphatic_drainage_of”, “member_of”, “projects_from”, “projects_to”, “receives_drainage_from”, “receives_input_from”, “receives_projection_from”, “related_condition”, “related_modality”, “segment_of”, “sends_output_to”};

^ each one of these sets is the same as the Character to Location set from Part 1. However, these are much larger.

over 12,000 questions .

update:

Added count down timer, added correct answer display if incorrect answer chosen, reformatted button layouts, changed some colors, and added some annoying sounds  XD

 

Android: Gamification of a DataSET / Part 2

I have turned the previous post Java: LOL!: Gamification of a DataSET into an Android Application.  This example project will show you how to gamify a simple multiple choice quiz in order to engage the user more.

Free download this example app can be found on GooglePlay.

https://play.google.com/store/apps/details?id=Quizer.Quiz

Game Mechanics and Rewards/Risks:

The player gets asked a random question from the dataset and is presented with a multiple choice of 4 answers.   The correct answer will reward the him/her with a banana (+).  If the player chooses wrong he will lose a banana (-) or even go into banana debt.  The banana is an ongoing indicator of status.  If the player accumulates  more then 20 bananas he will unlock this:  (its a sushi roll).  Also, there’s gooseberries.  For every 10 correct answers the player will get 1 gooseberry .

Continue reading

Java: LOL!: Gamification of a DataSET :D

Randomized multiple choice quiz of the relationship sets of Fallout 2 Characters and their Locations.

(Character (is from/is related to) Location)
(Concept 1 -> Relationship -> Concept 2)
Example:
( Sulik from Klamath)

Now we want to ask a random question, so we get a random number between 1 and 13 , and pick that row in the data set.

We roll the dice and get “1” so we take the first data row and ask

“Where is Sulik Found?”

This quiz is going to be multiple choice of 4, so we need 3 random incorrect answers, and we need to randomize the correct answer’s location somewhere within the set of incorrect answers.

Make a List of 3 unique/distinct incorrect answers out of the remaining values within the hashtable.  Again, exclude the correct answer  and handle any duplicates.  So in Sulik‘s case, the distinct set of potential incorrect answers looks like this.

Pick another random number and pick 3 distinct values from this list.  Then, append the 3 incorrect values with the correct one.  Pick another random random number 1-4 and display the randomized answers 4 times for “a.)” through “d.)“.

code for now…

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Random;
 
public class QuizStructure
{
	public static void main(String[] args)
	{
		LinkedList EveryPotentialQuestion_AnswerSet = new LinkedList();
 
		//HOW TO MAKE A Randomized QUIZ off OF a DataSet
 
		//Gamification of a DataSET// LOL :D
 
		System.out.println("indeed.");
		Hashtable Character_to_Location = new Hashtable();
 
		//"FALLOUT 2 Black Isle Character to Location" Relationship//
		//( Character - Is_From - Location )//
		//( Concept - Relationship - Concept )
		Character_to_Location.put("Sulik", "Klamath");
		Character_to_Location.put("Vic", "Den");
		Character_to_Location.put("Miria", "Modoc");
		Character_to_Location.put("Davin", "Modoc");
		Character_to_Location.put("Cassidy", "Vault City");
		Character_to_Location.put("Lenny", "Gecko");
		Character_to_Location.put("Marcus", "Broken Hills");
		Character_to_Location.put("Myron", "New Reno Stables");
		Character_to_Location.put("Skynet Robot", "Sierra Army Depot");
	        Character_to_Location.put("K-9", "Navarro");
		Character_to_Location.put("Goris", "Vault 13");
		Character_to_Location.put("Cyber Dog", "NCR");
		Character_to_Location.put("Dogmeat", "Cafe of Broken Dreams");
		System.out.println(Character_to_Location.toString());
		Enumeration keys = Character_to_Location.keys();
		while( keys.hasMoreElements() )
		{
			Object key = keys.nextElement();
			Object value = Character_to_Location.get(key);
			System.out.println("Question/Answer Preview:  Where is "+key+" from in Fallout 2?         Answer : "+value);
		}
	    Random randomGenerator = new Random();
	    System.out.println("size: "+Character_to_Location.size());
	    System.out.println("___________________________________");
		//ask Ten randomized questions with 4 randomized answers
for( int i = 0 ; i  < 10 ; i++)
{
	int randomInt = randomGenerator.nextInt(Character_to_Location.size());
	randomInt++;
	int iStop = 0;
	Enumeration morekeys = Character_to_Location.keys();
 
	while( morekeys.hasMoreElements() )
	{
	Object key = morekeys.nextElement();
	Object value = Character_to_Location.get(key);
	if ( iStop == randomInt)
	{
	//System.out.println("index:" + iStop + "    "+randomInt);
	System.out.println();
	System.out.println("Where is "+key+" from?");
	//Generate Multiple Choice
	//we know the correct answer is
	System.out.println("                   Correct Answer   : " + value);
	//now we need to generate other "incorrect" Choices
	//we need 3, Multiple Choice is Typically 4 questions
	LinkedList wrongAnswerList = new LinkedList();
	//while wrongAnswerList is not unique
	//we want to remove the possibility of duplicates
	//we want to not include correct answer
	boolean is_wronglist_unique = false;
 
while(!is_wronglist_unique)
{
int randomWrong = randomGenerator.nextInt(Character_to_Location.size());
randomWrong++;
Enumeration wrongkeys = Character_to_Location.keys();
int iStopInner =0;
while( wrongkeys.hasMoreElements() )
{
Object key2 = wrongkeys.nextElement();
Object value2 = Character_to_Location.get(key2);
if ( iStopInner == randomWrong)
{
if ( !wrongAnswerList.contains(value2))
{
if(!value2.equals(value))
	wrongAnswerList.add(value2);
}
 
}
iStopInner++;
}
if (wrongAnswerList.size() ==3)
{is_wronglist_unique = true;}
}
	System.out.println("                  Incorrect Answers : "+wrongAnswerList.toString());
	System.out.println();
	wrongAnswerList.add(value);
	System.out.println();
	String [] AnswerSet = (String[]) wrongAnswerList.toArray(new String[0]);
	//get 4 random ints :D
	//0-3
	LinkedList numberset = new LinkedList();
	boolean isnumbersetunique = false;
	int deerpCount = 0;
while(!isnumbersetunique)
{
int randomfinal4 = randomGenerator.nextInt(4);
if (!numberset.contains(randomfinal4))
{
	numberset.add(randomfinal4);
	deerpCount++;
}
if(deerpCount == 4)
{
isnumbersetunique = true;
String individualquestion ="";
System.out.println("** FINAL QUESTION ***   Where is "+key+" from?");
 individualquestion += "** FINAL QUESTION ***   Where is "+key+" from?";
ListIterator itr = numberset.listIterator();
String[] abcd = {"a.)","b.)","c.)","d.)"};
int ix = 0;
while(itr.hasNext())
{
	int get =(int) itr.next();
	System.out.println("                        " +abcd[ix]+" "+ AnswerSet[get]);
	individualquestion += "                        " +abcd[ix]+" "+ AnswerSet[get];
	ix++;
}
 
if ( !EveryPotentialQuestion_AnswerSet.contains(individualquestion))
{
	EveryPotentialQuestion_AnswerSet.add(individualquestion);
	//how do I know when this ^ is full ?????? ???????
	//What is the most optimal way to answer this ^ without doing it manually?
}
}
}
wrongAnswerList.clear();
		}
		iStop++;
	}
}
		//the more questions you ask the more answers you'll get
	}
}

Output Example:

What is the total number of distinct Questions and Possible combinations of Answers?  How many unique questions could be asked? Submit your answers below :D

C#: Hashtable Inversion, how to invert a Hashtable

This quick project is example of simple Data transformation.  Hashtable’s values containing a comma deliminated list of strings gets turned into a distinct list of keys in another Hashtable.  And, the numbers (keys of initial Hashtable) are accumulated into the values of the new Hashtable.  Creating an inverted Hashtable.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
 
namespace HashInversion
{
    class Program
    {
        static void Main(string[] args)
        {
            Hashtable num_2_Letters_Hash = new Hashtable();
            Hashtable letters_2_num_Hash = new Hashtable();
 
            num_2_Letters_Hash.Add(1, "a,c,d");
            num_2_Letters_Hash.Add(6, "d,e");
            num_2_Letters_Hash.Add(13, "a,d,j");
            num_2_Letters_Hash.Add(29, "c,e,d");
            num_2_Letters_Hash.Add(7, "j");
            num_2_Letters_Hash.Add(9, "e,c,a");
            num_2_Letters_Hash.Add(11, "c,d,f,j");
 
            foreach (var key in num_2_Letters_Hash.Keys)
            {
                string content = num_2_Letters_Hash[key].ToString();
                string [] letters = content.Split(',');
                for (int i = 0; i < letters.Length; i++)
                {
                    if ( letters_2_num_Hash.ContainsKey(letters[i].ToString()))
                    {
                        string previous_content = letters_2_num_Hash[letters[i]].ToString();
                        letters_2_num_Hash[letters[i]] = previous_content + "," + key;
                    }
                    else
                    {
                        letters_2_num_Hash.Add(letters[i],""+key);
                    }
                }
            }
 
            Console.WriteLine();
 
            Console.WriteLine("before");
            foreach (var key in num_2_Letters_Hash.Keys)
            {Console.WriteLine(key + "   " + num_2_Letters_Hash[key]);}
 
            Console.WriteLine("after");
            foreach (var key in letters_2_num_Hash.Keys)
            {Console.WriteLine(key + "   " + letters_2_num_Hash[key]);}
        }
    }
}

Java: How to invert a Hashtable?

Say you have a Hashtable with : number for keys, and a comma deliminated list of letters of values.  Now you want to make another hash table which is the opposite.  The keys for the second Hashtable will be a distinct list of all possible letters from the first Hashtable, and the values will be a comma deliminated list of all the numbers associated with a particular letter.

import java.util.Enumeration;
import java.util.Hashtable;
 
public class HashInversion
{
	public static void main(String[] args)
	{
 
		//hashtable : numbers with lists of letters
		Hashtable num2letter_hash = new Hashtable();
 
		//hashtable letters with list of numbers
		Hashtable letters2num_hash = new Hashtable();
 
		num2letter_hash.put(1,"a,b,c,d");
		num2letter_hash.put(22,"g,e,d");
		num2letter_hash.put(73,"e,g,d");
		num2letter_hash.put(41,"a,v,c,d,b,e");
		num2letter_hash.put(5,"a,l");
		num2letter_hash.put(17,"a");
		num2letter_hash.put(18,"a,l,e");
 
		//loop through all the elements in num2letter_hash
		Enumeration keys = num2letter_hash.keys();
		while( keys.hasMoreElements() )
		{
int key = (int) keys.nextElement();
String content = (String) num2letter_hash.get(key);
//break up the content by commas
String [] letters = content.split(",");
for( int i = 0 ; i < letters.length; i++)
{
//if this letter hasn't been added to the new hash,
//  add it, and set its value to the current key
//if it already exists in the new table, obtain the current value string
//  and append a new number/key to it.
if( letters2num_hash.containsKey(letters[i].toString()) )
{
String previous_num =  (String) letters2num_hash.get(letters[i].toString());
letters2num_hash.put(letters[i].toString(), previous_num+","+key);
}
else
{
letters2num_hash.put( letters[i].toString(), ""+key);
}
}
		}
		//before  (numbers,letter-list)
		System.out.println(num2letter_hash.toString());
		//after   (letters,number-list)
		System.out.println(letters2num_hash.toString());
	}
}