Skip to content

Commit

Permalink
bugfix: reset time after move in MoveTime mode (not fully working)
Browse files Browse the repository at this point in the history
  • Loading branch information
LocutusOfPenguin committed Aug 23, 2017
1 parent c590bd9 commit 1360738
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion dgt/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ def _process_computer_move_done(self):
self._exit_menu()
if not self.dgtmenu.get_confirm():
DispatchDgt.fire(self.dgttranslate.text('K05_okpico'))
if self.dgtmenu.get_time_mode() == TimeMode.FIXED: # go back to a stopped time display
if self.dgtmenu.get_time_mode() == TimeMode.FIXED: # go back to a stopped time display and reset times
self.time_control.reset()
DispatchDgt.fire(Dgt.DISPLAY_TIME(force=True, wait=True, devs={'ser', 'i2c', 'web'}))

def _process_user_move_done(self, message):
Expand Down
13 changes: 10 additions & 3 deletions picochess.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ def think(game: chess.Board, timec: TimeControl, msg: Message):
If a move is found in the opening book, fire an event in a few seconds.
"""
# start_clock()

def reset_fixed_time():
nonlocal time_control
if time_control.mode == TimeMode.FIXED:
time_control.reset()

# reset_fixed_time()
DisplayMsg.show(msg)
start_clock()
book_res = searchmoves.book(bookreader, game.copy())
Expand Down Expand Up @@ -240,14 +246,15 @@ def user_move(move: chess.Move, sliding: bool):
nonlocal game
nonlocal done_move
nonlocal done_computer_fen
nonlocal time_control

logging.debug('user move [%s]', move)
if move not in game.legal_moves:
logging.warning('illegal move [%s]', move)
else:
stop_search_and_clock()
if interaction_mode in (Mode.NORMAL, Mode.OBSERVE, Mode.REMOTE) and not sliding:
time_control.add_inc(game.turn) # add fischer inc if not in pondering modes (tc is now stopped!)
time_control.add_time(game.turn)

done_computer_fen = None
done_move = chess.Move.null()
Expand Down Expand Up @@ -360,7 +367,7 @@ def process_fen(fen: str):
done_move = chess.Move.null()
if check_game_state(game, play_mode):
searchmoves.reset()
time_control.add_inc(not game.turn)
time_control.add_time(not game.turn)
if time_control.mode != TimeMode.FIXED:
start_clock()
legal_fens = compute_legal_fens(game.copy())
Expand Down
5 changes: 4 additions & 1 deletion timecontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _out_of_time(self, time_start):
logging.debug(txt, self.internal_time[self.active_color], display_color, time_start)
Observable.fire(Event.OUT_OF_TIME(color=self.active_color))

def add_inc(self, color):
def add_time(self, color):
"""Add the increment value to the color given."""
assert self.internal_running() is False, 'internal clock still running for: %s' % self.run_color
if self.mode == TimeMode.FISCHER:
Expand All @@ -144,6 +144,9 @@ def add_inc(self, color):
w_hms, b_hms = self._log_time()
logging.info('after internal time w:%s - b:%s', w_hms, b_hms)

if self.mode == TimeMode.FIXED:
self.reset()

def start_internal(self, color, log=True):
"""Start the internal clock."""
if not self.internal_running():
Expand Down

0 comments on commit 1360738

Please sign in to comment.