Welcome to the Critter Dome! In this lab, you’ll be using your OOP skills to design and implement a set of critters that will face off in an epic battle (think rock-paper-scissors turned up to 11). We’ve designed an arena where your critters will compete. Let’s start by exploring this simulated animal world. You can see this world yourself by running
At the beginning, you will see an empty grid with no animals. The
Go button starts the simulation; initially there is nothing to simulate so the move counter will just run with nothing happening. You’ll see the full simulation once you have some critters on your board.
At every step of the simulation, each critter is asked if it wants to stay in its current location or, if it wants to move, in which direction: North, East, South, or West (critters cannot move on the diagonals). Critters move around in a world of finite size, but the world is toroidal (going off the right edge brings you back to the left and vice versa; going off the top edge brings you back to the bottom and vice versa).
The critter world is divided into cells that have integer coordinates. There are 38 cells across and 35 cells up and down. The upper-left cell has coordinates (0,0), increasing
x values moves you right and increasing
y values move you down.
This program may be confusing at first because you are not writing the
main() function (i.e., the client code that uses your animal objects), therefore your code will not be in control of the overall program’s execution. Instead, you are defining a set of critter classes that become part of the larger program. For example, you might find that you want to have one of your critters make several moves all at once—you won’t be able to do that. The only way a critter can move is to wait for the simulator to ask it for a move. Although this experience can be frustrating, it is a good introduction to the kind of programming we do with objects in the real world.
As the simulation runs, critters may collide by moving onto the same location. When two critters collide, they battle. The winning critter survives and the losing critter is removed from the simulation. The following table summarizes the possible action choices each critter can make and which critter will win in each case. To help you remember which beats which, notice that the starting letters and win/loss ratings of “roar, pounce, scratch” correspond to those of “rock, paper, scissors.” If both critters make the same choice, the winner is chosen at random.
|ROAR||Random||B wins||A wins|
|A||POUNCE||A wins||Random||B wins|
|SCRATCH||B wins||A wins||Random|