Last active
March 24, 2019 12:45
-
-
Save Joseph94m/48b05d5c089581253eb153610483f7b7 to your computer and use it in GitHub Desktop.
Sparse game of life rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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