# 蟒蛇 – 生活模式游戏不正确进行

>我分解了我的代码中的逻辑语句,以使用no和/或语句.
>我通过将我的邻居()函数插入到自己的程序中,并设置了一些网格配置.
>然后我看着打印出来的网格,我在某个位置打了个邻居().它工作得很好

```#Function to find number of live neighbors
def neighbors(row, column):

if row > 0:
if board[row-1][column]:
if column > 0:
if board[row][column-1]:
if row < thesize-1:
if board[row+1][column]:
if column < thesize-1:
if board[row][column+1]:

if row > 0 and column > 0:
if board[row-1][column-1]:
if row < thesize-1 and column < thesize-1:
if board[row+1][column+1]:
if row > 0 and column < thesize-1:
if board[row-1][column+1]:
if row < thesize-1 and column > 0:
if board[row+1][column-1]:

#Return the final count (0-8)

```#Main loop
while 1:

#Manage the rules of the game
for r in range(len(board)):
for c in range(len(board)):
neighborcount = neighbors(r, c)
if board[r][c]:
giveLife(r, c)
if neighborcount < 2 or neighborcount > 3:
board[r][c] = False
elif not board[r][c]:
killRuthlessly(r, c)
if neighborcount == 3:
board[r][c] = True```

```for r in range(len(board)):
for c in range(len(board)):
if board[r][c]:
giveLife(r, c)
if not board[r][c]:
killRuthlessly(r, c)```

giveLife是一个在给定位置绘制黑色矩形的函数,killRuthlessly绘制一个白色的矩形.这些都似乎正常工作.