-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot_gui.py
More file actions
123 lines (98 loc) · 3.51 KB
/
bot_gui.py
File metadata and controls
123 lines (98 loc) · 3.51 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# chess_bot_gui.py
import tkinter as tk
import threading
from chess_bot import ChessBot
import time
# Create App window
app = tk.Tk()
app.title("ChessBot GUI")
app.attributes("-topmost", True)
# Initialize ChessBot instance
bot = ChessBot(
stockfish_path=r"C:\Users\KIIT\Downloads\stockfish-windows-x86-64-avx2\stockfish\stockfish-windows-x86-64-avx2.exe",
chromedriver_path=r"C:\Users\KIIT\Downloads\chromedriver-win64\chromedriver.exe"
)
move=""
def open_browser():
threading.Thread(target=bot.open_chess_com).start()
def start_bot():
bot.recent_move()
# move_label.config(text=f"Best Move: {bot.get_best_move()}")
# move_label.pack(pady=10)
def clear():
bot.reset()
def best_move_txt():
while True:
move_label.config(text=f"Best Move: {bot.str}")
move_label.pack(pady=10)
time.sleep(0.1)
class threads():
def __init__(self):
self.stop_event=threading.Event()
self.recent_move_thread = threading.Thread(target=bot.recent_move)
self.recent_move_thread.daemon = True
self.check=self.recent_move_thread.is_alive()
self.is_running = False
def start_recent_move_thread(self):
if self.check:
print("Thread can only be started once!!")
else:
self.is_running = True
self.recent_move_thread.start()
txt_thread=threading.Thread(target=best_move_txt)
txt_thread.daemon=True
txt_thread.start()
print("Recent move detection thread started.")
def stop(self):
self.is_running = False
self.stop_event.set()
bot.stop_bot()
def print(self):
self.check=self.recent_move_thread.is_alive()
print("Thread Status:",self.check)
print("Loop Status:",bot.int)
thrd=threads()
def start_best_move_thread():
best_move_thread=threading.Thread(target=best_move)
best_move_thread.daemon=True
best_move_thread.start()
def best_move():
print("|||||||||||||||||||||\n")
thrd.print()
bot.get_best_move()
bot.print()
bot.rec_move()
move_label.config(text=f"Best Move: {bot.get_best_move()}")
move_label.pack(pady=10)
# def show():
# move=bot.str
# move_label = tk.Label(app, text=f"Best Move: {move}", font=("Arial", 16))
# move_label.pack(pady=10)
def start_auto_play():
if not bot.driver:
print("Please open Chess.com first!")
return
bot.check = True
bot.int = 1
thrd.start_recent_move_thread()
auto_play_button.config(state='disabled')
stop_button.config(state='normal')
def stop_auto_play():
bot.check = False
bot.int = 0
bot.stop_bot()
auto_play_button.config(state='normal')
stop_button.config(state='disabled')
# Buttons in the GUI
open_button = tk.Button(app, text="Open Chess.com", command=open_browser, height=2, width=20)
open_button.pack(pady=10)
auto_play_button = tk.Button(app, text="Start Auto Play", command=start_auto_play, height=2, width=20)
auto_play_button.pack(pady=10)
stop_button = tk.Button(app, text="Stop Auto Play", command=stop_auto_play, height=2, width=20, state='disabled')
stop_button.pack(pady=10)
# best_move_button = tk.Button(app, text="Best Move", command=best_move, height=2, width=20)
# best_move_button.pack(pady=10)
move_label = tk.Label(app, text="Best Move: ", font=("Arial", 16))
move_label.pack(pady=10)
app.geometry("300x400")
app.mainloop()