Enable "cheating" on lights out game.

This commit is contained in:
Yaro Kasear 2025-08-11 15:09:18 -05:00
parent 63c503c84a
commit 109176573c
2 changed files with 25 additions and 12 deletions

View file

@ -11,30 +11,30 @@ from ..utils.load import eager_load_worklog_relationships, eager_load_inventory_
def generate_solvable_matrix(level, seed_clicks=None):
size = level + 3
matrix = [[True for _ in range(size)] for _ in range(size)]
presses = []
def toggle(x, y):
directions = [(0, 0), (-1, 0), (1, 0), (0, -1), (0, 1)] # self, N, S, W, E
for dx, dy in directions:
def press(x, y):
# record the press (once)
presses.append((x, y))
# apply its effect
for dx, dy in [(0,0),(-1,0),(1,0),(0,-1),(0,1)]:
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)
for _ in range(num_clicks):
x = random.randint(0, size - 1)
y = random.randint(0, size - 1)
toggle(x, y)
return matrix
press(x, y)
return matrix, presses # return the PRESS LIST as the “solution”
@main.route("/12648243")
def coffee():
level = request.args.get('level', 0, int)
matrix = generate_solvable_matrix(level)
return render_template("coffee.html", matrix=matrix, level=level)
matrix, clicked = generate_solvable_matrix(level)
return render_template("coffee.html", matrix=matrix, level=level, clicked=clicked)
@main.route("/")
def index():