Question
I hope someone can help with this java-assignment: This assignment is about Conways Game of Life . Game of Life is a simple grafical simulation,
I hope someone can help with this java-assignment:
This assignment is about Conways Game of Life. Game of Life is a simple grafical simulation, where the user indicates the initial state and can then follow the development of the conditions.
In game of Life a condition is a n*n grid of fields called cells, where each cell can either be dead or alive. To visualize a condition a dot is drawn at (x,y) hvis the cell is alive (a dead cell is not marked).
Each cell has 8 neighbors as illustrated in figur below. On the background of a condition, the next condition is found by the following rules:
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.
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.
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 p 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started