Project 2: It’s a cat and mouse game… | CS 2113 Software Engineering - Spring 2021

Project 2: It’s a cat and mouse game… #

This is a two part project. The first part of the project will require you to submit a UML diagram and descriptions of your OOP design to complete the project. The second part of the project is your full submission.

Preliminaries #

Github Classroom Link:

Testing #

There is no test script. There is built in debugging tools that can help you develop your code and perform grading.

Compiling your code #

Your code should compile with javac

javac *.java

Development Environment #

You can complete this code using replit or with a local IDE like IntelliJ, VisualStudio, or XCode.

Mice, Cat, ZombieCat Simulation #

In this project, you will complete a point simulation of a city of mice, cats, and zombie-cats! Once your simulation is visualized, it may look like the animation below.

Simulation GIF

A quick description of this visualization. The blue dots are mice, the yellow/cyan dots are cats, and the red/black zombie-cats. Cats chase mice, and when they catch a mouse, they eat it. If a cat doesn’t eat enough, they turn into a zombie-cat. Zombie-cats chase mice and other cats. They can eat a mouse, but if they eat a cat, that cat turns into a zombie-cat!

You’re job in this lab is use good OOP to design this simulation. You will do this in two parts.

A tour of the starter code #

In the repository, you are provided with the following Java files that you should review. They are heavily commented, and will provide the guide posts for completing this project. Not all details are described here, so I strongly encourage you to read through the entirety of the code provided for you. #

An abstract class that represents a creature in the simulation. You’ll need to realize this class for your mice, cats, and zombie cats. #

This class represents the city/space in which the creatures live. There are two primary java collections that maintain the state of the simulation

    private List<Creature> creatures; //list of all creatues
    //Map of GridPoint to a list of cratures whose location is that grid point 
    private HashMap<GridPoint,List<Creature>> creatureGrid; 

The creatures is a full list of all the active creatures in the simulation. the creatureGrid is a map that connects the GridPoint (a row/col location in the city) to a list of creatures currently at that location. It’s important that these data structures remain consistent, otherwise you’re simulation will go pear-shaped.

Importantly, the City class as a method simulate that describes the primary routine of each iteration off the simulation. You cannot edit this method, but you should review it carefully because it will dictate how you design your other classes.

