From e03988f28a4276bb9bf2729046f57414ff2768af Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Tue, 29 Jul 2025 11:40:52 -0500 Subject: [PATCH] Fix the lights-out easter egg. --- inventory/routes/index.py | 10 +++++----- inventory/templates/coffee.html | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/inventory/routes/index.py b/inventory/routes/index.py index 58ed4ce..6fb5cb8 100644 --- a/inventory/routes/index.py +++ b/inventory/routes/index.py @@ -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) diff --git a/inventory/templates/coffee.html b/inventory/templates/coffee.html index 68e908d..62ee55e 100644 --- a/inventory/templates/coffee.html +++ b/inventory/templates/coffee.html @@ -23,8 +23,10 @@ checkbox.addEventListener('change', function() { const [x, y] = this.id.split('-').slice(1).map(Number); const neighbors = [ - [x - 1, y], [x + 1, y], [x, y - 1], [x, y + 1], - [x - 1, y - 1], [x - 1, y + 1], [x + 1, y - 1], [x + 1, y + 1] + [x - 1, y], + [x + 1, y], + [x, y - 1], + [x, y + 1] ]; neighbors.forEach(([nx, ny]) => {