add: data generator
This commit is contained in:
@@ -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__()
|
||||
Reference in New Issue
Block a user