-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboard.py
More file actions
65 lines (53 loc) · 1.92 KB
/
board.py
File metadata and controls
65 lines (53 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Board generation and management
import random
import datetime
from typing import List, Dict, Set, Tuple
from src.config.constants import FREE_SPACE_TEXT, FREE_SPACE_POSITION
# Avoid import at module level to prevent circular imports
# We'll import get_phrases inside the function
# Global state
board = []
clicked_tiles = set()
board_iteration = 1
today_seed = ""
board_views = {}
def generate_board(seed_val: int) -> None:
"""Generate a new board using the provided seed value."""
global board, today_seed, clicked_tiles
# Import here to avoid circular imports
from src.core.phrases import get_phrases
todays_seed = datetime.date.today().strftime("%Y%m%d")
random.seed(seed_val)
phrases = get_phrases()
shuffled_phrases = random.sample(phrases, 24)
shuffled_phrases.insert(12, FREE_SPACE_TEXT)
board = [shuffled_phrases[i:i+5] for i in range(0, 25, 5)]
clicked_tiles.clear()
for r, row in enumerate(board):
for c, phrase in enumerate(row):
if phrase.upper() == FREE_SPACE_TEXT:
clicked_tiles.add((r, c))
today_seed = f"{todays_seed}.{seed_val}"
return board
def reset_board() -> None:
"""Clear all clicked tiles except FREE SPACE."""
global clicked_tiles
clicked_tiles.clear()
for r, row in enumerate(board):
for c, phrase in enumerate(row):
if phrase.upper() == FREE_SPACE_TEXT:
clicked_tiles.add((r, c))
def generate_new_board() -> None:
"""Generate a completely new board with a new seed."""
global board_iteration
board_iteration += 1
return generate_board(board_iteration)
def toggle_tile(row: int, col: int) -> None:
"""Toggle the clicked state of a tile."""
if (row, col) == FREE_SPACE_POSITION:
return
key = (row, col)
if key in clicked_tiles:
clicked_tiles.remove(key)
else:
clicked_tiles.add(key)