Lesson 4: Map Bug Detectives — Tracing and Fixing Broken Routes

Learning objective

Students will step through a broken map program one instruction at a time, circle the exact arrow (bug) where the path hits an obstacle or goes the wrong way, and write a working repair.

Materials

Vocabulary

Lesson flow

1. Opening: Why Guessing Doesn't Fix Bugs (7 min)

  1. Put this 4×4 Swamp Map on the board (S = Start Camp at Col 1, Row 1; T = Treehouse at Col 4, Row 4; # = Mud Swamp):
Row 4 (Top):    [ . ]  [ . ]  [ . ]  [ T ]
Row 3:          [ . ]  [ # ]  [ # ]  [ . ]
Row 2:          [ . ]  [ . ]  [ . ]  [ . ]
Row 1 (Bottom): [ S ]  [ . ]  [ # ]  [ . ]
                Col 1  Col 2  Col 3  Col 4
  1. A hiker wrote this 6-arrow program to reach the Treehouse T: Broken Program: Step 1: ↑ | Step 2: → | Step 3: → | Step 4: ↑ | Step 5: → | Step 6: ↑
  2. Ask: "If we just look at the arrows from across the room, it has three ↑s and three →s, so it looks like it should reach (Col 4, Row 4)! Why did the hiker get stuck in the Mud Swamp?"
  3. Trace and Number Each Step Together on the Map:
  4. Start at S (Col 1, Row 1).
  5. Step 1 (↑): Lands on (Col 1, Row 2) — write 1 in that square (safe!).
  6. Step 2 (→): Lands on (Col 2, Row 2) — write 2 in that square (safe!).
  7. Step 3 (→): Lands on (Col 3, Row 2) — write 3 in that square (safe!).
  8. Step 4 (↑): Moves from (Col 3, Row 2) up to (Col 3, Row 3) — SPLAT! (Col 3, Row 3) is a Mud Swamp (#)!
  9. Circle Step 4 and Step 5: If we swap Step 4 and Step 5 so the hiker goes → first (to Col 4, Row 2) and then ↑ ↑ up Column 4, the hiker walks right around the swamp and reaches T!

2. Main activity: Three Bug-Hunter Cases on the Swamp Map (18 min)

Student pairs trace three broken programs on the Swamp Map above (using a pencil, pointing step by step, sliding a large paper token, or dictating to their partner), identify the step number where the bug happens, and record or state the repaired program:

  1. Case 1 — The Wrong-Direction Bug:
  2. Broken Program: ↑ ↑ ↑ → → ←
  3. Trace: Steps 1–3 (↑ ↑ ↑) climb Column 1 to (Col 1, Row 4). Steps 4–5 (→ →) walk across Row 4 to (Col 3, Row 4). Then Step 6 (←) steps backward to (Col 2, Row 4) instead of stepping onto T!
  4. Bug Location: Step 6 (←).
  5. Fix: Change Step 6 from ← to → (↑ ↑ ↑ → → →).
  6. Case 2 — The Loop Count Bug (Off-by-One):
  7. Broken Program: REPEAT 2 TIMES: [ ↑ ] then REPEAT 3 TIMES: [ → ]
  8. Trace: REPEAT 2 TIMES: [ ↑ ] only climbs 2 squares from (Col 1, Row 1) to (Col 1, Row 3). Then the first → of the second loop crashes straight into the swamp at (Col 2, Row 3)!
  9. Bug Location: The first loop said REPEAT 2 TIMES instead of REPEAT 3 TIMES.
  10. Fix: Change the first loop to REPEAT 3 TIMES: [ ↑ ] (so the hiker climbs all the way to Row 4 before walking 3 steps right to T).
  11. Case 3 — Partner Bug Swap (6 min):
  12. Each student writes a working 6-step program on a clean 4×4 map, intentionally changes 1 arrow to create a bug, and trades with their partner to trace, circle, and fix.

3. Discussion questions (5 min)

4. Closing check (5 min)

On the Swamp Map (S at Col 1, Row 1; Swamp # at Col 3, Row 1; T at Col 4, Row 4):

  1. A student writes the program: → → ↑ → ↑ ↑. On which step number (1, 2, 3, 4, 5, or 6) does the hiker step into a Mud Swamp (#), and which square is it?
  2. What is wrong with the program ↑ ↑ ↑ → → on the Swamp Map? (Where does it stop?)
  3. How do you fix ↑ ↑ ↑ → → so it reaches T at (Col 4, Row 4)?

Worked answers for closing check

  1. Step 2 (→)! Step 1 (→) moves safely to (Col 2, Row 1), and Step 2 (→) steps right into the Mud Swamp # at (Col 3, Row 1).
  2. It stops 1 square short at (Col 3, Row 4) because it only has two → arrows at the end instead of three.
  3. Add one more → at the end (↑ ↑ ↑ → → →, or REPEAT 3 TIMES: [ ↑ ] then REPEAT 3 TIMES: [ → ]).