Program Overview

Open Live View Before Moving On

Since this portion of the lab involves an interactive graphical display, you’ll need to use the Ports tab to open a live view window over port 6080. As in previous labs, the password is csci. Please refer to the lab 4 warmup for detailed instructions if you need a reminder.

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 a grid with whatever critters exist in your project. The Go button starts the simulation. Initially, there are only Sloth ‘S’ critters which don’t move – these are a given example critter we’ll explain in the next part. As such, the move counter will increase without any movement on the board. You will eventually see the full simulation after implementing different critters.

At every step of the simulation, each critter is asked if it wants to stay in its current location or, if not, in which direction it wants to move: North, East, South, or West (critters cannot move on the diagonals). The arena has a finite size, but is “toroidal”—this means 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.

ROARRandomB winsA wins
APOUNCEA winsRandomB wins
SCRATCHB winsA winsRandom