Boss

Boss: Rescue the Last Lantern

The boss
Boss Fight!
Every passing test breaks a shield.

Deep in the Hollow Maze lies the last lantern of Pythonia (L). The way out (X) is guarded by the Maze Golem (M), a stone giant who has stood in the dark for a hundred years. It only steps aside for someone carrying light.

Pip has just 15 turns before the maze's magic traps them. Build the whole game: movement, inventory, a turn budget and clear endings.

Rules

  • Each known command (a direction or take) uses 1 turn, even a blocked move. Unknown commands cost nothing.
  • Walls (#) and the map's edges block Pip.
  • The game is won on X, and lost when turns hit 0. Winning on your last turn still counts as a win.

Assignment

normalize, set_tile and new_game are written for you.

  1. step(state, command) returns a message (no printing):
    • Direction: use a turn. Wall or edge: "A wall blocks the way." Golem (M) without "lantern" in the backpack: "The Maze Golem blocks the exit." With it: clear the tile to ".", move there, "The Maze Golem steps aside!" Otherwise move: f"Pip walks {cmd}."
    • "take": use a turn. On L: add "lantern", clear the tile, return "Pip lifts the last lantern!" Else "Nothing to take here."
    • Anything else: f"Pip doesn't know '{cmd}'. Try north, south, east, west or take."
  2. status(state) returns "win" if Pip is on X, otherwise "lose" if state["turns"] is 0, otherwise None.
  3. play(world, start, turns, commands) makes a new game. For each command: if it normalizes to "quit", return "quit". Otherwise print the message from step, and if status isn't None, return it. If the commands run out, return "quit".