This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conway.py
68 lines (60 loc) · 2.42 KB
/
conway.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
#!/usr/bin/python
import Conway.GameOfLife
import time
import sys
def pattern_toad():
return [ [0, 0, 0, 0, 0], \
[0, 1, 1, 1, 0], \
[1, 1, 1, 0, 0], \
[0, 0, 0, 0, 0], \
[0, 0, 0, 0, 0]]
def pattern_pulsar():
return [ [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0], \
[0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0], \
[0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0], \
[0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0], \
[0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0], \
[0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0], \
[0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ]
def pattern_glider():
return [ [0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], \
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ]
def print_and_wait(text):
print( chr(27)+"[2J" + text)
sys.stdout.flush()
time.sleep(1)
def main():
raw_universe = pattern_toad()
game = Conway.GameOfLife.Game(raw_universe)
print_and_wait(game.show_universe(''))
for i in range(50):
game.next_step()
print_and_wait(game.show_universe(''))
# Standard boilerplate to call the main() function.
if __name__ == '__main__':
main()