Spaces:
Runtime error
Runtime error
Ali Abid
commited on
Commit
·
0a95498
1
Parent(s):
cad28ac
changes
Browse files- formatters.py +10 -5
- game_manager.py +8 -5
- run.py +1 -6
formatters.py
CHANGED
@@ -31,14 +31,19 @@ def crossword(grid: List[List[Optional[str]]], clues: List[Clue]):
|
|
31 |
return output
|
32 |
|
33 |
|
34 |
-
def clue_riddle(clue):
|
35 |
if clue is None:
|
36 |
return "..."
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
return (
|
40 |
"\n".join(line for line in clue.riddle.splitlines() if line.strip() != "")
|
41 |
+ " - "
|
42 |
-
+
|
43 |
-
+ "s"
|
44 |
)
|
|
|
31 |
return output
|
32 |
|
33 |
|
34 |
+
def clue_riddle(clue: Clue):
|
35 |
if clue is None:
|
36 |
return "..."
|
37 |
+
|
38 |
+
if clue.solved:
|
39 |
+
end_line = clue.answer + " - " + clue.solver
|
40 |
+
elif clue.timed_out:
|
41 |
+
end_line = clue.answer
|
42 |
+
else:
|
43 |
+
time_remaining = GUESS_TIMEOUT - (time.time() - clue.create_time)
|
44 |
+
end_line = str(round(max(0, time_remaining))) + "s"
|
45 |
return (
|
46 |
"\n".join(line for line in clue.riddle.splitlines() if line.strip() != "")
|
47 |
+ " - "
|
48 |
+
+ end_line
|
|
|
49 |
)
|
game_manager.py
CHANGED
@@ -17,7 +17,7 @@ MAX_WORD_SIZE = 10
|
|
17 |
WORD_LIMIT = 7500
|
18 |
COMPLETE_GAME_TIMEOUT = 60 * 60
|
19 |
INCOMPLETE_GAME_TIMEOUT = 60 * 60 * 24
|
20 |
-
GUESS_TIMEOUT =
|
21 |
|
22 |
|
23 |
with open("words.json", "r") as f:
|
@@ -55,6 +55,8 @@ class Clue:
|
|
55 |
self.solved: bool = solved
|
56 |
self.riddle: str = ""
|
57 |
self.create_time: int
|
|
|
|
|
58 |
|
59 |
def __repr__(self):
|
60 |
return f"{self.answer}: {self.location}, {'Across' if self.across else 'Down'}, {'Solved' if self.solved else 'Unsolved'}"
|
@@ -122,12 +124,10 @@ class Game:
|
|
122 |
return False
|
123 |
for clue in matched_clues:
|
124 |
clue.solved = True
|
|
|
125 |
place_on_grid(self.grid, clue.answer, clue.location, clue.across)
|
126 |
self.player_scores[player_name] += 1
|
127 |
|
128 |
-
def time_left(self):
|
129 |
-
return INCOMPLETE_GAME_TIMEOUT - (time.time() - self.last_update_time)
|
130 |
-
|
131 |
|
132 |
def place_on_grid(grid, word, location, across):
|
133 |
x, y = location
|
@@ -249,7 +249,10 @@ def game_thread():
|
|
249 |
del games[room_name]
|
250 |
continue
|
251 |
for i, clue in enumerate(game.clues):
|
252 |
-
|
|
|
|
|
|
|
253 |
game.replace_clue(i)
|
254 |
|
255 |
time.sleep(0.1)
|
|
|
17 |
WORD_LIMIT = 7500
|
18 |
COMPLETE_GAME_TIMEOUT = 60 * 60
|
19 |
INCOMPLETE_GAME_TIMEOUT = 60 * 60 * 24
|
20 |
+
GUESS_TIMEOUT = 10
|
21 |
|
22 |
|
23 |
with open("words.json", "r") as f:
|
|
|
55 |
self.solved: bool = solved
|
56 |
self.riddle: str = ""
|
57 |
self.create_time: int
|
58 |
+
self.solver: str = None
|
59 |
+
self.timed_out: bool = False
|
60 |
|
61 |
def __repr__(self):
|
62 |
return f"{self.answer}: {self.location}, {'Across' if self.across else 'Down'}, {'Solved' if self.solved else 'Unsolved'}"
|
|
|
124 |
return False
|
125 |
for clue in matched_clues:
|
126 |
clue.solved = True
|
127 |
+
clue.solver = player_name
|
128 |
place_on_grid(self.grid, clue.answer, clue.location, clue.across)
|
129 |
self.player_scores[player_name] += 1
|
130 |
|
|
|
|
|
|
|
131 |
|
132 |
def place_on_grid(grid, word, location, across):
|
133 |
x, y = location
|
|
|
249 |
del games[room_name]
|
250 |
continue
|
251 |
for i, clue in enumerate(game.clues):
|
252 |
+
timed_out = now - clue.create_time > GUESS_TIMEOUT if clue is not None else None
|
253 |
+
if timed_out:
|
254 |
+
game.clues[i].timed_out = True
|
255 |
+
if clue is None or clue.solved or timed_out:
|
256 |
game.replace_clue(i)
|
257 |
|
258 |
time.sleep(0.1)
|
run.py
CHANGED
@@ -43,9 +43,6 @@ with gr.Blocks(css="style.css") as app:
|
|
43 |
elem_id="guess",
|
44 |
)
|
45 |
guess_btn = gr.Button("Guess")
|
46 |
-
prev_answers = gr.DataFrame(
|
47 |
-
headers=None, row_count=1, col_count=3, label="Previous Answers"
|
48 |
-
)
|
49 |
|
50 |
def start_game(data):
|
51 |
game = new_game(data[room_name])
|
@@ -92,18 +89,16 @@ with gr.Blocks(css="style.css") as app:
|
|
92 |
no_up = data[last_update] == game.last_update_index
|
93 |
return {
|
94 |
grid: gr.skip() if no_up else formatters.crossword(game.grid, game.clues),
|
95 |
-
prev_answers: gr.skip() if no_up else [[clue.answer for clue in game.previous_clues[-3:]]],
|
96 |
score_table: [[k, v] for k, v in game.player_scores.items()],
|
97 |
clue1: formatters.clue_riddle(game.clues[0]),
|
98 |
clue2: formatters.clue_riddle(game.clues[1]),
|
99 |
clue3: formatters.clue_riddle(game.clues[2]),
|
100 |
-
|
101 |
}
|
102 |
|
103 |
start_btn.click(
|
104 |
update_game,
|
105 |
{room_name, last_update},
|
106 |
-
[grid,
|
107 |
every=1,
|
108 |
)
|
109 |
|
|
|
43 |
elem_id="guess",
|
44 |
)
|
45 |
guess_btn = gr.Button("Guess")
|
|
|
|
|
|
|
46 |
|
47 |
def start_game(data):
|
48 |
game = new_game(data[room_name])
|
|
|
89 |
no_up = data[last_update] == game.last_update_index
|
90 |
return {
|
91 |
grid: gr.skip() if no_up else formatters.crossword(game.grid, game.clues),
|
|
|
92 |
score_table: [[k, v] for k, v in game.player_scores.items()],
|
93 |
clue1: formatters.clue_riddle(game.clues[0]),
|
94 |
clue2: formatters.clue_riddle(game.clues[1]),
|
95 |
clue3: formatters.clue_riddle(game.clues[2]),
|
|
|
96 |
}
|
97 |
|
98 |
start_btn.click(
|
99 |
update_game,
|
100 |
{room_name, last_update},
|
101 |
+
[grid, clue1, clue2, clue3, score_table],
|
102 |
every=1,
|
103 |
)
|
104 |
|