AP CSA FRQ Guide
2007 FRQ 2: PounceFish
Search forward within a fish visibility range for the nearest prey, then eat that fish and move to its location, or use ordinary fish behavior when no prey is found.
Legacy Marine Biology Simulation22 minute targetMarine Biology Simulationinheritanceobjectsdirectional searchlegacy
Skills Tested
What this FRQ is really practicing
Marine Biology Simulationinheritanceobjectsdirectional searchlegacy
Review these topics before attempting the problem.
Starter Approach
How to begin with your own plan
- 1Part A: search at most range locations directly ahead, starting with the next location, and return the nearest fish found.
- 2Respect environment boundaries and return null when there is no fish within range.
- 3Part B: keep the supplied isInEnv guard, use findFish, and move to the original location of prey after causing it to die.
- 4When no prey is found, delegate to the ordinary Fish act behavior.
Attempt the problem before opening the solution.
Common Mistakes
Mistakes to watch for while writing
Scanning all surrounding locations instead of looking only forward.
Returning a farther fish instead of the first fish encountered.
Trying to obtain the prey location only after removing the prey from its environment.
Self Check
Review questions before you submit
Uses the fish visibility range to limit the search.
Check only locations directly ahead, from nearest to farthest.
Returns null when the search finds no prey.
Do not return this fish or an out-of-range fish.
Calls findFish to locate prey during act.
Reuse the search helper rather than duplicating it.
Uses the inherited act behavior when there is no prey.
The no-prey branch should delegate to super.act().
Practice Links
