Skip to content

Instantly share code, notes, and snippets.

@Joseph94m
Last active March 24, 2019 12:45
Show Gist options
  • Save Joseph94m/48b05d5c089581253eb153610483f7b7 to your computer and use it in GitHub Desktop.
Save Joseph94m/48b05d5c089581253eb153610483f7b7 to your computer and use it in GitHub Desktop.
Sparse game of life rules
class SparseSetRules(Rule):
def apply_rules(self, grid, max_size,get_neighbours):
#grid = state.grid
counter = {}
for elem in grid:
if elem not in counter:
counter[elem]=0
nb = get_neighbours(elem, max_size)
for n in nb:
if n not in counter:
counter[n] = 1
else:
counter[n] += 1
for c in counter:
if (counter[c] < 2 or counter[c] > 3) :
grid.discard(c)
if counter[c] == 3:
grid.add(c)
return grid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment