| 1 | ## “holdenwebs” |
| 2 | |
| 3 | This game has been played ever since there were cards. |
| 4 | I don't know how long that is. |
| 5 | As a child I (holdenweb) became aware of the importance of |
| 6 | memory by playing games. |
| 7 | |
| 8 | I used to watch a TV programme called "Picture Book" where |
| 9 | one of the regular features showed a scene with about ten objects |
| 10 | in it, and then asked you to name all the ones you could remember. |
| 11 | Because I was in love with the presenter (I was four, and Patricia |
| 12 | Driscoll must have been at least twenty-five) I wanted to do well. |
| 13 | |
| 14 | This particular game is often played with cards. |
| 15 | My mother taught it calling it "Remembrance," but it |
| 16 | is also known as "Pairs" and (at least in America) as "Pelmanism." |
| 17 | There are probably many other names. |
| 18 | It's pretty simple: you click on cards to reveal them until you |
| 19 | manage to pair all the cards (I didn't mention there were two of |
| 20 | each card in the deck, did I?) |
| 21 | |
| 22 | #### Game Play |
| 23 | |
| 24 | The game is played on a rectangular board, with a grid of 200 x 200 |
| 25 | "cards". When you click on a card its value is revealed. When you |
| 26 | click on a second card the same thing happens, and if the values |
| 27 | match they are removed from the game. |
| 28 | |
| 29 | The object is to match all the cards as quickly as you can. |
| 30 | |
| 31 | ### Environment |
| 32 | |
| 33 | This program started out at the June 2015 London Python Dojo, where we were |
| 34 | challenged to create programs for the "pygame-zero" environment. |
| 35 | |
| 36 | [We need to add proper links and so on so someone who just comes |
| 37 | across this can find out how to install Python and pygame-zero.] |
| 38 | |
| 39 | So it should run on most things, but it was originally |
| 40 | written on a Macintosh, though it's really targeted at |
| 41 | the Raspberry Pi. It's written in Python 3, as all new educational |
| 42 | Python programs should be, otherwise where are we going to find the |
| 43 | effort to convert all the Python 2? [Evangelism over]. |
| 44 | |
| 45 | ### Architecture |
| 46 | |
| 47 | The progam represents the board as a list of lists called `board`. |
| 48 | |
| 49 | A list calles `STATUS` contains the co-ordinates of clicked cards. |
| 50 | |
| 51 | A list called `ignore` contains the coordinates of cards that have |
| 52 | already been matched in the game and so should be ignored. |
| 53 | |
| 54 | The game as originally published establishes a list of lists |
| 55 | to represent the board. The programmer can change the board |
| 56 | size by changing ROWS and COLUMNS, but the will then have to |
| 57 | make sure that they make the window the right size (we were |
| 58 | lucky the default window appears to be 800 x 600). |
| 59 | |
| 60 | The `draw()` function clears the screen and then represents each |
| 61 | card as |
| 62 | |
| 63 | * The background image (currently a picture of @holdenweb) |
| 64 | if it hasn't been matched or clicked on; |
| 65 | |
| 66 | * The card value image (stored in the `board` list) if it has |
| 67 | been clicked on but not yet matched, or |
| 68 | |
| 69 | * A checkmark if it has been matched and is therefore no longer |
| 70 | in play. |
| 71 | |
| 72 | The `on_mouse_down()` function is activated when the user clicks |
| 73 | a mouse button. It looks at the `STATUS` list to determine |
| 74 | how many clicks the player has made this turn so far. |
| 75 | |
| 76 | If the player has already clicked twice this turn it does nothing, |
| 77 | as it is waiting for the turn to be over. Otherwise the card |
| 78 | coordinates are added to `STATUS`. |
| 79 | |
| 80 | If this is the first click, the function then simply returns. |
| 81 | |
| 82 | If this is the second click, it checks whether the two cells have the |
| 83 | same image. If they don't it should play a depressing sound (though at |
| 84 | the moment it is boringly silent). If they do then it should (but again |
| 85 | doens't) play a cheerful sound, and adds both cells to the `ignore` list |
| 86 | so they cannot be selected in subsequent turns. Finally it sets a |
| 87 | two-second timeout so the player can see what happened. |
| 88 | |
| 89 | The rest of the code just supports the functions described above. |
| 90 | |
| 91 | ### Status |
| 92 | |
| 93 | The game as it stands is functionally complete but minimally playable. |
| 94 | The logic is intended to be simple and incomplete enough to it to |
| 95 | be fun for players to extend as they wish. |
| 96 | Some suggestions are listed below. |
| 97 | |
| 98 | ## Opportunities for Developer Players |
| 99 | |
| 100 | The game has no sound effects, though `print` calls indicate where |
| 101 | the sounds should be emitted. This is a rewarding way to change the |
| 102 | game since at the moment it seems boring even to me. |
| 103 | |
| 104 | There is no fanfare of trumpets when all cards are matched. |
| 105 | The program just continues to sit there. |
| 106 | It doesn't even terminate, which would be logical once there |
| 107 | is nothing more the player can achieve. |
| 108 | |
| 109 | There is no instrumentation or scoring, which would be a major |
| 110 | way to add positive feedback for the player. |
| 111 | |
| 112 | At the moment we select the cards on the board using `board[row][col]`. |
| 113 | It would be relatively easy to use a dict and use tuples as |
| 114 | indexes, allowing the use of `board[row, col]` instead. |
| 115 | A player familiar with Python might enjoy trying that as an |
| 116 | alternative. |
| 117 | |
| 118 | When two cards are matched they currently turn checked immediately. |
| 119 | It would be better if the player actually saw the matching cards |
| 120 | for a while before play continued. |
| 121 | |
| 122 | The graphics are unexciting, and those with an interest in such matters |
| 123 | should find it easy to replace the images with something that suits their |
| 124 | taste better. The programming world needs more people with a good sense |
| 125 | of visual design. You only have to look at the current graphics to see |
| 126 | that as a graphic artist I am quite a respectable plumber. |
| 127 | |
| 128 | It's easy to adjust the timings of things, but it would be even easier |
| 129 | if the values were _manifest constants_ the same as ROWS and COLS, and |
| 130 | this would make the program logic easier to understand. |
| 131 |