Mar-23-2020, 05:27 PM
Hello !
I have a problem with my game of life. To move from one step to the next, I execute this code :
Could you please help me ? Thanks you very much !
I have a problem with my game of life. To move from one step to the next, I execute this code :
import numpy as np def pulsar(): X = np.zeros((17, 17)) X[2, 4:7] = 1 X[4:7, 7] = 1 X += X.T X += X[:, ::-1] X += X[::-1, :] return X p=pulsar() grid=np.zeros([22,22]) for i in range(np.shape(p)[0]): for j in range(np.shape(p)[1]): grid[i+int((np.shape(grid)[0]-np.shape(p)[0])/2)][j+int((np.shape(grid)[1]-np.shape(p)[1])/2)]=p[i][j] class game_of_life(): def __init__(self): self.automaton() def automaton(self): new=np.zeros_like(grid) l=np.shape(new)[0] c=np.shape(new)[1] for i in range(l): for i in range(c): if l-1>=0 and c-1>=0 and l+1<=np.shape(new)[0] and c+1<=np.shape(new)[1]: sum_n=grid[l-1][c-1]+grid[l-1][c]+grid[l-1][c+1]+grid[l][c+1]+grid[l+1][c+1]+grid[l+1][c]+grid[l+1][c-1]+grid[l][c-1] if grid[l][c]==0 and sum_n==3: self.new[l][c]=1 if grid[l][c]==1: if sum_n>3: self.new[l][c]=0 elif 2<=sum_n<=3: self.new[l][c]=1 elif sum_n<2: self.new[l][c]=0 print(new) game_of_life()The problem is that my new array is full of zeros !
Could you please help me ? Thanks you very much !