-
Notifications
You must be signed in to change notification settings - Fork 0
/
life.py
executable file
·51 lines (44 loc) · 1.2 KB
/
life.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from engine import GameEngine
from field import StandardField
from rules import next_generation_std, IterativeStopRule
def main():
""" Main entry function.
Tries to run some tests for now.
:returns: None.
"""
def print_field(field):
""" Prints the field to console window.
:field: a field to be printed.
:returns: None.
"""
sys.stdout.write("== State ==\n")
last_row = 0
for coord in field.cells_coords():
row = coord[0]
if row > last_row:
sys.stdout.write("\n")
last_row = row
if field.get_cell(coord):
sys.stdout.write("*")
else:
sys.stdout.write(" ")
sys.stdout.write("\n")
sys.stdout.flush()
# Make a simple test field
field = StandardField(5, 5)
field.set_cell((0,0), True)
field.set_cell((0,1), True)
field.set_cell((1,2), True)
field.set_cell((2,0), True)
field.set_cell((2,1), True)
field.set_cell((1,3), True)
field.set_cell((0,4), True)
field.set_cell((2,4), True)
# Run an engine
engine = GameEngine(next_generation_std, field, print_field)
engine.run_until_true(IterativeStopRule(6))
if __name__ == "__main__":
main()