Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
M-DinhHoangViet committed Jan 29, 2024
1 parent 3fb8277 commit 24b59ac
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lichess_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ def __init__(self, api: API, game_information: Game_Information, config: dict) -
opponent = self.game_info.black_opponent if self.is_white else self.game_info.white_opponent
self.engine = Engine.from_config(config['engines'][self._get_engine_key()], config['syzygy'], opponent)
self.scores: list[chess.engine.PovScore | None] = []
consecutive_draw_moves = config['offer_draw']['consecutive_moves']
self.draw_scores: deque[chess.engine.PovScore | None] = deque(maxlen=consecutive_draw_moves)
consecutive_resign_moves = config['resign']['consecutive_moves']
self.resign_scores: deque[chess.engine.PovScore | None] = deque(maxlen=consecutive_resign_moves)
self.last_message = 'No eval available yet.'
self.last_pv: list[chess.Move] = []

Expand Down Expand Up @@ -483,7 +479,7 @@ def _make_gaviota_move(self) -> Move_Response | None:
def _make_syzygy_move(self) -> Move_Response | None:
assert self.syzygy_tablebase

if chess.popcount(self.board.occupied) > self.config['syzygy']['max_pieces']:
if chess.popcount(self.board.occupied) > self.config['syzygy']['max_pieces'] or self._has_mate_score():
return

best_moves: list[chess.Move] = []
Expand Down Expand Up @@ -605,7 +601,7 @@ def _make_egtb_move(self) -> Move_Response | None:
is_endgame = chess.popcount(self.board.occupied) <= max_pieces
has_time = self._has_time(self.config['online_moves']['online_egtb']['min_time'])

if not is_endgame or not has_time:
if not is_endgame or not has_time or self._has_mate_score():
return

timeout = self.config['online_moves']['online_egtb']['timeout']
Expand Down Expand Up @@ -820,6 +816,13 @@ def _has_time(self, min_time: float) -> bool:

return self.own_time >= min_time

def _has_mate_score(self) -> bool:
for score in filter(None, reversed(self.scores)):
mate = score.relative.mate()
return mate is not None and mate > 0

return False

def _reduce_own_time(self, seconds: float) -> None:
if self.is_white:
self.white_time -= seconds
Expand Down

0 comments on commit 24b59ac

Please sign in to comment.