Java GUI Game of Life (and Death) - 41754

Solution Posted by

Rating : (19)A+
Solution Detail
Price: \$30.00
Request Description

D Assignment 1 : Game of Life (and Death)

* If the cell is Empty then * If it is adjacent to at least two Foods, * it will become Food next turn *

Otherwise it will stay as it was. * * If the cell is a Grazer then * If the Grazer is overcrowded or starved *

then it will die next turn. * Otherwise it will stay as it was. * * If the cell is a Food then * If it is next to at

least 2 Grazers * then it will become a Grazer next turn * Otherwise it will stay the same

The Skeleton

On the next few slides I will go through the Skeleton:

• The Livable interface;

• The World class, in which you put your code;

• The LifeAndDeath class, in which you also put code;

• The VisualTest class, which runs a visualiser just for your entertainment.

please see the attached skeleton code

Summary: Write a program to simulate a population of grazers and food in a simple 2D world,

similar to Conway’s classic Game of Life. For the sake of this assignment, food and grazers are both

creatures. This is an example of using cellular automata.

Each tick of the clock, the next state of the cell will be determined by its current state and the states

of its neighbours, according to the following rules:

1. If the cell is EMPTY:

If it is adjacent to at least two Foods, it will become Food next turn;

Otherwise it will stay as it was.

2. If the cell is a Food:

If it is next to at least two Grazers then it will become a Grazer next turn; Otherwise it will stay as

it was.

3. If the cell is a Grazer:

If the Grazer is overcrowded or starved then it will die next turn (and the cell will become empty);

Otherwise it will stay as it was.

Overcrowded means there aremore than 3 adjacent cells of the same kind as this one.

Starved means, for a predator, that there is no food in any adjacent cell.

We will represent food with dots ‘.’ and grazers with ‘@’. Here’s an example of what you might see if

you run the Visualiser with your (correct) code:

The programmust be called LifeAndDeath.

The program must have the class LifeAndDeath.java which contains the main method, and another

class file called World.java which implements the Livable interface. You must put all your own

code (not the Livable interface) into a package called assignment1.

The World class must have a constructor that takes as its arguments the size of the grid, the probability

(as a double) of each cell initially containing food, and the probability (as a double) of each cell

initially containing a grazer, like this:

1 public World (int size , double probFood , double probGrazer ) {

2 // ... fill in this

3 }

Do not change the Livable interface in any way.

The programmust be able to be run as follows:

java LifeAndDeath 25 0.1 0.2 100

Which would create a 25£25 grid of cells, and each cell would have a probability of 0.1 of being a

grazer or of 0.2 of being food (so probability of 0.7 of being empty). The program should run with the

above arguments for 100 ticks of the clock or until everything dies.

The LifeAndDeath program should print out the grid as above with each grid on a new line (not

side by side as I showed in the last part of the example).

If the program is given another argument, the string “summary” as the last String, then it should

only print out the total number of creatures after each tick of the clock, not the whole grid.

*marking

The marking will be partly by automatic testing of the methods you made to implement the Livable

interface, and partly by hand.

The hand-marking criteria are the same as for the Tasks:

Clarity up to 1 mark for good clear layout, sensible variable and method names, and good commenting;

Design up to 2 marks for the overall design of how your methods relate to each other, their logic, effective

code re-use, and appropriate use of access modifiers public, private and protected;

Error handling up to 2 marks for effectively dealing with run-time errors that could arise through exception

handling and checking for “corner cases” (e.g. checking coordinates are valid);

The auto-marking criteria are:

Unit testing up to 5 marks for testing the methods in Livable, implemented in your World class.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Testing The automatic testing will test each method you have to implement, and will test that your

World constructor works correctly. It will call the methods given in the skeleton code and compare the

return values with what is expected.

Automatic testing is worth 5 marks for this Assignment

Solution Description

Java GUI Game of L

Attachments