求帮忙,看一下这个程序
能不能帮忙看一下这个程序为什么运行错误?主题是做一个wireworld,一种细胞自动机。
import matplotlib.pyplot as plt
import matplotlib.animation as animation
mur = 2
head = 1
taile =9
cond =0
def go(x,y):
if n[x][y-1]==head and n[x][y]==cond:
n[x][y]=head
n[x][y-1]=taile
n[x][y-2]=cond
def fin(x,y):
if n[x][-1]==1:
n[x][0]=head
n[x][-1]=taile
n[x][-2]=cond
def init():
return n
def update(*args):
for x in range(3):
for y in range(8):
if n[x][y-1]==head and n[x][y]==cond :
n[x][y]=head
n[x][y-1]=taile
n[x][y-2]=cond
if n[x+1][y]==3:
n[x][0]=head
im.set_array(n)
return im,
fin(x,y)
n=[[1,0,0,0,0,0,2,0],
[1,0,0,0,0,0,0,0],
[2,2,2,2,2,3,2,2]]
init()
fig = plt.figure()
im= plt.imshow(n,interpolation = "nearest")
ani = animation.FuncAnimation(fig,update,init_func=init,frames = 300,interval=2*500,blit = False)
plt.grid(True)
plt.show()