Spaces:
Runtime error
Runtime error
from game_manager import Clue | |
from typing import List, Optional | |
import time | |
from game_manager import GUESS_TIMEOUT | |
def crossword(grid: List[List[Optional[str]]], clues: List[Clue]): | |
clue_grid = [[[] for _ in range(len(grid[0]))] for _ in range(len(grid))] | |
for clue_id, clue in enumerate(clues): | |
if clue is None: | |
continue | |
if clue.across: | |
for i, _ in enumerate(clue.answer): | |
clue_grid[clue.location[0]][clue.location[1] + i].append(clue_id) | |
else: | |
for i, _ in enumerate(clue.answer): | |
clue_grid[clue.location[0] + i][clue.location[1]].append(clue_id) | |
output = "<div class='crossword'>" | |
for i, row in enumerate(grid): | |
output += "<div class='c-row'>" | |
for j, cell in enumerate(row): | |
clue_ids = clue_grid[i][j] | |
output += f"""<div class='cell {"" if cell is None else "filled"} {"" if len(clue_ids) == 0 else f"clue {' '.join('clue-' + str(clue_id+1) for clue_id in clue_ids)}"}'>""" | |
if cell == None: | |
output += " " | |
else: | |
output += cell | |
output += "</div>" | |
output += "</div>" | |
output += "</div>" | |
return output | |
def clue_riddle(clue: Clue): | |
if clue is None: | |
return "..." | |
if clue.solved: | |
end_line = clue.answer + " - " + clue.solver | |
elif clue.timed_out: | |
end_line = clue.answer | |
else: | |
time_remaining = GUESS_TIMEOUT - (time.time() - clue.create_time) | |
end_line = str(round(max(0, time_remaining))) + "s" | |
return ( | |
"\n".join(line for line in clue.riddle.splitlines() if line.strip() != "") | |
+ " - " | |
+ end_line | |
) | |