AP CSP Robot Tracing Practice

5 Questions Exam-Authentic Only Strategy Guide Predict First

AP CSP Robot Practice — Exam Style

Big Idea 3: Algorithms & Programming — MISSING CODE, Which Grid Fails & Natural Language Algorithms

🔈

Strategy: Find the Decision Point First

Every robot MISSING CODE question has one or more decision points — squares where the robot’s path requires a conditional choice. Before reading any answer option, find those points on the grid. They map directly to the IF(CAN_MOVE...) conditions you need.

Decision Point → CAN_MOVE Condition

Robot must turn left at a junction Look for left path open, forward blocked IF (CAN_MOVE (left)) { ROTATE_LEFT(); MF() }
Robot hits a wall, must turn Look for forward blocked IF (CAN_MOVE (forward)) { MF() } ELSE { ROTATE_LEFT() }
Robot hugs wall until opening Look for right side blocked, then open REPEAT UNTIL (CAN_MOVE(right)) { MF() }; ROTATE_RIGHT()

Step 1: Identify decision points

Trace the path the robot needs to follow. Mark every square where it must choose between going straight or turning. These are your inflection points — typically corners, T-junctions, or dead ends.

Step 2: Match condition to direction

At each decision point, ask: “What direction does the robot need to check?” If the robot turns left at a crossing, the code checks CAN_MOVE(left). If it keeps going until hitting a wall, look for a blocked-forward condition.

Step 3: Order matters — rotate THEN move

A common wrong answer places MOVE_FORWARD before ROTATE. If the robot needs to turn left and step through a door, the code must ROTATE_LEFT() first, then MOVE_FORWARD() — never the reverse.

For “Which Grid Fails” questions: The program can only turn in one direction (left or right). Scan each grid to find whether the path to the goal requires a turn in the other direction. If it does, that’s the grid that fails. If all turns go the same way as the program rotates, it works.
Your Score 0 / 5

Section 1: MISSING CODE Questions

The most common robot question type. Fill in the body of a REPEAT UNTIL loop. Use the decision-point strategy above before revealing choices.

1
MISSING CODE — Find the Correct Body
MediumMISSING CODE
💡Decision point: The robot travels right, then hits the right boundary. At that point it cannot go forward. What does it need to do? Turn toward the goal (upward). Turning left from a rightward-facing robot = facing up. So the condition is: if forward is blocked, ROTATE_LEFT.

The grid above shows a robot at row 3, column 1, facing right (→), in a 4×4 grid. The black squares at rows 1–2, column 1 are walls the robot cannot enter. The goal is the highlighted square at row 1, column 3.

Grid
Outer Loop (given)
REPEAT UNTIL (goalReached())
{
   
}
Option A

Option B

Option C

Option D

Which of the following replacements for moves the robot to the goal square?

2
MISSING CODE — Nested REPEAT UNTIL
HardMISSING CODE — Nested Loop
💡Decision point: The decision point is the corner where the robot hits the right boundary wall and must turn. The robot should move forward until it cannot, then turn right (to face upward). That maps to: REPEAT UNTIL(NOT forward){MF}; ROTATE_RIGHT.

The robot starts at row 5, column 1, facing right (→). The black squares block the right column and bottom row (except the start). The goal is at row 1, column 5.

Grid
Outer Loop (given)
REPEAT UNTIL (goalReached())
{
   
}
Option A

Option B

Option C

Option D

Which replacement for moves the robot to the goal?

3
MISSING CODE — When to Turn Left
HardMISSING CODE — Left Turn Decision
💡Decision point: The decision point is at row 3, column 3: the robot is heading up but (2,3) is a wall. Forward is blocked. Right is also blocked (3,4 is a wall). The only open direction is left (toward col 2). The condition to check is CAN_MOVE(left) — rotate left first, then move. The order matters: rotate then move, not move then rotate.

The robot starts at row 5, column 3, facing up (↑). The black squares block the upper-right region of the grid. The goal is at row 1, column 1.

Grid
Outer Loop (given)
REPEAT UNTIL (goalReached())
{
   
}
Option A

Option B

Option C

Option D

Which replacement for moves the robot to the goal?

Section 2: Which Grid Does the Program Fail?

A program is given. One of four grids causes it to loop or miss the goal. Test each grid against the program mentally.

4
For Which Grid Does the Program FAIL?
HardWhich Grid Fails
💡Decision point: Key insight: This program can only turn left. If any point on the path to the goal requires a right turn, the program will rotate the wrong direction and loop. Scan each grid: does the path from robot to goal require any right turns?
Program

Grid A
Grid B
Grid C
Grid D

The program above is used in each of the four grids below. The robot can move into white or gray squares but cannot move into black regions. For which grid does the program NOT correctly move the robot to the goal?

Section 3: Natural Language Algorithm

Four English step descriptions, four grids with different robot starting positions. Which algorithm works for all four?

5
Natural Language Algorithm — Circuit Around Black Squares
HardNatural Language Algorithm
💡Decision point: Decision point: When should the robot stop moving forward and make a corner turn? It should turn exactly when it reaches a corner of the black region — which is exactly when the square to its right changes from black to non-black (end of a side). Going forward until the right is black means the robot is moving alongside the black region. The corner is when the black region ends on the right.

The figure above shows one example grid. Each of the four grids below has the same 2×2 black square region, but the robot starts in a different position and direction along the perimeter. The goal is for the robot to make a complete circuit around the black squares, finishing in its exact starting position and direction.

Example Grid

The figure above shows one example arrangement. The same 2×2 black region appears in all four grids; only the robot’s starting position and direction changes. Which of the following algorithms moves the robot in a complete circuit around the black squares, returning to its exact starting position and direction in every grid?

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]