COMP 141 Spring 2018
Program 8: Memory
Assigned: Monday, April 16
Due: Friday, April 27, 2018 by 11:55pm
You may work with a partner for this project. If you choose to do so, only turn in one copy of the project with both of your names in the comments at the beginning of the code.
If Memory doesn't particularly interest you, you may do one of the challenge problems at the end of this description, or propose a different project to me of comparable difficulty.
You must get my approval before starting work on your project if you are not writing the Memory program.
The game Memory is a simple matching game usually played with cards in which there are 2 of each kind of card. The game starts with all the cards turned upside down (so you can't see their face), and a player will select two cards to turn over. If the two cards match, they remain up, otherwise, they are turned back over. The idea is to find all pairs of cards using one's memory of which cards they've seen before. Memory is normally a 2-player game such that the player with the most pairs at the end of the game, wins! We will instead implement a 1-player version, in which case the player will always "win" assuming they don't give up.
This program will most likely take longer than others this semester - be sure to START EARLY!
Program Specifications
This program requires you to use:
2-D lists
SimpleGraphics: open a canvas, use mouse clicks as the user input for moves, close the canvas
Random number generation: to initialize the board
Nested loops
Description
Write a program that
Uses simplegraphics to:
Draw grid lines to display a 4 x 4 grid
Use clicks to determine which grid location a user has selected
Correctly uncover the appropriate "card" (i.e. display the correct shape/color for the clicked on grid square)
Allow the user to select 2 cards for each turn and if the cards match, leave them turned up, otherwise, turn them back over
You must correctly display the board after every click.
You will compare 2 cards and then on the next click, turn the cards back over if they are not matching.
You must use at least a 4 x 4 board, but you are welcome to make it bigger.
You must draw something in each grid when it is clicked, but it does not have to be a filled in circle.
Your program should keep running until there are no more unturned "cards".
Example Run
Since this program is using graphics, there is no example dialog. However, here are some screenshots of a game while it is being played.
Initial Board |
Board After 1st turn |
End Board |
 |
 |
 |
Your board does not need to look exactly like this, but all the mentioned functionality should work as shown. If you would like to play my version of the game to check the functionality, the compiled python code is available under the Memory.zip file in my Public directory. You'll need to unzip this file onto your computer and run it from the command line. Ask me if you have trouble with this.
Hints
I suggest initializing your board with 2 copies each of 1-8. (Don't randomly select the values, randomly select the row and column that value will go in.)
I suggest using positive values of 1-8 to designate cards that are NOT showing, and negative values to designate cards that ARE showing.
I suggest writing a do_move function that takes in the board, row and column and switches the sign of the value at that location in the board. (i.e. if it is -5 it becomes 5, if it is 5 it becomes -5.)
I suggest writing a function that converts a number to a color so you can easily lookup the color of the shape you wish to display for a particular value. You can instead have numbers associated with images. Again, write a simple if-elif-else type function to map numbers to images.
I suggest dealing with a pair of clicks for each iteration of your loop, i.e., allow the user to click once and show that "card", click a 2nd time, show that "card", and then compare them and update the values in the board as necessary (switch back to positive if they were not matching.) This code is all in 1 iteration of the loop.
What to Do
Create a Python program named yourlastname_yourfirstname_prg8.py. If you work with a partner, name it yourlastname_partnerslastname_prg8.py
Include the standard program header at the top of your Python file.
Follow the comment guide to correctly comment your code.
Submit your Python file on Moodle under Program 8.
Note: If you include any images in your code, be sure to create a zip file with your .py file and the image files and submit the .zip file on Moodle.
Requirements
When I examine your program, an A program must satisfy the following requirements.
Your program file is named correctly and it includes the standard program header.
You must open the canvas.
You must draw grid lines on the canvas so the user can tell where each "card" is.
You must randomly initialize the board so that the game is different every time.
The user must be able to clearly tell when a pair is matching.
You must close the canvas on the last click.
You must turn over a card when the user clicks.
You must compare the 2 uncovered cards and turn them back over if they are not the same.
You must display a final message when the user "wins".
You must use appropriate functions (at least 3 functions besides main).
Creativity points - have fun with this and make it your own!
You must comment your code appropriately (particularly your functions), use good variable names, and your code must be neatly and clearly formatted and include proper use of 'white space'.
Note: If your program doesn't run (i.e, has a syntax error), you may receive partial credit for the items listed above in bold.
Alternate Challenge Questions
Here are some alternate games/projects with graphics that involve a 2-D list. You are welcome to work on one of these problems instead of Memory, but you MUST let me know as it is best to agree upon final functionality before you being implementing. As mentioned, you may also select a different game with graphics if none of these are to your liking either. Any ideas beyond this list MUST be approved before you begin working on them.
Minesweeper
Connect 4 (requires the normal board size of 6 x 7)
PPM Image - Pesky Tourist Problem - involves reading in a few similar images and finding the median value image - more details available upon request
2048
Grading
Your program will be graded on correctness, as well as on coding style, which refers to choices you make when writing your code, such as good use of variable names, appropriate indentation,
and comments (this is not an exhaustive list). See the syllabus for further grading details.
You will receive one bonus point for every complete day your program is turned in early, up to a maximum of five points. For instance, if your program is due on September 20 at 11:59pm, if you turn in your code on Moodle any time on September 19 from 12:00am through 11:59pm, you will receive one extra point on your project. Programs submitted on September 18 from 12:00am through 11:59pm will receive two points. This pattern continues for up to five points.