Checkpoint

Checkpoint: Unlock the Watchtower

On top of Bramble Hill stands a watchtower (T) with a dark lantern. The only path goes through a locked gate (G). The key (K) is somewhere on the hill.

This checkpoint uses the whole chapter: commands, deltas, a backpack that lasts all game, and items you collect.

Assignment

  1. can_enter(world, pos, backpack) returns False if pos is outside the map or the tile is "#". A "G" tile is allowed only if "key" is in backpack. Anything else is True.

  2. travel(world, start, commands) starts at start with an empty backpack, then for each command:

    • a direction in MOVES: move there if can_enter allows it;
    • "take": if the tile under Pip is in ITEMS and that item isn't in the backpack yet, append its name;
    • anything else: ignore it.

    It returns (pos, backpack).