Dawson Community College Programming & Coding Worksheet

You have been hired by Yellowstone National Park to implement Conway’s ‘Game of Life'(https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) because they believe that this ‘game’ might provide
some insight into the development of patterns in microbial mats in the various hot-springs. Conway’s game
begins with the creation of a random, two-dimensional matrix containing only ‘O’ and ‘1’, and the matrix is
meant to represent a two-dimensional surface that contains open spots, i.e., the ‘O’ spots, and spots occupied
by microbes, i.e., the ‘l’ spots. The code below creates a two-dimensional matrix (size is numX by numy) of
zeros and ones, and then uses matplotlib’s spy() function to plot the matrix.
import matplotlib.pyplot as plt
import numpy
numX, numY = 20, 20
x = numpy.random.randint(0,2, (numX, numy)) # Initial population
for iter in range(3):
# iterate through 3 growth/death cycles
# Your code should go here!
plt. figure(iter) # create a new figure for this iteration
plt.spy(x, markersize=10) # plots the pattern each cycle/iteration
=
You’ve been hired to implement the rules of Conway’s Game of Life so that the final plot reflects the population
after 3 growth/death cycles (i.e., 3 iterations). Each iteration (i.e., inside the 3 iteration loop), your code should
go through each spot on the surface (i.e., each entry in the matrix) except for the outer edges using a double for-
loop (e.g., for J in range(numY-1):, then a second loop inside this loop, for I in range(numX-1):). For each spot,
count the number of living neighbors (above, below, left, and right). The total sum of neighbors must be in the
range 0-4, and, since each spot is either a 0 or 1, just adding the values of the four neighbors will tell you the
total number of neighbors. YNP recommends, for example:
neighbors X[I-1,3] + x[I+1,J] + x[I,J-1] + x[I,J+1]
Once the number of neighbors is calculated, you can implement the rules of the Game of Life (see wikipedia)
using ‘if’ statements. For rule #1, which states that any living microbe on a spot dies if it has less than 2 living
neighbors, an if-statement would be:
if neighbors < 2 and x[I,J] == 1: x[I,J] = 0 # Oh no! It died ! Please write a memo to Yellowstone National Park summarizing the algorithm you developed, describe the results, including at least one output plot, and, finally, including you code in the appendix. Rule #2 states that if the number of neighbors is greater than 3, the spot dies from starvation. The third and final rules states that if there are exactly 3 neighbors, the spot should be occupied (i.e., set to 1). Hint: We are not exactly implementing Conway's Game of Life because we are skipping the outer edges and we are updating the matrix as we step through it. The original algorithm updated every spot simultaneously. If you try to copy some online Python code for Conway's Game of Life, it will probably implement this original algorithm, which is not correct here, and you will be committing academic misconduct so please do not copy it.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER