Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, time, copy
- def printBoard():
- time.sleep(1)
- os.system('cls')
- for i in xrange(n):
- for j in xrange(n):
- if board[i][j] == 0:
- print " ",
- else:
- print "X",
- print
- def countLiveNeighbours(x, y):
- s = 0
- if board[x % n][(y + 1) % n] == 1:
- s = s + 1
- if board[x % n][(y - 1) % n] == 1:
- s = s + 1
- if board[(x - 1) % n][(y + 1) % n] == 1:
- s = s + 1
- if board[(x - 1) % n][y % n] == 1:
- s = s + 1
- if board[(x - 1) % n][(y - 1) % n] == 1:
- s = s + 1
- if board[(x + 1) % n][(y + 1) % n] == 1:
- s = s + 1
- if board[(x + 1) % n][y % n] == 1:
- s = s + 1
- if board[(x + 1) % n][(y - 1) % n] == 1:
- s = s + 1
- return s
- n = int(raw_input(" Unesite dimenzije table: "))
- board = [[0 for x in xrange(n)] for x in xrange(n)]
- copyBoard = copy.deepcopy(board)
- while True:
- i = int(raw_input(" x: "))
- if i == -1:
- break
- j = int(raw_input(" y: "))
- board[i][j] = 1
- copyBoard[i][j] = 1
- printBoard()
- while True:
- for i in xrange(n):
- for j in xrange(n):
- # print countLiveNeighbours(i, j)
- if countLiveNeighbours(i, j) < 2:
- copyBoard[i][j] = 0
- elif countLiveNeighbours(i, j) > 3:
- copyBoard[i][j] = 0
- elif (countLiveNeighbours(i, j) == 3 and board[i][j] == 0):
- copyBoard[i][j] = 1
- board = copy.deepcopy(copyBoard)
- printBoard()
- #break
- input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement