Fix the lights-out easter egg.
This commit is contained in:
parent
921400456e
commit
e03988f28a
2 changed files with 9 additions and 7 deletions
|
@ -13,8 +13,8 @@ def generate_solvable_matrix(level, seed_clicks=None):
|
||||||
matrix = [[True for _ in range(size)] for _ in range(size)]
|
matrix = [[True for _ in range(size)] for _ in range(size)]
|
||||||
|
|
||||||
def toggle(x, y):
|
def toggle(x, y):
|
||||||
for dx in [-1, 0, 1]:
|
directions = [(0, 0), (-1, 0), (1, 0), (0, -1), (0, 1)] # self, N, S, W, E
|
||||||
for dy in [-1, 0, 1]:
|
for dx, dy in directions:
|
||||||
nx, ny = x + dx, y + dy
|
nx, ny = x + dx, y + dy
|
||||||
if 0 <= nx < size and 0 <= ny < size:
|
if 0 <= nx < size and 0 <= ny < size:
|
||||||
matrix[nx][ny] = not matrix[nx][ny]
|
matrix[nx][ny] = not matrix[nx][ny]
|
||||||
|
|
|
@ -23,8 +23,10 @@
|
||||||
checkbox.addEventListener('change', function() {
|
checkbox.addEventListener('change', function() {
|
||||||
const [x, y] = this.id.split('-').slice(1).map(Number);
|
const [x, y] = this.id.split('-').slice(1).map(Number);
|
||||||
const neighbors = [
|
const neighbors = [
|
||||||
[x - 1, y], [x + 1, y], [x, y - 1], [x, y + 1],
|
[x - 1, y],
|
||||||
[x - 1, y - 1], [x - 1, y + 1], [x + 1, y - 1], [x + 1, y + 1]
|
[x + 1, y],
|
||||||
|
[x, y - 1],
|
||||||
|
[x, y + 1]
|
||||||
];
|
];
|
||||||
|
|
||||||
neighbors.forEach(([nx, ny]) => {
|
neighbors.forEach(([nx, ny]) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue