-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
105 lines (76 loc) · 3.19 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
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
# The code is modified from https://github.com/Stanou01260/chessbot_python/blob/master/code/main.py
import tkinter as tk
import board_basics
from game_state_classes import *
from voice_to_chess_notation import Voice_to_chess_notation
import pyttsx3
def clear_logs():
logs_text.delete('1.0', tk.END)
def add_log(log):
logs_text.insert(tk.END, log + "\n")
def stop_playing():
clear_logs()
button_start = tk.Button(text="Start playing (s)", command=start_playing)
button_start.grid(column=0, row=1)
def start_playing(ignore=None):
pyautogui.click()
print(ignore)
game_state = Game_state(voice_to_chess_notation)
add_log("Looking for a chessboard...")
engine.say("Looking for a chessboard")
engine.runAndWait()
position, we_are_white = chessboard_detection.find_chessboard()
add_log("Found the chessboard " + position.print_custom())
engine.say("Found the chessboard")
engine.runAndWait()
game_state.board_position_on_screen = position
button_start = tk.Button(text="Stop playing", command=stop_playing)
button_start.grid(column=0, row=1)
resized_chessboard = chessboard_detection.get_chessboard(game_state)
game_state.previous_chessboard_image = resized_chessboard
game_state.we_play_white = we_are_white
if we_are_white:
add_log("We are white")
engine.say("We are white")
engine.runAndWait()
game_state.moves_to_detect_before_play = 0
else:
add_log("We are black")
engine.say("We are black")
engine.runAndWait()
game_state.moves_to_detect_before_play = 1
game_state.previous_chessboard_image = chessboard_detection.read_black_chessboard()
while not game_state.board.is_game_over():
window.update()
if game_state.moves_to_detect_before_play == 0:
game_state.play_next_move()
if game_state.board.is_game_over():
break
found_move, move = game_state.register_move_if_needed()
if found_move:
clear_logs()
add_log("The board :\n" + str(game_state.board) + "\n")
add_log("\nAll moves :\n" + str(game_state.executed_moves))
else:
pass
#print(move)
engine.say("Game is over")
engine.runAndWait()
button_start = tk.Button(text="Start playing", command=start_playing)
button_start.grid(column=0, row=1)
window = tk.Tk()
window.title("Voice to chess notation by Alper Karayaman")
label_title = tk.Label(text="Welcome on voice to chess notation, hope you will have fun with it", anchor="e",
wraplength=300)
label_title.grid(column=0, row=0)
engine = pyttsx3.init()
voice_to_chess_notation = Voice_to_chess_notation(engine)
engine.say("Welcome on voice to chess notation, hope you will have fun with it")
engine.runAndWait()
button_start = tk.Button(text="Start playing (s)", command=start_playing)
button_start.grid(column=0, row=1)
logs_text = tk.Text(window, width=40, height=25, background='gray')
logs_text.grid(column=0, row=2)
window.geometry("+1000+100")
window.bind("s", start_playing)
window.mainloop()