๐Ÿง  MEMORY MATCH in Python

The same card game โ€” but every line of it is Python, running in your browser

โ† Back to Fun Time
๐Ÿ Starting Pythonโ€ฆ
Moves
0
Pairs
0 / 8
Stars
โ˜…โ˜…โ˜…
Best
โ€”

โŒจ๏ธ Controls

  • โ† โ†’ โ†‘ โ†“ move the dashed cursor
  • Space or Enter turn a card over
  • Clicking or tapping a card works too
  • P pause  โ€ข  R new game
  • ๐ŸŽฎ Xbox controller? Just plug it in or pair it โ€” the stick and D-pad are the arrow keys, A is SPACE, Menu pauses and View starts again

๐ŸŽฏ How to play

  • Sixteen cards lie face down, hiding eight pairs.
  • Turn two over. If they match they stay up; if not, they turn back โ€” so remember them!
  • A move is a pair of cards, not a single one.
  • Find all eight pairs to win.

๐Ÿ† Scoring

  • Eight pairs cannot be found in fewer than 8 moves.
  • 12 moves or fewer = โ˜…โ˜…โ˜…
  • 18 moves or fewer = โ˜…โ˜…
  • More than that = โ˜… โ€” everybody who finishes gets a star.

๐Ÿง‘โ€๐Ÿ’ป This whole game is Python

There is almost no JavaScript on this page. The browser downloaded Pyodide โ€” a complete Python interpreter compiled to WebAssembly โ€” and then ran the .py files in funtime/pylib/. Python does the rules, the maths and the drawing.

File What it does Good functions to try re-writing
pylib/memory_rules.py The rules: dealing, flipping, matching card_index, create_deck, is_match, flip_card
pylib/memory_draw.py Painting the cards โ€” Python calling the canvas draw_symbol, draw_card, card_at_pixel
pylib/memory_web.py The glue: clicks, keyboard, the loop do_action, on_board_click, frame

๐Ÿ” Compare the two versions. Open lib/memory-rules.js and pylib/memory_rules.py side by side โ€” same ideas, two languages.

๐Ÿ› ๏ธ Build it yourself: Build Memory Match in Python walks you through the functions one at a time.

โš ๏ธ If the game never starts: the page has to read its .py files, which a browser will not do for a page opened straight off your disk. Use the live site, or run python3 -m http.server in the project folder.