๐Ÿ’ฃ MINESWEEPER in Python

The same puzzle โ€” but the flood fill is written in Python

โ† Back to Fun Time
๐Ÿ Starting Pythonโ€ฆ
Mines left
10
Time
0
Opened
0
Best time
โ€”

โŒจ๏ธ Controls

  • Left click a square to dig  โ€ข  right click to flag it
  • On a phone: tap to dig, press and hold to flag
  • โ†‘ โ†“ โ† โ†’ move  โ€ข  SPACE dig  โ€ข  F flag
  • 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

  • The number on a square says how many of the eight squares around it are mines.
  • A square with no number has no mines near it at all โ€” so its neighbours open too.
  • Your first click is always safe. Dig anywhere to start.
  • You win by opening every square that is not a mine. Flags are just notes to yourself.

๐Ÿ† Getting good

  • If a 1 already has one flag beside it, every other neighbour is safe.
  • If a 3 has exactly three covered neighbours, all three are mines.
  • Work along the edges of the opened area โ€” that is where the clues are.
  • Stuck? There is usually a square somewhere else you can still work out.

๐Ÿง‘โ€๐Ÿ’ป 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/mines_rules.py The rules: the neighbours, the mines, the flood fill neighbours, count_mines, place_mines, reveal_cell
pylib/mines_draw.py Painting the board โ€” Python calling the canvas draw_covered, draw_flag, render_game
pylib/mines_web.py The glue: left click, right click, the clock do_action, on_right_click, frame

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

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