2009 AP CSA FRQ 4: TileGame
Topic: 2D Arrays & Game Logic
Skills: 2D array manipulation, object movement, game state management
Unit: Unit 4 (Data Collections) (2025-2026 AP CSA)
Points: 9 | Time: ~22 minutes
Part (a)
Write the getEmptyLocation method that finds the empty position in the grid.
Solution
public Location getEmptyLocation()
{
for (int r = 0; r < board.length; r++)
{
for (int c = 0; c < board[0].length; c++)
{
if (board[r][c] == 0)
{
return new Location(r, c);
}
}
}
return null;
}Part (b)
Write the slideDown method that moves a tile down if the space below is empty.
Solution
public boolean slideDown(int row, int col)
{
if (row + 1 >= board.length || board[row + 1][col] != 0)
{
return false;
}
board[row + 1][col] = board[row][col];
board[row][col] = 0;
return true;
}Key Concepts
Common Mistakes
Official Resources
Author: Tanner Crow - AP CS Teacher, 11+ years