Skip to content

Commit 041e42a

Browse files
committed
Update python_easy_chess_gui.py
* Modify search info display of opponent engine. Just use one line with score, depth, time and pv line. * When user selects opponent engine, show also the current engine in the window.
1 parent 0ae35f9 commit 041e42a

1 file changed

Lines changed: 32 additions & 75 deletions

File tree

python_easy_chess_gui.py

Lines changed: 32 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959

6060
APP_NAME = 'Python Easy Chess GUI'
61-
APP_VERSION = 'v0.80'
61+
APP_VERSION = 'v0.81'
6262
BOX_TITLE = '{} {}'.format(APP_NAME, APP_VERSION)
6363

6464

@@ -345,26 +345,26 @@ def run(self):
345345
try:
346346
if 'depth' in info:
347347
self.depth = int(info['depth'])
348-
self.eng_queue.put('{} depth'.format(self.depth))
349348

350349
if 'score' in info:
351350
self.score = int(info['score'].relative.score(mate_score=32000))/100
352-
self.eng_queue.put('{:+0.2f} score'.format(self.score))
353351

354352

355353
self.time = info['time'] if 'time' in info else \
356-
time.time() - start_thinking_time
357-
self.eng_queue.put('{} time'.format(self.time))
354+
time.time() - start_thinking_time
358355

359356
if 'pv' in info and not ('upperbound' in info or 'lowerbound' in info):
360357
self.pv = info['pv'][0:self.pv_length]
361358
self.pv = self.board.variation_san(self.pv)
362359
self.eng_queue.put('{} pv'.format(self.pv))
363360
self.bm = info['pv'][0]
364361

365-
if 'nps' in info:
366-
self.nps = info['nps']
367-
self.eng_queue.put('{} nps'.format(self.nps))
362+
# score, depth, time, pv
363+
if self.score is not None and \
364+
self.pv is not None and self.depth is not None:
365+
info_to_send = '{:+5.2f} | {} | {:0.1f}s | {} info_all'.format(
366+
self.score, self.depth, self.time, self.pv)
367+
self.eng_queue.put('{}'.format(info_to_send))
368368

369369
# If we use "go infinite" we stop the search by time and depth
370370
if not is_time_check and \
@@ -376,7 +376,7 @@ def run(self):
376376
if 'depth' in info:
377377
if int(info['depth']) >= self.max_depth:
378378
logging.info('Max depth limit is reached.')
379-
break
379+
break
380380
except:
381381
logging.info('Error in parsing engine search info')
382382
else:
@@ -448,41 +448,11 @@ def update_text_box(self, msg, is_hide):
448448
best_move = None
449449
msg_str = str(msg)
450450

