COMP 141: Project 9

Memory

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 matching game commonly played by children. The game starts with all the cards turned face-down (so you can't see the face-up side), and a player will select two cards to turn over. If the two cards match, they remain face-up, otherwise, they are turned back over. The object of the game is to find all pairs of cards using one's memory of which cards they've seen before and where they are located. Memory is normally a 2-player game where that the player that finds the most pairs at the end of the game wins, but we will implement a single-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

    In Memory, we will begin with a 4-by-4 grid of cards arranged in a square. This grid will be represented internally (in Python) as a 2d list. Similarly, each card in the grid will be represented internally (in your Python program) as a number from 1-8. Note that there are 16 squares in a 4x4 grid, so each number from 1-8 will appear twice (which makes sense, since the player must find pairs of numbers). However, when you draw the cards using simplegraphics, you will use colors instead of numbers (you can decide on which color each number 1-8 should go with).

    The program will work similarly to our tic-tac-toe with graphics program, in that you're using a numeric representation internally in Python (numbers 1-8 for Memory, and 1/0/-1 for tic-tac-toe), but when you display the game board, you're using a different representation visually (colors for Memory, and X/O for tic-tac-toe).

    Requirements

    Your program should do the following:

    Your program should keep running until there are no more unturned "cards".

    Example Run

    Since this program is using graphics, there is no example run. 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.

    Suggested steps that your program should take

    You can follow the same basic idea as the graphical tic-tac-toe game.

    What to Do

  • Create a Python program named yourlastname_yourfirstname_memory.py. If you are working with a partner, name it yourlastname_partnerslastname_memory.py
  • Include the standard program header at the top of your Python file and follow the comment guide to correctly comment your code.
  • Submit your Python file on Moodle under Program 9.
  • 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)
  • 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.