Skip to content

Commit 64efd6b

Browse files
Add max_time option to online books (#1114)
1 parent 5ff3f76 commit 64efd6b

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

config.yml.default

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,29 @@ engine: # Engine settings.
4646
chessdb_book:
4747
enabled: false # Whether or not to use chessdb book.
4848
min_time: 20 # Minimum time (in seconds) to use chessdb book.
49+
max_time: 10800 # Maximum starting game time (in seconds) to use chessdb book.
4950
move_quality: "good" # One of "all", "good", "best".
5051
min_depth: 20 # Only for move_quality: "best".
5152
lichess_cloud_analysis:
5253
enabled: false # Whether or not to use lichess cloud analysis.
5354
min_time: 20 # Minimum time (in seconds) the bot must have to use cloud analysis.
55+
max_time: 10800 # Maximum starting game time (in seconds) the bot must have to use cloud analysis.
5456
move_quality: "best" # One of "good", "best".
5557
max_score_difference: 50 # Only for move_quality: "good". The maximum score difference (in cp) between the best move and the other moves.
5658
min_depth: 20
5759
min_knodes: 0
5860
lichess_opening_explorer:
5961
enabled: false
6062
min_time: 20
63+
max_time: 10800 # Maximum starting game time (in seconds) the bot must have to use the lichess opening explorer.
6164
source: "masters" # One of "lichess", "masters", "player"
6265
player_name: "" # The lichess username. Leave empty for the bot's username to be used. Used only when source is "player".
6366
sort: "winrate" # One of "winrate", "games_played"
6467
min_games: 10 # Minimum number of times a move must have been played to be chosen.
6568
online_egtb:
6669
enabled: false # Whether or not to enable online endgame tablebases.
6770
min_time: 20 # Minimum time (in seconds) the bot must have to use online EGTBs.
71+
max_time: 10800 # Maximum starting game time (in seconds) the bot must have to use online EGTBs.
6872
max_pieces: 7 # Maximum number of pieces on the board to use endgame tablebases.
6973
source: "lichess" # One of "lichess", "chessdb".
7074
move_quality: "best" # One of "best" or "suggest" (it takes all the moves with the same WDL and tells the engine to only consider these; will move instantly if there is only 1 "good" move).

lib/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,24 @@ def insert_default_values(CONFIG: CONFIG_DICT_TYPE) -> None:
169169
set_config_default(CONFIG, "engine", "online_moves", "online_egtb", key="enabled", default=False)
170170
set_config_default(CONFIG, "engine", "online_moves", "online_egtb", key="source", default="lichess")
171171
set_config_default(CONFIG, "engine", "online_moves", "online_egtb", key="min_time", default=20)
172+
set_config_default(CONFIG, "engine", "online_moves", "online_egtb", key="max_time", default=10800)
172173
set_config_default(CONFIG, "engine", "online_moves", "online_egtb", key="max_pieces", default=7)
173174
set_config_default(CONFIG, "engine", "online_moves", "online_egtb", key="move_quality", default="best")
174175
set_config_default(CONFIG, "engine", "online_moves", "chessdb_book", key="enabled", default=False)
175176
set_config_default(CONFIG, "engine", "online_moves", "chessdb_book", key="min_time", default=20)
177+
set_config_default(CONFIG, "engine", "online_moves", "chessdb_book", key="max_time", default=10800)
176178
set_config_default(CONFIG, "engine", "online_moves", "chessdb_book", key="move_quality", default="good")
177179
set_config_default(CONFIG, "engine", "online_moves", "chessdb_book", key="min_depth", default=20)
178180
set_config_default(CONFIG, "engine", "online_moves", "lichess_cloud_analysis", key="enabled", default=False)
179181
set_config_default(CONFIG, "engine", "online_moves", "lichess_cloud_analysis", key="min_time", default=20)
182+
set_config_default(CONFIG, "engine", "online_moves", "lichess_cloud_analysis", key="max_time", default=10800)
180183
set_config_default(CONFIG, "engine", "online_moves", "lichess_cloud_analysis", key="move_quality", default="best")
181184
set_config_default(CONFIG, "engine", "online_moves", "lichess_cloud_analysis", key="min_depth", default=20)
182185
set_config_default(CONFIG, "engine", "online_moves", "lichess_cloud_analysis", key="min_knodes", default=0)
183186
set_config_default(CONFIG, "engine", "online_moves", "lichess_cloud_analysis", key="max_score_difference", default=50)
184187
set_config_default(CONFIG, "engine", "online_moves", "lichess_opening_explorer", key="enabled", default=False)
185188
set_config_default(CONFIG, "engine", "online_moves", "lichess_opening_explorer", key="min_time", default=20)
189+
set_config_default(CONFIG, "engine", "online_moves", "lichess_opening_explorer", key="max_time", default=10800)
186190
set_config_default(CONFIG, "engine", "online_moves", "lichess_opening_explorer", key="source", default="masters")
187191
set_config_default(CONFIG, "engine", "online_moves", "lichess_opening_explorer", key="player_name", default="")
188192
set_config_default(CONFIG, "engine", "online_moves", "lichess_opening_explorer", key="sort", default="winrate")

lib/engine_wrapper.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,8 @@ def get_chessdb_move(li: lichess.Lichess, board: chess.Board, game: model.Game,
835835
use_chessdb = chessdb_cfg.enabled
836836
time_left = msec(game.state[wbtime(board)])
837837
min_time = seconds(chessdb_cfg.min_time)
838-
if not use_chessdb or time_left < min_time or board.uci_variant != "chess":
838+
max_time = seconds(chessdb_cfg.max_time)
839+
if not use_chessdb or time_left < min_time or game.clock_initial > max_time or board.uci_variant != "chess":
839840
return None, {}
840841

841842
move = None
@@ -872,8 +873,9 @@ def get_lichess_cloud_move(li: lichess.Lichess, board: chess.Board, game: model.
872873
side = wbtime(board)
873874
time_left = msec(game.state[side])
874875
min_time = seconds(lichess_cloud_cfg.min_time)
876+
max_time = seconds(lichess_cloud_cfg.max_time)
875877
use_lichess_cloud = lichess_cloud_cfg.enabled
876-
if not use_lichess_cloud or time_left < min_time:
878+
if not use_lichess_cloud or time_left < min_time or game.clock_initial > max_time:
877879
return None, {}
878880

879881
move = None
@@ -925,8 +927,10 @@ def get_opening_explorer_move(li: lichess.Lichess, board: chess.Board, game: mod
925927
side = wbtime(board)
926928
time_left = msec(game.state[side])
927929
min_time = seconds(opening_explorer_cfg.min_time)
930+
max_time = seconds(opening_explorer_cfg.max_time)
928931
source = opening_explorer_cfg.source
929-
if not opening_explorer_cfg.enabled or time_left < min_time or source == "master" and board.uci_variant != "chess":
932+
if (not opening_explorer_cfg.enabled or time_left < min_time or game.clock_initial > max_time or source == "master"
933+
and board.uci_variant != "chess"):
930934
return None, {}
931935

932936
move = None
@@ -980,9 +984,11 @@ def get_online_egtb_move(li: lichess.Lichess, board: chess.Board, game: model.Ga
980984
pieces = chess.popcount(board.occupied)
981985
source = online_egtb_cfg.source
982986
minimum_time = seconds(online_egtb_cfg.min_time)
987+
maximum_time = seconds(online_egtb_cfg.max_time)
983988
time_left = game.state[wbtime(board)]
984989
if (not use_online_egtb
985990
or msec(time_left) < minimum_time
991+
or game.clock_initial > maximum_time
986992
or board.uci_variant not in ["chess", "antichess", "atomic"]
987993
and source == "lichess"
988994
or board.uci_variant != "chess"

wiki/Configure-lichess-bot.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ will precede the `go` command to start thinking with `sd 5`. The other `go_comma
103103
- Configurations common to all:
104104
- `enabled`: Whether to use the database at all.
105105
- `min_time`: The minimum time in seconds on the game clock necessary to allow the online database to be consulted.
106+
- `max_time`: The maximum starting game time in seconds on the game clock necessary to allow the online database to be consulted.
106107
- `move_quality`: Choice of `"all"` (`chessdb_book` only), `"good"` (all except `online_egtb`), `"best"`, or `"suggest"` (`online_egtb` only).
107108
- `all`: Choose a random move from all legal moves.
108109
- `best`: Choose only the highest scoring move.

0 commit comments

Comments
 (0)