451-
if not 'bestmove ' in msg_str:
452-
if 'score' in msg_str:
453-
score = float(' '.join(msg_str.split()[0:-1]).strip())
454-
msg_line = '{:+0.2f}\n'.format(score)
455-
self.window.FindElement('info_score_k').Update(
456-
'' if is_hide else msg_line)
457-
458-
if 'pv' in msg_str:
459-
pv = ' '.join(msg_str.split()[0:-1]).strip()
460-
msg_line = '{}\n'.format(pv)
461-
self.window.FindElement('info_pv_k').Update(
462-
'' if is_hide else msg_line)
463-
464-
if 'depth' in msg_str:
465-
depth = int(' '.join(msg_str.split()[0:-1]).strip())
466-
msg_line = 'Depth {}\n'.format(depth)
467-
self.window.FindElement('info_depth_k').Update(
468-
'' if is_hide else msg_line)
469-
470-
if 'time' in msg_str:
471-
tsec = float(' '.join(msg_str.split()[0:-1]).strip())
472-
msg_line = 'Time {}\n'.format(self.get_time_mm_ss_ms(tsec*1000))
473-
self.window.FindElement('info_time_k').Update(
474-
'' if is_hide else msg_line)
475-
476-
if 'nps' in msg_str:
477-
nps = int(' '.join(msg_str.split()[0:-1]).strip())
478-
479-
# Add suffix K if nps is 1 Million or more
480-
if nps >= 1000000:
481-
msg_line = 'Knps {:0.0f}\n'.format(nps/1000)
482-
else:
483-
msg_line = 'Nps {}\n'.format(nps)
484-
485-
self.window.FindElement('info_nps_k').Update(
451+
if not 'bestmove ' in msg_str:
452+
if 'info_all' in msg_str:
453+
info_all = ' '.join(msg_str.split()[0:-1]).strip()
454+
msg_line = '{}\n'.format(info_all)
455+
self.window.FindElement('search_info_all_k').Update(
486456
'' if is_hide else msg_line)
487457
else:
488458
best_move = chess.Move.from_uci(msg.split()[1])
@@ -517,11 +487,7 @@ def set_new_game(self):
517487

518488
def clear_elements(self):
519489
""" Clear movelist, score, pv, time, depth and nps boxes """
520-
self.window.FindElement('info_score_k').Update('')
521-
self.window.FindElement('info_pv_k').Update('')
522-
self.window.FindElement('info_depth_k').Update('')
523-
self.window.FindElement('info_time_k').Update('')
524-
self.window.FindElement('info_nps_k').Update('')
490+
self.window.FindElement('search_info_all_k').Update('')
525491
self.window.FindElement('_movelist_').Update(disabled=False)
526492
self.window.FindElement('_movelist_').Update('', disabled=True)
527493
self.window.FindElement('polyglot_book1_k').Update('')
@@ -844,11 +810,11 @@ def set_time_limit(self):
844810

845811
self.max_time = min(MAX_TIME, max(MIN_TIME, user_movetime))
846812

847-
def get_engine_settings(self, engine_id_name):
813+
def get_engine_settings(self):
848814
""" Display engine settings """
849815
sg.PopupOK(
850816
'Engine = {}\nThreads = {}\nHash = {} mb\nDepth = {}\nMovetime = {} sec'.format(
851-
engine_id_name, self.threads, self.hash, self.max_depth,
817+
self.opp_eng_id_name, self.threads, self.hash, self.max_depth,
852818
self.max_time), title=BOX_TITLE, keep_on_top=True)
853819

854820
def play_game(self, engine_id_name, board):
@@ -1000,8 +966,9 @@ def play_game(self, engine_id_name, board):
1000966
self.set_time_limit()
1001967
continue
1002968

969+
# Mode: Play, Stm: Computer (first move)
1003970
if button == 'Get Settings::engine_info_k':
1004-
self.get_engine_settings(engine_id_name)
971+
self.get_engine_settings()
1005972
continue
1006973

1007974
# Mode: Play, Stm: Computer (first move, not thinking)
@@ -1015,7 +982,7 @@ def play_game(self, engine_id_name, board):
1015982
logging.info('Current engine file: {}'.format(current_engine_file))
1016983

1017984
layout = [
1018-
[sg.T('Engine file', size=(12,1))],
985+
[sg.T('Current Opponent: {}'.format(self.opp_eng_id_name), size=(40,1))],
1019986
[sg.Listbox(values=self.engine_list, size=(48,6),
1020987
key='engine_file_k')],
1021988
[sg.T('Threads', size=(12, 1)),
@@ -1170,8 +1137,9 @@ def play_game(self, engine_id_name, board):
11701137
self.window.Element('book2_k').Update(text_color='green' if is_hide_book2 else 'red')
11711138
break
11721139

1140+
# Mode: Play, Stm: User
11731141
if button == 'Get Settings::engine_info_k':
1174-
self.get_engine_settings(engine_id_name)
1142+
self.get_engine_settings()
11751143
break
11761144

11771145
# Mode: Play, Stm: User, Allow user to change engine settings
@@ -1184,7 +1152,7 @@ def play_game(self, engine_id_name, board):
11841152
logging.info('Current engine file: {}'.format(current_engine_file))
11851153

11861154
layout = [
1187-
[sg.T('Engine file', size=(12,1))],
1155+
[sg.T('Current Opponent: {}'.format(self.opp_eng_id_name), size=(40,1))],
11881156
[sg.Listbox(values=self.engine_list, size=(48,6),
11891157
bind_return_key = True, key='engine_file_k')],
11901158
[sg.T('Threads', size=(12, 1)),
@@ -1838,22 +1806,20 @@ def build_main_layout(self):
18381806

18391807
# Define board
18401808
white_board_layout, black_board_layout = self.create_board()
1841-
bc = '#d3dae4'
18421809

18431810
board_controls = [
18441811
[sg.Text('Mode Neutral', size=(36, 1), font=('Consolas', 10), key='_gamestatus_')],
18451812
[sg.Text('White', size=(6, 1), font=('Consolas', 10)), sg.Text('Human',
1846-
font=('Consolas', 10), key='_White_', size=(35, 1), relief='sunken')],
1813+
font=('Consolas', 10), key='_White_', size=(36, 1), relief='sunken')],
18471814
[sg.Text('Black', size=(6, 1), font=('Consolas', 10)), sg.Text('Computer',
1848-
font=('Consolas', 10), key='_Black_', size=(35, 1), relief='sunken')],
1849-
1850-
[sg.Text('MOVE LIST', font=('Consolas', 10))],
1851-
[sg.Multiline('', do_not_clear=True, autoscroll=True, size=(0, 1),
1852-
font=('Consolas', 10), key='_movelist_', disabled=True)],
1815+
font=('Consolas', 10), key='_Black_', size=(36, 1), relief='sunken')],
18531816

18541817
[sg.Text('Advise', font=('Consolas', 10), click_submits=True, key='advise_k'),
18551818
sg.Text('', font=('Consolas', 10), key='advise_info_k', relief='sunken',
18561819
size=(36,1))],
1820+
1821+
[sg.Multiline('', do_not_clear=True, autoscroll=True, size=(0, 1),
1822+
font=('Consolas', 10), key='_movelist_', disabled=True)],
18571823

18581824
[sg.Text('BOOK 1\nsrc: Computer games', size=(20, 2),
18591825
font=('Consolas', 10), click_submits=True, key='book1_k'),
@@ -1866,12 +1832,8 @@ def build_main_layout(self):
18661832

18671833
[sg.Text('ENGINE SEARCH INFO', font=('Consolas', 10), size=(28, 1),
18681834
click_submits=True, key='search_info_k')],
1869-
[sg.Text('', key='info_score_k', size=(8, 1), background_color = bc),
1870-
sg.Text('', key='info_pv_k', size=(28, 1), background_color = bc)],
1871-
1872-
[sg.Text('', key='info_depth_k', size=(8, 1), background_color = bc),
1873-
sg.Text('', key='info_time_k', size=(12, 1), background_color = bc),
1874-
sg.Text('', key='info_nps_k', size=(14, 1), background_color = bc)],
1835+
[sg.Text('', key='search_info_all_k', size=(44, 1),
1836+
font=('Consolas', 10), relief='sunken')],
18751837
]
18761838

18771839
white_board_tab = [[sg.Column(white_board_layout)]]
@@ -1936,16 +1898,11 @@ def main_loop(self):
19361898

19371899
# Mode: Neutral
19381900
if button == 'Get Settings::engine_info_k':
1939-
self.get_engine_settings(engine_id_name)
1901+
self.get_engine_settings()
19401902
continue
19411903

19421904
# Mode: Neutral, Allow user to change opponent engine settings
19431905
if button == 'Set Engine Opponent':
1944-
# Disable the main window and build a new window for setting
1945-
# engine opponent. Enable the main window when done
1946-
1947-
# Backup current engine info, in case user cancels the engine selection,
1948-
# we can just restore to current values.
19491906
current_engine_list = self.engine_list
19501907
current_engine_file = self.engine_file
19511908

@@ -1954,7 +1911,7 @@ def main_loop(self):
19541911
logging.info('Current engine file: {}'.format(current_engine_file))
19551912

19561913
layout = [
1957-
[sg.T('Engine file', size=(12,1))],
1914+
[sg.T('Current Opponent: {}'.format(self.opp_eng_id_name), size=(40,1))],
19581915
[sg.Listbox(values=self.engine_list, size=(48,6),
19591916
bind_return_key = True, key='engine_file_k')],
19601917
[sg.T('Threads', size=(12, 1)),

0 commit comments

Comments
 (0)