2015-06-01 12:45:23 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
@author: jrpotter
|
|
|
|
@date: June 01, 2015
|
|
|
|
"""
|
2015-06-01 00:58:09 +00:00
|
|
|
|
2015-06-01 12:30:00 +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
|
|
|
|
"""
|
2015-06-01 12:30:00 +00:00
|
|
|
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
|
|
|
|
|
2015-06-01 02:19:50 +00:00
|
|
|
c = cam.CAM(1, (100, 100))
|
2015-06-01 00:58:09 +00:00
|
|
|
c.randomize()
|
|
|
|
r = rs.Ruleset(rs.Rule.SATISFY)
|
2015-06-01 12:30:00 +00:00
|
|
|
n = nh.Neighborhood.moore(c.master, True)
|
|
|
|
c.start_plot(100, r, n, game_of_life)
|