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 = "
"
for i, row in enumerate(grid):
output += "
"
for j, cell in enumerate(row):
clue_ids = clue_grid[i][j]
output += f"""
"""
if cell == None:
output += " "
else:
output += cell
output += "
"
output += "
"
output += "
"
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
)