๐ŸŒ€ MAZE RUNNER in Python

The same maze โ€” but Python digs it and Python finds the way out

โ† Back to Fun Time
๐Ÿ Starting Pythonโ€ฆ
Steps
0
Best possible
0
Time
0
Escaped
0

โŒจ๏ธ Controls

  • โ†‘ โ†“ โ† โ†’ or W A S D walk
  • Tapping the maze walks one step towards where you tapped
  • H or SPACE show the shortest way out
  • N dig a brand-new maze  โ€ข  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

  • Start in the top-left corner. The ring in the bottom-right is the way out.
  • Every maze is dug fresh, so you have never seen this one before.
  • There is always exactly one route between any two places โ€” no loops.
  • The scoreboard shows the fewest steps possible. Can you match it?

๐Ÿง  Two great algorithms

  • The maze is dug by a recursive backtracker: walk, dig, and back up when stuck.
  • The hint uses breadth-first search, the shortest-path algorithm.
  • The same search finds routes on road maps and in chess programs.
  • Both are only about twenty lines. You write them in the workshop.

๐Ÿง‘โ€๐Ÿ’ป 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/maze_rules.py The rules: digging the maze and finding the way out room_neighbours, carve_maze, find_path, move_player
pylib/maze_draw.py Painting the maze โ€” Python calling the canvas draw_maze, draw_hint, render_game
pylib/maze_web.py The glue: the keyboard, the taps, the clock do_action, on_board_click, frame

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

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