Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Current Question Finally, we will model how the game evolves over time in a single plot. Modify your code from the previous step. Instead of

Current Question

Finally, we will model how the game evolves over time in a single plot.

Modify your code from the previous step. Instead of storing the time steps as separate elements in a list, each time step should be added to an accumulator array pd_time. This will give us a "heat map" of how the system has evolved over time. Use pentadecathlon again.

pentadecathlon = np.zeros( ( 24,24 ) ) pentadecathlon[ 10:20,10 ] = 1 pentadecathlon[ 12, 9 ] = 1 pentadecathlon[ 12,10 ] = 0 pentadecathlon[ 12,11 ] = 1 pentadecathlon[ 17, 9 ] = 1 pentadecathlon[ 17,10 ] = 0 pentadecathlon[ 17,11 ] = 1 

Starter Code

import numpy as np import matplotlib.pyplot as plt pentadecathlon = np.zeros( ( 24,24 ) ) pentadecathlon[ 10:20,10 ] = 1 pentadecathlon[ 12, 9 ] = 1 pentadecathlon[ 12,10 ] = 0 pentadecathlon[ 12,11 ] = 1 pentadecathlon[ 17, 9 ] = 1 pentadecathlon[ 17,10 ] = 0 pentadecathlon[ 17,11 ] = 1 pd_time = ??? evoln = pentadecathlon[ : ] nt = 30 for t in ???: ??? # evolve the system forward in `evoln` pd_time += evoln plt.imshow( pd_time ) plt.show()

Previous Question for reference

Now that we have a working evolve function, we can carry out longer-term simulations of the Game of Life. (If you haven't gotten evolve to work yet, we provide it for this step.)

Consider a wrapper loop that will simulate a glider traveling for nt time steps:

import numpy as np import matplotlib.pyplot as plt glider = np.zeros( ( 24,24 ) ) glider[ 10,10 ] = 1 glider[ 11,10 ] = 1 glider[ 12,10 ] = 1 glider[ 12,11 ] = 1 glider[ 11,12 ] = 1 nt = 10 for t in range( nt ): cells = evolve( cells ) plt.imshow( cells ) plt.show() 

Write a program which implements a loop evolving pentadecathlon for thirty time steps. You should implement a list of ndarrays named pd_list, each containing a single generation of pentadecathlon's evolution.

pentadecathlon = np.zeros( ( 24,24 ) ) pentadecathlon[ 10:20,10 ] = 1 pentadecathlon[ 12, 9 ] = 1 pentadecathlon[ 12,10 ] = 0 pentadecathlon[ 12,11 ] = 1 pentadecathlon[ 17, 9 ] = 1 pentadecathlon[ 17,10 ] = 0 pentadecathlon[ 17,11 ] = 1

import numpy as np import matplotlib.pyplot as plt

pentadecathlon = np.zeros( ( 24,24 ) ) pentadecathlon[ 10:20,10 ] = 1 pentadecathlon[ 12, 9 ] = 1 pentadecathlon[ 12,10 ] = 0 pentadecathlon[ 12,11 ] = 1 pentadecathlon[ 17, 9 ] = 1 pentadecathlon[ 17,10 ] = 0 pentadecathlon[ 17,11 ] = 1

pd_list = [] pd_list.append( pentadecathlon ) nt = 30 for t in range(nt): pentadecathlon = evolve ( pentadecathlon ) pd_list.append( pentadecathlon ) # evolve the simulation and append it to `pd_list` plt.imshow( pd_list[ -1 ] ) plt.show()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions