Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will write a Java program that implements Conway’s Game of Life, a simple ce

ID: 3766306 • Letter: Y

Question

You will write a Java program that implements Conway’s Game of Life, a simple cellular automaton.

Our simplified version has a 10 x 10 grid, numbered like this:

0 1 2 3 4 5 6 7 8 9

        0

        1

        2

        3

        4

        5

        6

        7

        8

        9

The grid is represented by a 10 x 10 2-dimensional integer array. If the grid point (i, j) is “populated”, the array element [i][j] contains 1; otherwise it contains 0. Elements along the edges, i == 0 or 9, or j == 0 or 9, are always unpopulated.

When we display the grid, a populated cell is indicated by a ‘#’; an unpopulated cell is indicated by a space.

What your program should do:

            Prompt the user to enter a list of (i,j) pairs (both non-negative integers)

                        (stop when a negative integer is read for either i or j)

            Prompt the user to enter the number of time steps

            Initialize the grid based on the (i,j) pairs entered by the user

            Display the initial state of the grid

                        (call the displayGrid() method)

            For each time step,

update the grid according to Conway’s rules (call the updateGrid() method)

display the grid (call the displayGrid() method)

We follow Conway’s standard rules for updating the cells.

For a cell that is “populated”, if the cell has <= 1 neighbors, or > = 4 neighbors, it dies (becomes 0). Otherwise, it survives (remains 1).

For a cell that is not populated, if the cell has exactly 3 neighbors, it becomes populated (becomes 1).

Cells on the edge always remain unpopulated (0).

Some sample runs are shown in text files on libra in ~whsu/csc210/P8/.

The displayGrid() method has prototype:

     void displayGrid(int mat[][]);

It displays the borders of the grid (see sample runs below), and prints the 10 x 10 grid of cells. Populated cells are indicated with a ‘#’ sign, unpopulated cells with a space.

The updateGrid() method has prototype:

     void updateGrid(int mat[][]);

mat is the 2-dimensional array that contains the current state of the grid. The method counts the neighbors in each cell of the grid, updates the cells in the grid according to Conway’s rules, and returns the grid.

Explanation / Answer

CellState.java

This class implements a datatype for recording the state of a cell. It includes these methods:

The methods with static modifies are class methods. They are not invoked on an object (there is no this). Instead, call them as CellState.createAlive () and CellState.createDead ().

Cell.java

This class provides a basic Cell implementation. It includes these methods:

To produce cellular automata with interesting behavior, you will produce a subtype of the Cell class and override the getNextState method to do something more interesting.

ExtremeLifeCell.java

This class implements a cell that follows the Extreme Game of Life rules described above. We use extends Cell to indicate that the ExtremeLifeCell class is a subtype of Cell. This means it inherits the non-private methods from the Cell class. To implement a new cell behavior, we need to provide a new implementation of the getNextState method:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote