AP CSA FRQ Guide
2009 FRQ 2: StockpileCritter
Write a legacy GridWorld critter that gathers neighboring actors into an energy stockpile, spends one unit of energy per act, and removes itself when it cannot supply that energy.
Legacy GridWorld Energy State22 minute targetGridWorldclassesstateinheritancelegacy
Skills Tested
What this FRQ is really practicing
GridWorldclassesstateinheritancelegacy
Review these topics before attempting the problem.
Starter Approach
How to begin with your own plan
- 1Maintain private stockpile state between acts, starting with no stored energy.
- 2Gather all neighboring actors by removing them from the grid and adding one energy unit for each actor.
- 3Spend one energy unit when available; remove this critter when no unit can be spent.
- 4Preserve the inherited act method and the postconditions of the Critter methods.
Attempt the problem before opening the solution.
Common Mistakes
Mistakes to watch for while writing
Overriding act instead of using the inherited Critter behavior.
Removing only selected kinds of neighbors rather than all gathered actors.
Checking for starvation before collecting the neighboring actors.
Self Check
Review questions before you submit
Declares private state for stored energy.
A local variable would lose the stockpile between acts.
Overrides processActors to gather neighboring actors.
Keep act inherited and use the appropriate Critter hook.
Removes gathered actors from the grid.
Every gathered neighboring actor contributes one energy unit.
Decreases stored energy when supplying an act.
Check the stockpile after gathering neighbors.
Practice Links
