Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
Fun and challenging memory game.

Post by Matthew »

I was reading a book yesterday which had a section about memory. It gave a technique of remembering lists easily, especially with nouns. You link each noun together with a visualisation. This way you can also remember lists in order. To test my new skill I made a program. In this program, select the number of items you want in a list. The program will show each item for 5 seconds each. Afterwards you need to recall the items in order. You aren't allowed to look back at the items else it's cheating. It will score you afterwards.

If you have python then jsut run this code in a file with the .py extension from a terminal with the python or equivalent (Eg, python2.x) command.

Code: Select all

#!/usr/bin/env python
import random,os,time
nouns = ["advice","anger","answer","apple","arithmetic","badge","basket","basketball","battle","beast","beetle","beggar","brain","branch","bubble","bucket","cactus","cannon","cattle","celery","cellar","cloth","coach","coast","crate","cream","daughter","donkey","drug","earthquake","feast","fifth","finger","flock","frame","furniture","geese","ghost","giraffe","governor","honey","hope","hydrant","icicle","income","island","jeans","judge","lace","lamp","lettuce","marble","month","north","ocean","patch","plane","playground","poison","riddle","rifle","scale","seashore","sheet","pavement","skate","slave","sleet","smoke","stage","station","thrill","throat","throne","title","toothbrush","turkey","underwear","vacation","vegetable","visitor","voyage","year","monkey","banana","telephone","robot","water","bomb","chocolate","fire","ring","boat","camera","tomato","wrench","flour","milk","paint","pie","shovel","axe","wall","carrot","bath"]
while 1:
	print "A number of words will appear for 5 seconds each. Try to remember them in the order they appear. After all the words have been given you will need to type the words you saw in order, afterwards. You will then be given a score."
	while 1:
		try:
			number = int(raw_input("How many words? (5-105): "))
			if number > 4 and number < 106:
				break
		except ValueError:
			print "Error: Not a number."
	words = random.sample(nouns, number)
	for word in words:
		os.system("clear")
		print
		print "   " + word
		time.sleep(5)
	os.system("clear")
	score = 0
	answers = []
	for word in words:
		ans = (raw_input("Give the next word: ")).lower()
		answers.append(ans)
		if ans == word:
			score += 1
	print "You scored " + str(score) + "/" + str(number)
	print "Actual - Yours"
	for x in xrange(len(words)):
		print words[x] + " - " + answers[x] 
	while 1:
		ans = raw_input("Play again? (Y/N):")
		if ans == "N":
			raise(SystemExit)
		elif ans == "Y":
			break
		
I got 25/25!!!!
You scored 25/25
Actual - Yours
telephone - telephone
branch - branch
cactus - cactus
hydrant - hydrant
cellar - cellar
advice - advice
water - water
smoke - smoke
seashore - seashore
north - north
turkey - turkey
arithmetic - arithmetic
income - income
beetle - beetle
coach - coach
rifle - rifle
bomb - bomb
cattle - cattle
chocolate - chocolate
battle - battle
beast - beast
basketball - basketball
honey - honey
toothbrush - toothbrush
basket - basket
...Well, before I got 9/25. That was the first try with 25 items. The technique works wonders.

Have fun!
Administrator
Administrator
Posts: 3307
Joined: Thu Dec 24, 2009 2:06 am
Allegiance:: Space Rome
Location: ON, Canada
User avatar
Administrator
Administrator
Re: Fun and challenging memory game.

Post by Scott »

I know this is late, but I did try it and a bunch of syntax errors came up. I fixed some of them but my Python knowledge isn't to extensive.

EDIT:
I have managed to create a C++ version though but have not been able to make completely random numbers (I think learning more about srand will solve the problem) but have come up with this:

Code: Select all

#include <iostream>
#include <windows.h>
#include <string>

