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,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)
|
||||
|
|
|
@ -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]) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue