-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (49 loc) · 1.83 KB
/
main.py
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
import sys
import os
from pathlib import Path
# Add src directory to the Python module search path
SRC_DIR = os.path.join(str(Path(__file__).resolve().parent), "src")
sys.path.append(SRC_DIR)
import logging
import threading
from config import MINESWEEPER_GRID_SIZE, TESSERACT_PATH, DEBUG, BOARD_VISUALIZER
from minesweeper_detector import MinesweeperDetector
from player import MinesweeperPlayer
from visualizer import MinesweeperVisualizer
def main():
"""
Main entry point for the Minesweeper solver.
This function configures logging, initializes the Minesweeper components,
and either runs the solver with or without a visualizer.
"""
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
# Initialize the Minesweeper detector and player
detector = MinesweeperDetector(MINESWEEPER_GRID_SIZE, TESSERACT_PATH, DEBUG)
player = MinesweeperPlayer(logger)
if BOARD_VISUALIZER:
# Use the visualizer in a separate thread
visualizer = MinesweeperVisualizer(MINESWEEPER_GRID_SIZE)
running = True
# Start a thread to update the game while keeping the visualizer responsive
update_thread = threading.Thread(
target=player.play_game,
args=(detector, visualizer, running),
daemon=True # Thread will stop when the main program exits
)
update_thread.start()
# Run the GUI in the main thread
try:
visualizer.run()
finally:
# Ensure the update thread stops when the visualizer is closed
running = False
else:
# Run the solver in the main thread without a visualizer
player.play_game(detector)
if __name__ == "__main__":
main()