CS010 Introduction to Computer Science I
Term Project
Deliverable Four


Simulation Modeling:
More Object-Oriented Programming
(last updated 4/22/2007)


Update


For the fourth deliverable, you will write a simple cat and mouse simulation.  We have a room containing some mice and some cats; we will model the room as a grid of squares that may contain a critter.  The mice and cats can move one space in any of eight directions; however, two mice and two cats cannot occupy the same square at the same time.  Critters may also stay in the same location (e.g., if there are no available adjacent squares).  The edges of the grid correspond the the walls of the room; critters cannot move in a wrap-around manner from one edge to the opposite edge.  The exception to two critters occupying the same space at the same time is that a cat can move to a square containing a mouse, in which case the cat has caught the mouse (the mouse dies and is removed from the simulation, the cat eats the mouse and gets larger). 

One purpose of this projcet is to provide additional practice using the object-oriented paradigm.  Again, you should use the principles covered in class and in Sections 39-41 to create a mouse class and a cat class.  These classes should encapsulate appropriate state variables and services relevant to a cats and mice.

Such services must include: 
'draw: displays this critter (mouse or cat) according to current status (location and size
'report: returns this critter's current status (location, animal-type, size)
'find-new: find (an available) location this critter can move to
'move: move the critter to the location found in 'find-new

As with the cellular automata, we have to resolve the timing synchronization of checking the availability of adjacent squares and actually moving there.  Thus, each critter has a find-new service that determines the next spot for a critter; presumably the critter has a state-variable that can hold this information.  Then on a subsequent pass over all the critters, each can move to the found location.

Part of your problem will be to figure out a way to mark and hold a square for a given critter so that other critters don't try to move there.  (Unless one is a mouse and the other is a cat.)
Another part of your problem is to get cats to move onto mice but not onto cats.

Write a main function, cats-and-mice, that will start things off.  The function shold consume: height of the grid representing the room, the width of the grid, the initial number of mice, and the number of cats.  Your program should display the critters moving around until the cats eat all the mice.  (Caution: if your room is very large, this might take a long time or even never finish.)

If you complete all of the above requirements, you are invited to add other services such as mice eating crumbs and growing, mice reproducing, cats taking naps, etc.  I'll award extra credit if you show creativity and elegance in your enhancements.

To grade this deliverable, I will review your code (including contracts, purpose statements, indentation, etc.), and then call your cats-and-mice function.   Therefore, it is important that you follow the requirements carefully.