add: data generator

This commit is contained in:
h z
2025-01-29 21:24:10 +00:00
parent 34e9b95145
commit 05d375d521
5 changed files with 101 additions and 7 deletions

View File

@@ -15,6 +15,10 @@ class Board:
self.lives.add((x, y))
def evaluate(self):
new_lives = self.try_evaluate()
self.lives = new_lives
def try_evaluate(self) -> set[(int, int)]:
new_lives = set()
for (x, y) in itertools.product(range(self.width), range(self.height)):
neighbor_count = 0
@@ -33,5 +37,18 @@ class Board:
new_lives.add((x, y))
if (x, y) not in self.lives and neighbor_count == 3:
new_lives.add((x, y))
self.lives = new_lives
return new_lives
def __str__(self):
res = ""
for y in range(self.height):
for x in range(self.width):
if (x, y) in self.lives:
res += "o"
else:
res += " "
res += "\n"
return res
def __repr__(self):
return self.__str__()