AP CSP Robot Tracing Practice
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
IF (CAN_MOVE (left)) { ROTATE_LEFT(); MF() }
IF (CAN_MOVE (forward)) { MF() } ELSE { ROTATE_LEFT() }
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.
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.
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.
REPEAT UNTIL (goalReached())
{
}
Which of the following replacements for moves the robot to the goal square?
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.
REPEAT UNTIL (goalReached())
{
}
Which replacement for moves the robot to the goal?
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.
REPEAT UNTIL (goalReached())
{
}
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.
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?
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.
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?
Practice Complete!
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.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]