-
Notifications
You must be signed in to change notification settings - Fork 0
/
lifegame.py
61 lines (53 loc) · 1.25 KB
/
lifegame.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
import time
import sys
args = sys.argv
def ume(sta):
vsta = "00000000"
for i, char in enumerate(sta):
vsta += char
if i % 5 == 4:
vsta += "00"
vsta += "000000"
return vsta
def show(sta):
for i, char in enumerate(sta):
if char == '0':
print('□ ', end='')
else:
print('■ ', end='')
if i % 5 == 4:
print()
def daytime(vsta):
sur = ""
for turn in list(range(9, 14)) + list(range(16, 21)) + list(range(23, 28)) + list(range(30, 35)) + list(range(37, 42)):
count = 0
for p in [-8, -7, -6, -1, 1, 6, 7, 8]:
if vsta[turn-1+p] == '1':
count += 1
sur += str(count)
return sur
def night(sta, sur):
nsta = ""
for i, char in enumerate(sur):
if char == '2':
nsta += sta[i]
elif char == '3':
nsta += '1'
else:
nsta += '0'
return nsta
def main():
sta = args[1]
vsta = ume(sta)
gen = 1
while True:
print(f"gen {gen}")
gen += 1
show(sta)
vsta = ume(sta)
sur = daytime(vsta)
sta = night(sta, sur)
time.sleep(1.5)
print("="*15)
if __name__ == "__main__":
main()