Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import time
- old_grid = [[0 for x in range(9)] for y in range(9)]
- # for i in range(0, 9):
- # for j in range(0, 9):
- # old_grid[i][j] = random.randrange(0, 2)
- old_grid[5][5] = 1
- old_grid[5][6] = 1
- old_grid[5][7] = 1
- new_grid = old_grid.copy()
- print(old_grid)
- def wrapindex(i, i_max):
- return (i_max + (i % i_max)) % i_max
- while 1:
- for x in range(0, 9):
- for y in range(0, 9):
- neighbors = old_grid[wrapindex(x-1, 9)][wrapindex(y+1, 9)] + old_grid[wrapindex(x+1, 9)][wrapindex(y+1, 9)] + old_grid[wrapindex(x+1, 9)][wrapindex(y+ 1, 9)] + \
- old_grid[wrapindex(x-1, 9)][wrapindex(y, 9)] + 0 + old_grid[wrapindex(x+1, 9)][wrapindex(y, 9)] + \
- old_grid[wrapindex(x-1, 9)][wrapindex(y-1, 9)] + old_grid[wrapindex(x+1, 9)][wrapindex(y-1, 9)] + old_grid[wrapindex(x+1, 9)][wrapindex(y-1, 9)]
- if neighbors == 3 and new_grid[x][y]== 0 :
- new_grid[x][y] = 1
- elif neighbors == 2 and new_grid[x][y]==1 :
- new_grid[x][y] = 1
- elif neighbors > 3:
- new_grid[x][y] = 0
- elif neighbors < 2:
- new_grid[x][y] = 0
- print(new_grid[x][y], end='')
- time.sleep(0.25)
- print()
- temp = old_grid[x][y]
- old_grid = new_grid.copy()
- print('\n')
- time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement