Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into deterministic-gam…
Browse files Browse the repository at this point in the history
…e-tests
  • Loading branch information
MarkZH committed Jan 4, 2025
2 parents 9f61ac7 + cfb8b8a commit 5da652e
Show file tree
Hide file tree
Showing 22 changed files with 388 additions and 361 deletions.
16 changes: 3 additions & 13 deletions .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r test_bot/test-requirements.txt
- name: Lint with flake8
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide.
# W503 and W504 are mutually exclusive. W504 is considered the best practice now.
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics --ignore=D,W503
- name: Lint with flake8-markdown
run: |
flake8-markdown "*.md"
flake8-markdown "wiki/*.md"
- name: Lint with flake8-docstrings
run: |
flake8 . --count --max-line-length=127 --statistics --select=D
# Check for python syntax errors and inconsistent code style.
ruff check --config test_bot/ruff.toml
5 changes: 4 additions & 1 deletion .github/workflows/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import datetime
import os

# File is part of an implicit namespace package. Add an `__init__.py`.
# ruff: noqa: INP001

with open("lib/versioning.yml") as version_file:
versioning_info = yaml.safe_load(version_file)

Expand All @@ -22,5 +25,5 @@
with open("lib/versioning.yml", "w") as version_file:
yaml.dump(versioning_info, version_file, sort_keys=False)

with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
print(f"new_version={new_version}", file=fh)
4 changes: 2 additions & 2 deletions extra_game_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from lib.types import OPTIONS_TYPE


def game_specific_options(game: model.Game) -> OPTIONS_TYPE:
def game_specific_options(game: model.Game) -> OPTIONS_TYPE: # noqa: ARG001
"""
Return a dictionary of engine options based on game aspects.
Expand All @@ -12,7 +12,7 @@ def game_specific_options(game: model.Game) -> OPTIONS_TYPE:
return {}


def is_supported_extra(challenge: model.Challenge) -> bool:
def is_supported_extra(challenge: model.Challenge) -> bool: # noqa: ARG001
"""
Determine whether to accept a challenge.
Expand Down
15 changes: 9 additions & 6 deletions homemade.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,21 @@
class ExampleEngine(MinimalEngine):
"""An example engine that all homemade engines inherit."""

pass


# Bot names and ideas from tom7's excellent eloWorld video

class RandomMove(ExampleEngine):
"""Get a random move."""

def search(self, board: chess.Board, *args: HOMEMADE_ARGS_TYPE) -> PlayResult:
def search(self, board: chess.Board, *args: HOMEMADE_ARGS_TYPE) -> PlayResult: # noqa: ARG002
"""Choose a random move."""
return PlayResult(random.choice(list(board.legal_moves)), None)


class Alphabetical(ExampleEngine):
"""Get the first move when sorted by san representation."""

def search(self, board: chess.Board, *args: HOMEMADE_ARGS_TYPE) -> PlayResult:
def search(self, board: chess.Board, *args: HOMEMADE_ARGS_TYPE) -> PlayResult: # noqa: ARG002
"""Choose the first move alphabetically."""
moves = list(board.legal_moves)
moves.sort(key=board.san)
Expand All @@ -46,7 +44,7 @@ def search(self, board: chess.Board, *args: HOMEMADE_ARGS_TYPE) -> PlayResult:
class FirstMove(ExampleEngine):
"""Get the first move when sorted by uci representation."""

def search(self, board: chess.Board, *args: HOMEMADE_ARGS_TYPE) -> PlayResult:
def search(self, board: chess.Board, *args: HOMEMADE_ARGS_TYPE) -> PlayResult: # noqa: ARG002
"""Choose the first move alphabetically in uci representation."""
moves = list(board.legal_moves)
moves.sort(key=str)
Expand All @@ -60,7 +58,12 @@ class ComboEngine(ExampleEngine):
This engine demonstrates how one can use `time_limit`, `draw_offered`, and `root_moves`.
"""

def search(self, board: chess.Board, time_limit: Limit, ponder: bool, draw_offered: bool, root_moves: MOVE) -> PlayResult:
def search(self,
board: chess.Board,
time_limit: Limit,
ponder: bool, # noqa: ARG002
draw_offered: bool,
root_moves: MOVE) -> PlayResult:
"""
Choose a move using multiple different methods.
Expand Down
15 changes: 8 additions & 7 deletions lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ def insert_default_values(CONFIG: CONFIG_DICT_TYPE) -> None:
for ponder in ["ponder", "uci_ponder"]:
set_config_default(CONFIG, section, key=ponder, default=False)

for type in ["hello", "goodbye"]:
for greeting in ["hello", "goodbye"]:
for target in ["", "_spectators"]:
set_config_default(CONFIG, "greeting", key=type + target, default="", force_empty_values=True)
set_config_default(CONFIG, "greeting", key=greeting + target, default="", force_empty_values=True)

if CONFIG["matchmaking"]["include_challenge_block_list"]:
CONFIG["matchmaking"]["block_list"].extend(CONFIG["challenge"]["block_list"])
Expand All @@ -259,7 +259,7 @@ def log_config(CONFIG: CONFIG_DICT_TYPE, alternate_log_function: Callable[[str],
:param CONFIG: The bot's config.
"""
logger_config = CONFIG.copy()
logger_config["token"] = "logger"
logger_config["token"] = "logger" # noqa: S105 (Possible hardcoded password)
destination = alternate_log_function or logger.debug
destination(f"Config:\n{yaml.dump(logger_config, sort_keys=False)}")
destination("====================")
Expand Down Expand Up @@ -321,10 +321,11 @@ def validate_config(CONFIG: CONFIG_DICT_TYPE) -> None:

pgn_directory = CONFIG["pgn_directory"]
in_docker = os.environ.get("LICHESS_BOT_DOCKER")
config_warn(not pgn_directory or not in_docker, "Games will be saved to '{}', please ensure this folder is in a mounted "
"volume; Using the Docker's container internal file system will prevent "
"you accessing the saved files and can lead to disk "
"saturation.".format(pgn_directory))
config_warn(not pgn_directory or not in_docker,
f"Games will be saved to '{pgn_directory}', please ensure this folder is in a mounted "
"volume; Using the Docker's container internal file system will prevent "
"you accessing the saved files and can lead to disk "
"saturation.")

valid_pgn_grouping_options = ["game", "opponent", "all"]
config_pgn_choice = CONFIG["pgn_file_grouping"]
Expand Down
6 changes: 3 additions & 3 deletions lib/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def react(self, line: ChatLine) -> None:
:param line: Information about the message.
"""
logger.info(f'*** {self.game.url()} [{line.room}] {line.username}: {line.text}')
logger.info(f"*** {self.game.url()} [{line.room}] {line.username}: {line.text}")
if line.text[0] == self.command_prefix:
self.command(line, line.text[1:].lower())

Expand All @@ -68,7 +68,7 @@ def command(self, line: ChatLine, cmd: str) -> None:
"""
from_self = line.username == self.game.username
is_eval = cmd.startswith("eval")
if cmd == "commands" or cmd == "help":
if cmd in ("commands", "help"):
self.send_reply(line,
"Supported commands: !wait (wait a minute for my first move), !name, "
"!eval (or any text starting with !eval), !queue")
Expand Down Expand Up @@ -97,7 +97,7 @@ def send_reply(self, line: ChatLine, reply: str) -> None:
:param line: Information about the original message that we reply to.
:param reply: The reply to send.
"""
logger.info(f'*** {self.game.url()} [{line.room}] {self.game.username}: {reply}')
logger.info(f"*** {self.game.url()} [{line.room}] {self.game.username}: {reply}")
self.li.chat(self.game.id, line.room, reply)

def send_message(self, room: str, message: str) -> None:
Expand Down
Loading

0 comments on commit 5da652e

Please sign in to comment.