๐Ÿ’  MATCH THREE in Python

The same puzzle โ€” but every match is found by Python

โ† Back to Fun Time
๐Ÿ Starting Pythonโ€ฆ
Score
0
Moves
0
Best chain
0
Best score
0

โŒจ๏ธ Controls

  • Click a shape, then click the one next to it โ€” they swap
  • โ†‘ โ†“ โ† โ†’ move  โ€ข  SPACE pick and swap
  • N shuffle the board  โ€ข  R new game
  • P pause
  • ๐ŸŽฎ 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

  • Swap two shapes that are touching to make a line of three or more.
  • The line vanishes, everything above falls down, and new shapes drop in.
  • If the falling shapes make another line, that is a chain โ€” and it is worth more.
  • A swap that makes no line is not allowed: the shapes simply swap back.

๐Ÿ† Scoring

  • Each shape cleared is worth 10 points.
  • The second link of a chain is worth double, the third triple, and so on.
  • So one big chain beats a lot of small matches.
  • Look for swaps that drop shapes onto other shapes of the same kind.

๐Ÿง‘โ€๐Ÿ’ป 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/match3_rules.py The rules: swapping, matching, falling, cascading swap_gems, find_matches, apply_gravity, try_swap
pylib/match3_draw.py Painting the shapes โ€” Python calling the canvas draw_shape, draw_grid, render_game
pylib/match3_web.py The glue: clicks, the keyboard, the cursor do_action, on_board_click, start_game

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

๐Ÿ› ๏ธ Build it yourself: Build Match Three 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.