Due: Friday September 15, 2017 @ 8:00PM
The Game of Life simulates organisms that inhabit an area. The organisms reproduce and die out according to rules based on population density. The area is modeled in a 2D matrix with each entry in the matrix representing a cell in the living area. Time advances in discrete time units. At each time advance some new organisms may be born and existing ones may die. Existing organisms may die due to overcrowding or isolation. New ones are born when nearby cells reflect an appropriate population density. You can see a simulation of the game here.
The game is thus parameterized by the particular population density ranges that allow organisms to be born or to continue to thrive. Each cell has eight neighbors (above, below, left, right, and four diagonals). Thus, if you count the cell as well, there are nine cells in its neighborhood. For a birth to occur, the cell must be empty and the neighborhood density be in the birth range. The birth range can be given as two integers from 1
to 9
, birthLow
and birthHigh
, so that a birth will occur if the cell is empty and the neighborhood population is at least birthLow
and no more than birthHigh
. Similarly, a death occurs in a cell if there is an organism there and the neighborhood has less than the minimum population for survival, or greater than the maximum. Hence there is a live range provided as two integers from 1
to 9
, liveLow
and liveHigh
.
The border of the area is not compatible with life, so the top and bottom rows and the left and right columns will never have organisms. This part of the assignment will simply initialize and print the values for a start state in the game of Life. You do NOT have to implement the FULL GAME in this phase.
Your program will read the parameters from standard input. This part of the program will have THREE inputs in the following order:
int
)int
)long
)You are to construct a 2D matrix of booleans of the given size. You should fill the matrix with false
values. Then create a Random
object initialized with the provided seed and fill the interior of the matrix row by row from left to right within each row. Do not place a new value in the first or last row, or the first or last column of the matrix as they may not contain an entity (and hence should remain false
). You should use the nextBoolean
method of the Random
object to get each value. This will generate a matrix in which each value (other than on the edge) is equally likely to be true
or false
.
Finally, print the matrix by printing a -
character for each false and a #
for each true. Include the outside rows and columns in the printing. Print a space after each -
character or #
character
Life
for grading and compatibility with later assignments. If you do not do this, you will not receive a good gradepublic static
methods with appropriate parameters in this assignment. Remember that each function should do ONE thing and do one thing well. You should not use any non-local (class or instance) variables.for
loops have appropriate bounds?6 8
7
- - - - - - - -
- # # # - - - -
- # # # # - # -
- - - # # - # -
- # - # - # # -
- - - - - - - -
Submit this as the Lab 1a: Matrix lab through Autolab
35 points total