Question: You will write a Java program that implements Conways Game of Life, a simple cellular automaton. See for example: http://www.bitstorm.org/gameoflife/ Our version has a 10

You will write a Java program that implements Conways Game of Life, a simple cellular automaton. See for example: http://www.bitstorm.org/gameoflife/ Our 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 2dimensional 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 nonnegative integers (stop when a negative integer is read for either i or j) Initialize the grid based on the (i,j) pairs entered by the user (set the corresponding array elements to 1) Prompt the user to enter the number of time steps Display the initial state of the grid (call the displayGrid() method) For each time step, update the grid according to Conways rules (call the updateGrid() method) display the grid (call the displayGrid() method) We follow Conways standard rules for updating the cells, as follows. A neighbor is a vertically, horizontally, or diagonally adjacent cell that is populated. A cell has anywhere from 0 to 8 neighbors. For a cell that is populated, if the cell has <= 1 neighbor(s), 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). The displayGrid() method has the following header: public static void displayGrid(int grid[][]) 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 the following header: public static void updateGrid(int grid[][]) grid is the 2dimensional array that contains the current state of the grid. The method counts the neighbors in each cell of the grid, and updates the cells in the grid according to Conways rules. Hint: As in Project 7, you will need to create a temporary array to do your updates into, and then copy its contents back into the original array. You can obviously enter arbitrary initial conditions to test your program. Some fun examples adapted from the bitstorm.org site: Glider: initial populated cells at (3, 4) (4, 2) (4, 4) (5, 3) (5, 4) 5 cell row: initial populated cells at (6,4) (6,5) (6,6) (6,7) (6,8) Small explosion: initial populated cells at (4, 5) (4,6) (5,4) (5,5) (5, 7) (6, 5) (6,6) Note that these will not behave exactly the same as the bitstorm.org display when the populated cells run into the boundary conditions. The updateGrid() method has the following header: public static void updateGrid(int grid[][]) grid is the 2dimensional array that contains the current state of the grid. The method counts the neighbors in each cell of the grid, and updates the cells in the grid according to Conways rules. Hint: As in Project 7, you will need to create a temporary array to do your updates into, and then copy its contents back into the original array. If its not too much trouble I'd love for someone knowledgeable in this to help me out here! Thx a lot! I just need help on the updateGrid() method part, I have done the rest fairly well!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!