Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have been hired by Yellowstone National Park to implement Conways Game of Life (https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) because they believe that this game might provide some insight

You have been hired by Yellowstone National Park to implement Conways 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. Conways game begins with the creation of a random, two-dimensional matrix containing only 0 and 1, and the matrix is meant to represent a two-dimensional surface that contains open spots, i.e., the 0 spots, and spots occupied by microbes, i.e., the 1 spots. The code below creates a two-dimensional matrix (size is numX by numY) of zeros and ones, and then uses matplotlibs 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.__________(____) # fill in the blanks to create a new figure

# for each iteration through the loop

plt.spy(x, markersize=10) # plots the pattern each cycle/iteration

name = Biomat Iteration# + str(iter+1)

plt.title(name)

Youve been hired to implement the rules of Conways 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 forloop (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,J] + 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! 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). 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.

Hint: We are not exactly implementing Conways 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 Conways Game of Life, it will probably implement this original algorithm, which is not correct here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions