Skip to content

Commit

Permalink
Add challenge preference
Browse files Browse the repository at this point in the history
  • Loading branch information
AttackingOrDefending authored Jun 18, 2024
1 parent 36a3b58 commit 54780b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions config.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 12 additions & 4 deletions lichess-bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions wiki/Configure-lichess-bot.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 54780b9

Please sign in to comment.