Bug hunt

The Disappearing Backpack

Some things should be set up once, before the game loop starts: the backpack, the step counter, the score. If you create them inside the loop, they are wiped clean at the start of every turn.

for cmd in commands:
    score = 0      # oops: back to 0 every turn!
    score += 1

The bug

Pip explores the meadow, takes the crystal, then takes the key. The explorer should report (['crystal', 'key'], 3): both items, and 3 steps walked. Instead it prints:

(['key'], 0)

The crystal vanished from the backpack, and the steps count is wrong. Two lines are in the wrong place.

Assignment

Fix explore(world, commands) so the backpack and the step count last for the whole expedition. It returns (backpack, steps).