Fix the lights-out easter egg.

This commit is contained in:
Yaro Kasear 2025-07-29 11:40:52 -05:00
parent 921400456e
commit e03988f28a
2 changed files with 9 additions and 7 deletions

View file

@ -13,11 +13,11 @@ def generate_solvable_matrix(level, seed_clicks=None):
matrix = [[True for _ in range(size)] for _ in range(size)]
def toggle(x, y):
for dx in [-1, 0, 1]:
for dy in [-1, 0, 1]:
nx, ny = x + dx, y + dy
if 0 <= nx < size and 0 <= ny < size:
matrix[nx][ny] = not matrix[nx][ny]
directions = [(0, 0), (-1, 0), (1, 0), (0, -1), (0, 1)] # self, N, S, W, E
for dx, dy in directions:
nx, ny = x + dx, y + dy
if 0 <= nx < size and 0 <= ny < size:
matrix[nx][ny] = not matrix[nx][ny]
# Pick a number of random "clicks"
num_clicks = seed_clicks if seed_clicks is not None else random.randint(size, size * 2)