To highlight one part of the simulate routine, you’ll notes the following loop.

        //For every creature determine if an action should be taken
        // such as, procreating (mice), eating (cats, zombiecats), or
        // some new action that you'll add to the system.
        for(Creature c : creatures){

In each iteration, every creature has a chance to take an action. That action could be to eat (or remove) another creature (e.g, cats eat mice) or to add anew creature (e.g., a cat becomes a zombie cat). But, you can’t modify the creatures list while iterating over it.

So the City maintains two queues of pending actions, and the following accessor methods.

    private Queue<Creature> rmQueue; //creatures that are staged for removal
    private Queue<Creature> addQueue; //creatures taht are staged to be added    
    //stage a create to be removed
    public void queueRmCreature(Creature c){
        //DO NOT EDIT

    //Stage a creature to be added
    public void queueAddCreature(Creature c){
        //DO NOT EDIT

Your code will add to these queues during different parts of these simulation to stage a removal or addition of a creature. Then there is a third method, clearQueue() that actually completes these actions. You will need to implement clearQueue() as part of this assignment. #

This class has the main method for the simulation. You may need to do minor modifications to this while editing and to meet the requirements of the assignment. #

This class implements a row/column pair that can be used as a key in a map. You should read this class, but you will not need to edit it.

Running, Visualization and debugging your simulation #

Like in Lab 6, we will separate the simulation from visualization.

Simulating #

You can run the simulator with the following arguments:

                      .-- Number of rounds to simulate
                      |    .- The seed of the random number generator
                      v    v
java Simulator 8 2 0 1000 42 
               ^ ^ ^
               | | '-number of inital zombie cats
               | '- number of initial cats
               '- number of initial mice

The output of the simulator is a series of x and y coordinates describing the locations of each of the creatures. It may look like below:

37 48 r
74 43 k
20 32 r
50 59 r
5 21 c
4 24 b
75 54 b
49 53 r
5 46 b
74 53 c
done 930

Like in Lab 6, the first two numbers are a coordinate, and the letter is a color. Once complete, the done command is given. Different from Lab 6, done also outputs the round number.

Optionally, you can include --DEBUG as the final argument, like below, if you want to iterative step through the simulation

$ java Simulator 8 2 0 1000 42 --DEBUG
42 10 b
50 3 b
38 66 b
63 13 b
53 76 b
55 32 b
48 23 b
27 23 b
43 43 y
27 20 c
done 1
Enter anything to continue: 
41 10 b
50 2 b
38 67 b
64 13 b
54 76 b
54 32 b
47 23 b
28 23 b
45 43 y
27 22 c
done 2
Enter anything to continue: 

A quick note about the simulation space. It’s a torus. That means when you go off one edge, you wrap around to the other edge of the board. You can see this in the animation above. Your code should account for that.

Visualizing #

Like in Lab 6, we’ve provided a plotting tool Plotter.jar which you can pipe your output to, like so

java Simulator 8 2 0 1000 42| java -jar Plotter.jar

This will open a visual, like the animation above. There are two arguments you can provide to the plotter.

Simulation GIF

Note that you can combine these two arguments, but you must set the millis first, and then the debug flag.

java -jar Plotter.jar 42 --DEBUG

Requirements #

Part A : UML Diagram (25 Points) #

For Part A, you must complete the following items and submit them via github

  • UML.png : Create UML diagram for your simulation code, visualize it, and save it as a file UML.png
  • : Complete the markdown file that describes your OOP design and class structure.

After you submit Part A, the teaching staff will provide feedback on your design in the form of a github issue. You must respond to this feedback and update your UML diagram and OOP design document when submitting Part B.

Part B: Implementation (75 Points) #

There are different levels of implementation you should complete. Note that in file, you must indicate which level you reached. You should submit working code up to one level. It is very difficult to provide partial credit for semi-working code that doesn’t fully achieve one of the levels.

Level 0: Mice (up to 35 points) #

Full implement mice actions such that:

  • After 20 rounds of simulation time, a mouse produces a new baby mouse at the same location
  • A mouse dies after 30 rounds simulation time
  • A mouse randomly turns, changes directions 20% of the time
  • A mouse is displayed as a blue dot.

Level 1: Mice and Cats (up to 45 points) #

Add a cat to the simulation

  • A cat eats a mouse if they end up on the same location. That is, the mouse should die and be removed from the simulation.
  • If a cat doesn’t eat a mouse within 50 moves, the cat dies.
  • Cats jump two spaces at a time. They do not traverse the grid point they jump over. That is, if they are on space (1,2) they would move to (1,4).
  • Cats randomly turn, change direction, 5% of the time.
  • Cats are displayed as a yellow dot.

Additionally, in your simulator, have it such that

  • Every 100 rounds, a mouse is added to a random location in the city
  • Every 25 round, a cat is added to a random location in the city

Level 2: Cats chase mice (up to 55 points) #

In this level, cat’s get a bit smarter …

  • A cat searches up to 20 grid points (as measured by the GridPoint.distance() method) for a mouse to chase.
  • If the cat finds a mouse, it moves towards the mouse and is displayed using the color cyan. (This is to make it easier for you to debug, and for us to grade).
  • If the cat cannot find a mouse, it moves normaly and is displayed in yellow.

Level 3: Zombie-Cats chase Cats and Mice (up to 65 points) #

Let’s add zombie cats to the mix!

First a modification to Cats:

  • If Cat does not eat within 50 rounds, they instead turn into a Zombie Cat.

Now let’s define Zombie Cats:

  • Zombie cats chase both mice and other non-zombie cats
  • Zombie cats can search up to 40 gird squares away (as measured by GridPoint.distance()
  • Zombie cats eating a mouse is the same as a normal cat. The mouse dies and is removed from the simulation.
  • When a zombie cat eats a cat, that cat becomes a zombie cat placed at the same location in the grid square
  • A zombie cat when not chasing another creature is displayed as red dot.
  • A zombie cat chasing another creature is displayed as a black dot
  • A zombie cat jumps 3 spaces at time. It does not move through the intervening space. That is, if it is at (5,10) it moves directly to (5,13).
  • A zombie cat that doesn’t eat anything within 100 rounds dies.

Level 4: Create a new creature type (up to 75 points) #

The final level of the simulation is for you to add a new creature of any type or behavior you want to the simulation. It should fit into the general model of creatures we already have and derive from Creature.

You should include this extra creature in the planning stage (Part A of the project), and fully describe its functionality in the file.

Particularly creative creatures will be entered into a class-wide competition for eligible for a +5 point bonus, as voted on by your peers.