
Boss
Boss: Rescue the Last Lantern

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.
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. OnL: 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."
- Direction: use a turn. Wall or edge:
status(state)returns"win"if Pip is onX, otherwise"lose"ifstate["turns"]is 0, otherwiseNone.play(world, start, turns, commands)makes a new game. For each command: if it normalizes to"quit", return"quit". Otherwise print the message fromstep, and ifstatusisn'tNone, return it. If the commands run out, return"quit".
normalize, set_tile and new_game are written for you.
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. OnL: 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."
- Direction: use a turn. Wall or edge:
status(state)returns"win"if Pip is onX, otherwise"lose"ifstate["turns"]is 0, otherwiseNone.play(world, start, turns, commands)makes a new game. For each command: if it normalizes to"quit", return"quit". Otherwise print the message fromstep, and ifstatusisn'tNone, return it. If the commands run out, return"quit".
main.py Python sleeping
Press Run to try your code, then Check to test it.