Game of Life
In class we implemented the Game of Life on a finite world with square cells and wrap around (torus) geometry, using the Moore definition of neighbours.
This assignment is an extension of this model. We want to see how an initial population structure affects its growth/decay.
Task 1
Consider all possible initial populations that can fit into a \(4\times 4\) grid, and compute the following:
- What percentage of populations shrunk in size?
- What percentage of populations grow in size?
- Draw a histogram of the final population sizes.
- Of the populations that died out, what was the average number of stages need for population to die out?
- Of the populations that died out, draw a histogram of the number of stages for population to die out.
Outline of Implementation:
- Initial populations that fits into a \(4\times 4\) grid can be one-to-one identified with integers in \(0..2^{16}-1\).
So one way to construct initial population is to:
- Pick an integer in \(0..2^{16}-1\)
- Convert to binary and prepend "0" so has 16 digits.
- Create
np.array
storing digits, and use .reshape
method to convert to a \(4\times4\) grid.
- Place population in desired position in
space
.
- To generate the required statistics have a loop that iterate over integers in \(0..2^{16}-1\).
- Initialise
space
.
- Create and place the initial population.
- Run simulation for the required number of stages (or until population dies/stop changing).
- Store results.
- Note this will take about 20 minutes, so test your code before running full loop.
- Used stored results to answer the given questions.
Task 2
Repeat Task 1 but replace the Moore neighbourhood with a Von Neumann neighbourhood (where diagonal cells are not included).
Outline of Implementation:
- The only change need is to redefine the function
count_neighbors
so that it uses the Von Neumann neighbourhood.
Task 3
Repeat Task 3 but replace Moore neighbourhood with a Von Neumann neighbourhood (where diagonal cells are not included) of radius 2. So the two cells to the left, to the right, above, and below are treated as neighbours.
Outline of Implementation:
- Again, the only change needed is a redefinition of
count_neighbors
.
Deliverable
Upload a notebook with completed tasks to Moodle using the link below.