-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.py
152 lines (139 loc) · 4.59 KB
/
module.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
'''
Colors...
White = 0
Black = 1
Grey = 2
'''
class Cell(object):
def __init__(self, row, column):
self.row = row
self.column = column
self.color = 2
#setup first cell of simulation
def StartSim(cells,rows, columns):
for row in range(0, rows):
for column in range(0, columns):
if cells[column][row].column != (columns // 2):
cells[column][row].color = 0
elif cells[column][row].row != 0:
cells[column][row].color = 0
else:
cells[column][row].color = 1
def RunSim(cells, rows, columns, rule):
for row in range(1, rows):
for column in range(0, columns):
ruleNumber = rule
if ruleNumber >= 128:
ruleNumber = ruleNumber - 128
if RuleEight(cells, row, column):
cells[column][row].color = 1
continue
if ruleNumber >= 64:
ruleNumber = ruleNumber - 64
if RuleSeven(cells, row, column):
cells[column][row].color = 1
continue
if ruleNumber >= 32:
ruleNumber = ruleNumber - 32
if RuleSix(cells, row, column):
cells[column][row].color = 1
continue
if ruleNumber >= 16:
ruleNumber = ruleNumber - 16
if RuleFive(cells, row, column):
cells[column][row].color = 1
continue
if ruleNumber >= 8:
ruleNumber = ruleNumber - 8
if RuleFour(cells, row, column):
cells[column][row].color = 1
continue
if ruleNumber >= 4:
ruleNumber = ruleNumber - 4
if RuleThree(cells, row, column):
cells[column][row].color = 1
continue
if ruleNumber >= 2:
ruleNumber = ruleNumber - 2
if RuleTwo(cells, row, column):
cells[column][row].color = 1
continue
if ruleNumber >= 1:
ruleNumber = ruleNumber - 1
if RuleOne(cells, row, column):
cells[column][row].color = 1
continue
print(columns, rows)
cells[columns - 1][rows-1].color = 2
def RuleOne(cells, row, column):
print('RuleOne')
try:
if cells[column-1][row-1].color == 0 and cells[column][row-1].color == 0 and cells[column+1][row-1].color == 0:
return True
else:
return False
except:
return False
def RuleTwo(cells, row, column):
print('RuleTwo')
try:
if cells[column-1][row-1].color == 0 and cells[column][row-1].color == 0 and cells[column+1][row-1].color == 1:
return True
else:
return False
except:
return False
def RuleThree(cells, row, column):
print('RuleThree')
try:
if cells[column-1][row-1].color == 0 and cells[column][row-1].color == 1 and cells[column+1][row-1].color == 0:
return True
else:
return False
except:
return False
def RuleFour(cells, row, column):
print('RuleFour')
try:
if cells[column-1][row-1].color == 0 and cells[column][row-1].color == 1 and cells[column+1][row-1].color == 1:
return True
else:
return False
except:
return False
def RuleFive(cells, row, column):
print('RuleFive')
try:
if cells[column-1][row-1].color == 1 and cells[column][row-1].color == 0 and cells[column+1][row-1].color == 0:
return True
else:
return False
except:
return False
def RuleSix(cells, row, column):
print('RuleSix')
try:
if cells[column-1][row-1].color == 1 and cells[column][row-1].color == 0 and cells[column+1][row-1].color == 1:
return True
else:
return False
except:
return False
def RuleSeven(cells, row, column):
try:
print('RuleSeven')
if cells[column-1][row-1].color == 1 and cells[column][row-1].color == 1 and cells[column+1][row-1].color == 0:
return True
else:
return False
except:
return False
def RuleEight(cells, row, column):
print('RuleEight')
try:
if cells[column-1][row-1].color == 1 and cells[column][row-1].color == 1 and cells[column+1][row-1].color == 1:
return True
else:
return False
except:
return False