Skip to content

Commit b30f1c1

Browse files
Copilotfsmosca
andauthored
Add time forfeit adjudication with Settings/Game checkbox option (#57)
Agent-Logs-Url: https://github.com/fsmosca/Python-Easy-Chess-GUI/sessions/28c3a0af-5893-4ab3-a1fb-5bb4f962026b Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: fsmosca <22366935+fsmosca@users.noreply.github.com>
1 parent 0623d86 commit b30f1c1

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

1.03 KB
Binary file not shown.

python_easy_chess_gui.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ def __init__(self, theme, engine_config_file, user_config_file,
732732

733733
self.is_save_time_left = False
734734
self.is_save_user_comment = True
735+
self.is_time_forfeit_enabled = True
735736

736737
def update_game(self, mc: int, user_move: str, time_left: int, user_comment: str):
737738
"""Saves moves in the game.
@@ -1705,6 +1706,7 @@ def play_game(self, window: sg.Window, board: chess.Board):
17051706
is_user_resigns = False
17061707
is_user_wins = False
17071708
is_user_draws = False
1709+
is_user_time_forfeit = False
17081710
is_search_stop_for_exit = False
17091711
is_search_stop_for_new_game = False
17101712
is_search_stop_for_neutral = False
@@ -1831,6 +1833,17 @@ def play_game(self, window: sg.Window, board: chess.Board):
18311833
window.Element(k).Update(elapse_str)
18321834
human_timer.elapse += 100
18331835

1836+
# Check if human has run out of time
1837+
if (self.is_time_forfeit_enabled and
1838+
human_timer.elapse >= human_timer.base):
1839+
color = 'white' if self.is_user_white else 'black'
1840+
sg.Popup(
1841+
'{} loses on time!'.format(color.capitalize()),
1842+
title=BOX_TITLE,
1843+
icon=ico_path[platform]['pecg'])
1844+
is_user_time_forfeit = True
1845+
break
1846+
18341847
if not is_human_stm:
18351848
break
18361849

@@ -2172,7 +2185,8 @@ def play_game(self, window: sg.Window, board: chess.Board):
21722185
continue
21732186

21742187
if (is_new_game or is_exit_game or is_exit_app or
2175-
is_user_resigns or is_user_wins or is_user_draws):
2188+
is_user_resigns or is_user_wins or is_user_draws or
2189+
is_user_time_forfeit):
21762190
break
21772191

21782192
# Else if side to move is not human
@@ -2407,6 +2421,10 @@ def play_game(self, window: sg.Window, board: chess.Board):
24072421
self.game.headers['Result'] = '0-1' if self.is_user_white else '1-0'
24082422
self.game.headers['Termination'] = '{} resigns'.format(
24092423
'white' if self.is_user_white else 'black')
2424+
elif is_user_time_forfeit:
2425+
self.game.headers['Result'] = '0-1' if self.is_user_white else '1-0'
2426+
self.game.headers['Termination'] = '{} forfeits on time'.format(
2427+
'white' if self.is_user_white else 'black')
24102428
elif is_user_wins:
24112429
self.game.headers['Result'] = '1-0' if self.is_user_white else '0-1'
24122430
self.game.headers['Termination'] = 'Adjudication'
@@ -3515,6 +3533,12 @@ def main_loop(self):
35153533
tooltip='[%clk h:mm:ss] will appear as\n' +
35163534
'move comment and is shown in move\n' +
35173535
'list and saved in pgn file.')],
3536+
[sg.CBox('Adjudicate game on time forfeit',
3537+
key='time_forfeit_k',
3538+
default=self.is_time_forfeit_enabled,
3539+
tooltip='When enabled, the game is\n' +
3540+
'adjudicated when the player\n' +
3541+
'runs out of time.')],
35183542
[sg.OK(), sg.Cancel()],
35193543
]
35203544

@@ -3528,6 +3552,7 @@ def main_loop(self):
35283552
break
35293553
if e == 'OK':
35303554
self.is_save_time_left = v['save_time_left_k']
3555+
self.is_time_forfeit_enabled = v['time_forfeit_k']
35313556
break
35323557

35333558
window.UnHide()

0 commit comments

Comments
 (0)