r
/
fifth
1
Fork 0
fifth/examples/life.py

39 lines
828 B
Python
Raw Normal View History

2015-06-01 12:45:23 +00:00
"""
@author: jrpotter
@date: June 01, 2015
"""
2015-06-01 00:58:09 +00:00
def game_of_life(coordinate, grid, neighbors):
2015-06-01 00:58:09 +00:00
"""
Rules of the Game of Life.
Note we ignore the second component of the neighbors tuples since
life depends on all neighbors
"""
total = sum(map(lambda x: x[1], neighbors))
if grid[coordinate]:
2015-06-01 00:58:09 +00:00
if total < 2 or total > 3:
return False
else:
return True
elif total == 3:
return True
else:
return False
if __name__ == '__main__':
2015-06-01 12:45:23 +00:00
import os, sys
sys.path.append(os.path.abspath('src'))
import cam
import ruleset as rs
import neighborhood as nh
c = cam.CAM(1, (100, 100))
2015-06-01 00:58:09 +00:00
c.randomize()
r = rs.Ruleset(rs.Rule.SATISFY)
n = nh.Neighborhood.moore(c.master, True)
c.start_plot(100, r, n, game_of_life)