Enable "cheating" on lights out game.
This commit is contained in:
parent
63c503c84a
commit
109176573c
2 changed files with 25 additions and 12 deletions
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue