
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
-
can_enter(world, pos, backpack)returnsFalseifposis outside the map or the tile is"#". A"G"tile is allowed only if"key"is inbackpack. Anything else isTrue. -
travel(world, start, commands)starts atstartwith an empty backpack, then for each command:- a direction in
MOVES: move there ifcan_enterallows it; "take": if the tile under Pip is inITEMSand that item isn't in the backpack yet, append its name;- anything else: ignore it.
It returns
(pos, backpack). - a direction in
-
can_enter(world, pos, backpack)returnsFalseifposis outside the map or the tile is"#". A"G"tile is allowed only if"key"is inbackpack. Anything else isTrue. -
travel(world, start, commands)starts atstartwith an empty backpack, then for each command:- a direction in
MOVES: move there ifcan_enterallows it; "take": if the tile under Pip is inITEMSand that item isn't in the backpack yet, append its name;- anything else: ignore it.
It returns
(pos, backpack). - a direction in
Press Run to try your code, then Check to test it.