Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java program that implements Conways Game of Life, where StdDraw is used to visualize how the conditions change, creating an animation. You should

Write a java program that implements Conways Game of Life, where StdDraw is used to visualize how the conditions change, creating an animation. You should implement the solution using at least two classes: GameOfLife og GameOfLifeMain.

1. Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.

2. Any live cell with two or three live neighbours lives on to the next generation.

3. Any live cell with more than three live neighbours dies, as if by overpopulation.

4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

The class GameOfLife should define GameOfLife-objects that represents a condition in a GameOfLife simulation. The class has to have methods to manipulate the conditions, fx change the value of a cell, simulate a step forward ect. In the class GameOfLife the condition is represented in a 2-dimensional array of integers (int[][]), where 1 indicates a living cell and 0 indicates a dead cell. Hence the game is represented by a matrix.

Your GameOfLife-class must at least have the two constructors:

public GameOfLife(int n). A constructor to generate a Game of Life with the startcondition being a n times n grid of randomly initialized cells.

public GameOfLife(int[][] initialState). A constructor to generate a Game of Life with the startcondition being represented in the array initialState

You will also need to use several methods on the pa GameOfLife-objects. There should be a method nextState() that generates the following condition in the current GameOfLife. When writing the method nextState() it can be a help to create another method liveNeighbours(int x, int y) which counts how many living neighbours the cell (x,y) has i in the current game.

The class GameOfLifeMain have the main method, which initializes a GameOfLife-object and uses the methods related to the object. To ensure the animation runs smoothly, you should use the method StdDraw.show(n), where n is an integer. This method draws the image og waits n milliseconds. Following calls of drawing methods will not be shown until next call of StdDraw.show(n). The method StdDraw.clear() can be used to erase the drawn.

Finally the class GameOfLifeMain should be able to read the starting conditions from a file (.gol). The format of the file is a matrix consisting of ones and zeros fx.

image text in transcribed

100

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

define what is meant by the term human resource management

Answered: 1 week ago