This is Exercise 2.4 the text. Write a multi-class sequential Java program that simulates the game of life. The simulation occurs on an M-by-N rectangular array of cells. Each cell has only two values: 0 and 1. Each cell has eight neighbors: up, down, left, right, and four diagonally. Cells on the four edges of the grid have fewer than eight neighbors, of course. If the grid is declared as
int[][] grid = new int[N][N];then the neighbors of an interior cell grid[i][j] are
grid[i-1][j], grid[i+1][j], grid[i][j-1], grid[i][j+1], grid[i-1][j-1], grid[i-1][j+1], grid[i+1][j-1], grid[i+1][j+1]
The game works like this. Fill the grid with the initial values. Then for each cell in the grid, compute the new value that the cell becomes in the next generation of the game. All changes occur simultaneously, called a generation.
The input data to your Java program is
Here are some sample input data sets to try. This initial population dies out.
0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0This initial population dies more slowly.
0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0This initial population reaches a stable state.
0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0This initial population oscillates.
0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0
Animate your program using XtangoAnimator.