-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.py
39 lines (34 loc) · 1.02 KB
/
board.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from random import randint, choice
class Board(object):
"""create game of life arena"""
def __init__(self, num=100):
"""initialize the arena"""
self._sidelen = num
self._size = num**2
self.board = []
self.errors = 0
for i in range(num):
row = []
for j in range(num):
col = [0]
row.append(col)
self.board.append(row)
def show(self):
"""shows the board"""
for i in range(self._sidelen):
chars = ""
for j in range(self._sidelen):
if self.board[i][j][0] == 1:
chars = chars+"#"
else:
chars = chars+"."
print(chars)
def toggle_val(self, row, col):
"""flips the value of an entry"""
x = self.board[row][col][0]
if x == 0:
self.board[row][col][0] = 1
elif x == 1:
self.board[row][col][0] = 0
else:
self.errors += 1