From 54780b94df0d9fb29db3c8b8ba19c55587fe34c7 Mon Sep 17 00:00:00 2001 From: Ioannis Pantidis <40605232+AttackingOrDefending@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:10:44 +0300 Subject: [PATCH] Add challenge preference --- config.yml.default | 1 + lichess-bot.py | 16 ++++++++++++---- wiki/Configure-lichess-bot.md | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/config.yml.default b/config.yml.default index c3f4d2fc5..f86f3ea39 100644 --- a/config.yml.default +++ b/config.yml.default @@ -127,6 +127,7 @@ correspondence: challenge: # Incoming challenges. concurrency: 1 # Number of games to play simultaneously. sort_by: "best" # Possible values: "best" and "first". + preference: "none" # Possible values: "none", "human", "bot". accept_bot: true # Accepts challenges coming from other bots. only_bot: false # Accept challenges by bots only. max_increment: 20 # Maximum amount of increment to accept a challenge in seconds. The max is 180. Set to 0 for no increment. diff --git a/lichess-bot.py b/lichess-bot.py index a5c02cbf0..ca72880cf 100644 --- a/lichess-bot.py +++ b/lichess-bot.py @@ -491,10 +491,18 @@ def sort_challenges(challenge_queue: MULTIPROCESSING_LIST_TYPE, challenge_config They can be sorted either by rating (the best challenger is accepted first), or by time (the first challenger is accepted first). """ - if challenge_config.sort_by == "best": - list_c = list(challenge_queue) - list_c.sort(key=lambda c: -c.score()) - challenge_queue[:] = list_c + if challenge_config.preference != "none": + list_challengers = list(challenge_queue) + humans = [challenger for challenger in list_challengers if not challenger.challenger.is_bot] + bots = [challenger for challenger in list_challengers if challenger.challenger.is_bot] + if challenge_config.sort_by == "best": + humans.sort(key=lambda challenger: challenger.score(), reverse=True) + bots.sort(key=lambda challenger: challenger.score(), reverse=True) + challenge_queue[:] = (humans + bots) if challenge_config.preference == "human" else (bots + humans) + elif challenge_config.sort_by == "best": + list_challengers = list(challenge_queue) + list_challengers.sort(key=lambda challenger: challenger.score(), reverse=True) + challenge_queue[:] = list_challengers def game_is_active(li: LICHESS_TYPE, game_id: str) -> bool: diff --git a/wiki/Configure-lichess-bot.md b/wiki/Configure-lichess-bot.md index 84e5c861c..0d3269cc0 100644 --- a/wiki/Configure-lichess-bot.md +++ b/wiki/Configure-lichess-bot.md @@ -154,6 +154,7 @@ will precede the `go` command to start thinking with `sd 5`. The other `go_comma - `challenge`: Control what kind of games for which the bot should accept challenges. All of the following options must be satisfied by a challenge to be accepted. - `concurrency`: The maximum number of games to play simultaneously. - `sort_by`: Whether to start games by the best rated/titled opponent `"best"` or by first-come-first-serve `"first"`. + - `preference`: Whether to prioritize human opponents, bot opponents, or treat them equally. - `accept_bot`: Whether to accept challenges from other bots. - `only_bot`: Whether to only accept challenges from other bots. - `max_increment`: The maximum value of time increment.