int main()
{
    using namespace std;
    
    string nouns[105] = {"advice","anger","answer","apple","arithmetic","badge", "basket","basketball","battle","beast","beetle","beggar","brain","branch","bubble","bucket","cactus","cannon","cattle","celery", "cellar","cloth","coach","coast","crate","cream","daughter","donkey","drug","earthquake","feast","fifth","finger","flock","frame","furniture","geese","ghost","giraffe","governor","honey","hope","hydrant","icicle","income","island","jeans","judge","lace","lamp","lettuce","marble","month","north","ocean","patch","plane","playground","poison","riddle","rifle","scale","seashore","sheet","pavement","skate","slave","sleet","smoke","stage","station","thrill","throat","throne","title","toothbrush","turkey","underwear","vacation","vegetable","visitor","voyage","year","monkey","banana","telephone","robot","water","bomb","chocolate","fire","ring","boat","camera","tomato","wrench","flour","milk","paint","pie","shovel","axe","wall","carrot","bath"};
    
    int nounPicks, i = 0, score = 0, j;    
    int question[25];
    string answer[25];
    
    cout << "You will get 25 words to remember with two seconds betweeen each word generated.\nYour goal is to remember as many as you can\n\n";
    cout << "Press ENTER when ready\n";
    cin.get();    
    cout << "\n\n\n\n";
    
    while (i != 25)
    {
          nounPicks = (rand() % 104);
          question[i] = nounPicks;          
          cout << nouns[nounPicks] << endl; 
          Sleep(2000);                   
          i++;
    }
    
    i = 0; //so it will print out correctly
    j = 1;
    
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    cout << "Please enter the words in the order you saw them.";
    while (i != 25)//to accomadate the incremented one before hand
    {       
          cout << "\n" << j << ". ";    
          cin >> answer[i];               
          i++;
          j++;
    }
        
    for (i = 0; i != 25; i++)
    {
        j = question[i];
        
        if (answer[i] == nouns[j])
        {
                      score++;
        }
    }
                      
    cout << "\nCongratualtions you are finished!";
    cout << "You scored: " << score << "/" << "25";
    
    cout << "\n\nPress ENTER to exit\n";
    cin.get();
    cin.get();
    
    return 0;      
}
          
I will post back once I get a chance to try your technique.
Image
Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
Give me the errors and I'll fix them.

"#include <windows.h>"

I can't try it then.
Administrator
Administrator
Posts: 3307
Joined: Thu Dec 24, 2009 2:06 am
Allegiance:: Space Rome
Location: ON, Canada
User avatar
Administrator
Administrator
Re: Fun and challenging memory game.

Post by Scott »

The syntax errors were in the python program not the C++ program.
Image
Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
I made the python version so I can fix it. I'm good with python.
Administrator
Administrator
Posts: 3307
Joined: Thu Dec 24, 2009 2:06 am
Allegiance:: Space Rome
Location: ON, Canada
User avatar
Administrator
Administrator
Re: Fun and challenging memory game.

Post by Scott »

Sorry, I misunderstood. I thought you meant that you couldn't try to fix the syntax errors in the C++ version when you were referring to the header. What OS do you use? I might be able to find an alternative (it is mainly for the sleep function).

As for the errors, there were many missing brackets for print which were easy to fix but also some errors I did not know how to fix.

Code: Select all

Traceback (most recent call last):
  File "C:\Documents and Settings\Derek\My Documents\memorygame.py", line 8, in <module>
    number = int(raw_input("How many words? (5-105): "))
NameError: name 'raw_input' is not defined
This is the first error and is the only one that is come up thus far. I know what it means but don't know if "raw_input" is a variable to meant to define or a function of sorts.

Oh, and to clarify, my name isn't Derek.
Image
Jedi Master
Jedi Master
Posts: 336
Joined: Sun Aug 09, 2009 9:16 am
Allegiance:: Jedi
User avatar
Jedi Master
Jedi Master
I use OSX.

I think you must be using python 3. I use python 2. Python 2 is more widely supported and more compatible with various things.

Python 3 isn't backwards compatible.
Administrator
Administrator
Posts: 3307
Joined: Thu Dec 24, 2009 2:06 am
Allegiance:: Space Rome
Location: ON, Canada
User avatar
Administrator
Administrator
Re: Fun and challenging memory game.

Post by Scott »

Okay
Image
Post Reply