
Quiz
When Does the Game End?
Every game needs clear rules for how it ends:
- Win: Pip reaches the exit (
X). - Lose: Pip runs out of turns.
- Quit: the player decides to stop.
A status function checks the rules after every turn. It
returns "win", "lose", or None when the game goes on.
But what if two rules are true at the same moment?
def status(state):
row, col = state["pos"]
if state["world"][row][col] == "X":
return "win"
if state["turns"] == 0:
return "lose"
return None
# Pip's very last turn took them onto the exit
state = {"world": ["..X"], "pos": (0, 2),
"turns": 0}
print(status(state))