🎯Calibrate
1Fill-in
2Debug
3Extend
4Create
🧠Concept
📓Reflect
👤 Your Details REQUIRED — fill in before you begin (★ = required)
Please fill in Name, Matric No., and Class before continuing.
🎯 Pre-Activity Calibration How confident are you? Make a prediction first.
Why calibrate? Predicting your score before you start trains metacognition — the skill of knowing what you know. Your prediction is never graded; only your honesty matters.
5
Before you start, guess what percentage of blanks you will get correct on your first attempt.



Tier 1 Fill-in-the-Blank — MOVES dict & wrap-around Complete the 6 blanks in the refactored update_game function.

Step 7 replaces the old if/elif direction chain with a dictionary lookup, and replaces wall-death with modulo wrap-around. Fill in each blank — use exact Python syntax.

MOVES = { "RIGHT": ( 1, 0), "LEFT": (-1, 0), "UP": ( 0, -1), "DOWN": ( 0, 1) } def update_game(snake, direction, food, score): hx, hy = snake[ [1] ] # get the head (index = ?) dx, dy = MOVES[ [2] ] # look up direction vector hx += dx; hy += dy # move one step hx = hx [3] GRID_COLS # wrap horizontally hy = hy [4] GRID_ROWS # wrap vertically new_head = (hx, hy) if new_head [5] snake[1:]: # self-collision only return snake, food, score, [6]
[1] Head index (one digit)
[2] Variable name for the direction string
[3] Wrap operator for horizontal (one character)
[4] Wrap operator for vertical (one character)
[5] Membership keyword (i_)
[6] Boolean value to stop the game (F_____)
Tier 2 Debug — Find & Fix 3 Bugs Each broken line below has one error. Write the corrected line in the input.

Three common mistakes students make when implementing wrap-around and the MOVES dictionary. Fix each broken line — type the corrected Python line exactly.

🐞 Bug 1 — Wrong wrap operator

The student used division instead of modulo. The snake exits the grid instead of wrapping.

hx = hx / GRID_COLS

Hint: one character is wrong — which operator causes wrap-around?

🐞 Bug 2 — Hardcoded dictionary key

The student hardcoded a lowercase string instead of using the direction variable. This always causes a KeyError.

dx, dy = MOVES["right"]

Hint: use the variable that holds the current direction string.

🐞 Bug 3 — Missing head index

The student tries to unpack the entire snake list instead of just its head. This causes a too many values to unpack error.

hx, hy = snake

Hint: access only the first element of the snake list.

REFLECT Mid-Activity Reflection (min 10 words to continue)


Tier 3 Extend — Add a STOP command to MOVES Modify the existing code to add new behaviour without rewriting everything.

One strength of the dictionary approach is how easy it is to extend. Add a "STOP" key to MOVES so the snake stays in place when it receives that command — then update update_game so it handles "STOP" correctly (the snake should not move or grow).

MOVES = { "RIGHT": ( 1, 0), "LEFT": (-1, 0), "UP": ( 0, -1), "DOWN": ( 0, 1), # ← add your STOP entry here } def update_game(snake, direction, food, score): hx, hy = snake[0] dx, dy = MOVES[direction] # ← handle STOP: if dx==0 and dy==0, return early unchanged hx += dx; hy += dy hx = hx % GRID_COLS hy = hy % GRID_ROWS ...


Tier 4 Create — Write update_game from scratch Apply everything: MOVES dictionary + modulo wrap-around + self-collision check.

Without referring to the code above, write the complete update_game function. It must: (1) look up the direction vector using MOVES, (2) apply wrap-around using %, (3) check for self-collision only (no wall-death), and (4) handle food/score correctly.

GRID_COLS = 20 GRID_ROWS = 15 MOVES = { # fill in the 4 direction keys and (dx, dy) tuples } def update_game(snake, direction, food, score): # your implementation here pass


🧠 Concept Concept Check — Modulo & Dictionary 5 multiple-choice questions. Answer all 5 then submit.

Test your understanding of modulo arithmetic and dictionary-based dispatch.

1. What does 20 % 20 evaluate to?

2. Given hx = -1 and GRID_COLS = 20, what is hx % GRID_COLS?

3. Why is using a MOVES dictionary better than an if/elif chain for direction handling?

4. Given MOVES = {"LEFT": (-1, 0)}, what does dx, dy = MOVES["LEFT"] give?

5. After adding % wrap-around, which check from the old code can be removed?

POST-ACTIVITY Post-Activity Calibration & Reflection
5
This is your self-estimate — be honest!



JOURNAL Reflective Journal — Step 7 (min 5 words per prompt)