Note that there are some explanatory texts on larger screens.

plurals
  1. POConway's Life: Iterate over a closed universe in Python
    primarykey
    data
    text
    <p>I have just started learning Python, and I'm trying to write a program for Conway's Game of Life. I'm trying to create a closed universe with boundary conditions(which are the opposite side/corner). I think I have done this, but I'm not iterating over the loop when it runs, and can't work out how to do this. Thanks very much in advance!</p> <pre><code>def iterate_conway_closed(universe_t0, n_iter=1, display=False): # This function is similar to your iterate_conway_open function # but instead of adding a zero guard ring it should add a # ‘wrapping ring’ as explained earlier. Use the same apply_rules # function as part 1) to actually apply the rules once you have # padded the universe. # Note that unlike the always 0 guard ring for an open universe # the wrapping ring will need updating after every call to # apply rules to reflect changes in the universe height, width=universe_t0.shape universe_array=numpy.zeros((height+2, width+2), dtype=numpy.uint8) universe_array[1:-1, 1:-1]=universe_t0 def count(n_iter): n=0 while n&lt;= n_iter: yield n n+=1 for n in range(0,n_iter): universe_array[:1,1:-1]=universe_t0[-1:,:] # Maps the bottom row universe_array[0,1:-1]=universe_t0[-1:,0:]# Maps the top row universe_array[1:-1,0]=universe_t0[:,0]# Maps the left column universe_array[1:-1,-1]=universe_t0[:,-1]# Maps the right column universe_array[0,0]=universe_t0[-1,0]# Maps the bottom left corner universe_array[0,-1]=universe_t0[-1,-1]# Maps the bottom right corner universe_array[-1,0]=universe_t0[0,0]# Maps the top left corner universe_array[-1,-1]=universe_t0[0,-1]# Maps the top right corner for i in range(0, n_iter): universe_array=apply_rules(universe_array) if display==True: b_print(universe_array) return universe_array[1:-1, 1:-1] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload