|
47 | 47 |
|
48 | 48 | board_iteration = 1 |
49 | 49 |
|
| 50 | +# Global set to track winning patterns (rows, columns, & diagonals) |
| 51 | +bingo_patterns = set() |
| 52 | + |
50 | 53 | def generate_board(seed_val: int): |
51 | 54 | """ |
52 | 55 | Generate a new board using the provided seed value. |
@@ -230,12 +233,87 @@ def toggle_tile(row, col): |
230 | 233 |
|
231 | 234 | # Check for Bingo win condition |
232 | 235 | def check_winner(): |
| 236 | + global bingo_patterns |
| 237 | + new_patterns = [] |
| 238 | + # Check rows and columns. |
233 | 239 | for i in range(5): |
234 | | - if all((i, j) in clicked_tiles for j in range(5)) or all((j, i) in clicked_tiles for j in range(5)): |
235 | | - ui.notify("BINGO!", color="green", duration=5) |
236 | | - return |
237 | | - if all((i, i) in clicked_tiles for i in range(5)) or all((i, 4 - i) in clicked_tiles for i in range(5)): |
238 | | - ui.notify("BINGO!", color="green", duration=5) |
| 240 | + if all((i, j) in clicked_tiles for j in range(5)): |
| 241 | + if f"row{i}" not in bingo_patterns: |
| 242 | + new_patterns.append(f"row{i}") |
| 243 | + if all((j, i) in clicked_tiles for j in range(5)): |
| 244 | + if f"col{i}" not in bingo_patterns: |
| 245 | + new_patterns.append(f"col{i}") |
| 246 | + |
| 247 | + # Check main diagonal. |
| 248 | + if all((i, i) in clicked_tiles for i in range(5)): |
| 249 | + if "diag_main" not in bingo_patterns: |
| 250 | + new_patterns.append("diag_main") |
| 251 | + |
| 252 | + # Check anti-diagonal. |
| 253 | + if all((i, 4-i) in clicked_tiles for i in range(5)): |
| 254 | + if "diag_anti" not in bingo_patterns: |
| 255 | + new_patterns.append("diag_anti") |
| 256 | + |
| 257 | + # Additional winning variations: |
| 258 | + |
| 259 | + # Blackout: every cell is clicked. |
| 260 | + if all((r, c) in clicked_tiles for r in range(5) for c in range(5)): |
| 261 | + if "blackout" not in bingo_patterns: |
| 262 | + new_patterns.append("blackout") |
| 263 | + |
| 264 | + # 4 Corners: top-left, top-right, bottom-left, bottom-right. |
| 265 | + if all(pos in clicked_tiles for pos in [(0,0), (0,4), (4,0), (4,4)]): |
| 266 | + if "four_corners" not in bingo_patterns: |
| 267 | + new_patterns.append("four_corners") |
| 268 | + |
| 269 | + # Plus shape: complete center row and center column. |
| 270 | + plus_cells = {(2, c) for c in range(5)} | {(r, 2) for r in range(5)} |
| 271 | + if all(cell in clicked_tiles for cell in plus_cells): |
| 272 | + if "plus" not in bingo_patterns: |
| 273 | + new_patterns.append("plus") |
| 274 | + |
| 275 | + # X shape: both diagonals complete. |
| 276 | + if all((i, i) in clicked_tiles for i in range(5)) and all((i, 4-i) in clicked_tiles for i in range(5)): |
| 277 | + if "x_shape" not in bingo_patterns: |
| 278 | + new_patterns.append("x_shape") |
| 279 | + |
| 280 | + # Outside edges (perimeter): all border cells clicked. |
| 281 | + perimeter_cells = {(0, c) for c in range(5)} | {(4, c) for c in range(5)} | {(r, 0) for r in range(5)} | {(r, 4) for r in range(5)} |
| 282 | + if all(cell in clicked_tiles for cell in perimeter_cells): |
| 283 | + if "perimeter" not in bingo_patterns: |
| 284 | + new_patterns.append("perimeter") |
| 285 | + |
| 286 | + if new_patterns: |
| 287 | + # Separate new win patterns into standard and special ones. |
| 288 | + special_set = {"blackout", "four_corners", "plus", "x_shape", "perimeter"} |
| 289 | + standard_new = [p for p in new_patterns if p not in special_set] |
| 290 | + special_new = [p for p in new_patterns if p in special_set] |
| 291 | + |
| 292 | + # Process standard win conditions (rows, columns, diagonals). |
| 293 | + if standard_new: |
| 294 | + for pattern in standard_new: |
| 295 | + bingo_patterns.add(pattern) |
| 296 | + standard_total = sum(1 for p in bingo_patterns if p not in special_set) |
| 297 | + if standard_total == 1: |
| 298 | + message = "BINGO!" |
| 299 | + elif standard_total == 2: |
| 300 | + message = "DOUBLE BINGO!" |
| 301 | + elif standard_total == 3: |
| 302 | + message = "TRIPLE BINGO!" |
| 303 | + elif standard_total == 4: |
| 304 | + message = "QUADRUPLE BINGO!" |
| 305 | + elif standard_total == 5: |
| 306 | + message = "QUINTUPLE BINGO!" |
| 307 | + else: |
| 308 | + message = f"{standard_total}-WAY BINGO!" |
| 309 | + ui.notify(message, color="green", duration=5) |
| 310 | + |
| 311 | + # Process special win conditions individually. |
| 312 | + for sp in special_new: |
| 313 | + bingo_patterns.add(sp) |
| 314 | + # Format the name to title-case and append "Bingo!" |
| 315 | + sp_message = sp.replace("_", " ").title() + " Bingo!" |
| 316 | + ui.notify(sp_message, color="blue", duration=5) |
239 | 317 |
|
240 | 318 | def sync_board_state(): |
241 | 319 | # Update tile styles in every board view (e.g., home and stream) |
@@ -501,8 +579,11 @@ def has_too_many_repeats(phrase, threshold=0.5): |
501 | 579 |
|
502 | 580 | def reset_board(): |
503 | 581 | """ |
504 | | - Reset the board by clearing all clicked states and re-adding the FREE SPACE. |
| 582 | + Reset the board by clearing all clicked states, clearing winning patterns, |
| 583 | + and re-adding the FREE SPACE. |
505 | 584 | """ |
| 585 | + global bingo_patterns |
| 586 | + bingo_patterns.clear() # Clear previously recorded wins. |
506 | 587 | clicked_tiles.clear() |
507 | 588 | for r, row in enumerate(board): |
508 | 589 | for c, phrase in enumerate(row): |
|
0 commit comments