Skip to content

Commit

Permalink
Merge branch 'lichess-bot-devs:master' into more_efficient_probing
Browse files Browse the repository at this point in the history
  • Loading branch information
adbar authored Jan 8, 2025
2 parents 5863fbf + e4c1939 commit 37eeafa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/versioning.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lichess_bot_version: 2025.1.4.3
lichess_bot_version: 2025.1.8.2
minimum_python_version: '3.9'
deprecated_python_version: '3.8'
deprecation_date: 2023-05-01
2 changes: 1 addition & 1 deletion test_bot/test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pytest==8.3.4
pytest-timeout==2.3.1
ruff==0.8.5
ruff==0.8.6
mypy==1.14.1
types-requests==2.32.0.20241016
types-PyYAML==6.0.12.20241230
72 changes: 45 additions & 27 deletions test_bot/test_external_moves.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import chess.engine
from datetime import timedelta
from copy import deepcopy
from requests.exceptions import ConnectionError, HTTPError, ReadTimeout
from requests.exceptions import ConnectionError, HTTPError, ReadTimeout, RequestException
from http.client import RemoteDisconnected
from lib.types import OnlineType, GameEventType
from typing import Optional, Union, cast
Expand Down Expand Up @@ -47,6 +47,14 @@ def online_book_get() -> OnlineType:

return online_book_get()

def is_website_up(self, url: str) -> bool:
"""Check if a website is up."""
try:
self.other_session.get(url, timeout=2)
return True
except RequestException:
return False


def get_configs() -> tuple[Configuration, Configuration, Configuration, Configuration]:
"""Create the configs used for the tests."""
Expand Down Expand Up @@ -132,39 +140,49 @@ def test_external_moves() -> None:
endgame_wdl1_fen = "6N1/3n4/3k1b2/8/8/7Q/1r6/5K2 b - - 6 9"
endgame_wdl0_fen = "6N1/3n4/3k1b2/8/8/7Q/5K2/1r6 b - - 8 10"

is_lichess_org_up = li.is_website_up("https://lichess.org/api/cloud-eval")
is_lichess_ovh_up = li.is_website_up("https://tablebase.lichess.ovh/standard")
is_chessdb_cn_up = li.is_website_up("https://www.chessdb.cn/cdb.php")

# Test lichess_cloud_analysis.
assert get_online_move_wrapper(li, chess.Board(starting_fen), game, online_cfg, draw_or_resign_cfg).move is not None
assert get_online_move_wrapper(li, chess.Board(opening_fen), game, online_cfg, draw_or_resign_cfg).move is not None
assert get_online_move_wrapper(li, chess.Board(middlegame_fen), game, online_cfg, draw_or_resign_cfg).move is None
if is_lichess_org_up:
assert get_online_move_wrapper(li, chess.Board(starting_fen), game, online_cfg, draw_or_resign_cfg).move is not None
assert get_online_move_wrapper(li, chess.Board(opening_fen), game, online_cfg, draw_or_resign_cfg).move is not None
assert get_online_move_wrapper(li, chess.Board(middlegame_fen), game, online_cfg, draw_or_resign_cfg).move is None

# Test chessdb_book.
assert get_online_move_wrapper(li, chess.Board(starting_fen), game, online_cfg_2, draw_or_resign_cfg).move is not None
assert get_online_move_wrapper(li, chess.Board(opening_fen), game, online_cfg_2, draw_or_resign_cfg).move is not None
assert get_online_move_wrapper(li, chess.Board(middlegame_fen), game, online_cfg_2, draw_or_resign_cfg).move is None
if is_chessdb_cn_up:
assert get_online_move_wrapper(li, chess.Board(starting_fen), game, online_cfg_2, draw_or_resign_cfg).move is not None
assert get_online_move_wrapper(li, chess.Board(opening_fen), game, online_cfg_2, draw_or_resign_cfg).move is not None
assert get_online_move_wrapper(li, chess.Board(middlegame_fen), game, online_cfg_2, draw_or_resign_cfg).move is None

# Test online_egtb with lichess.
assert get_online_move_wrapper(li, chess.Board(endgame_wdl2_fen), game, online_cfg, draw_or_resign_cfg).resigned
assert get_online_move_wrapper(li, chess.Board(endgame_wdl0_fen), game, online_cfg, draw_or_resign_cfg).draw_offered
wdl1_move = get_online_move_wrapper(li, chess.Board(endgame_wdl1_fen), game, online_cfg, draw_or_resign_cfg)
assert not wdl1_move.resigned and not wdl1_move.draw_offered
# Test with reversed colors.
assert get_online_move_wrapper(li, chess.Board(endgame_wdl2_fen).mirror(), game, online_cfg, draw_or_resign_cfg).resigned
assert get_online_move_wrapper(li, chess.Board(endgame_wdl0_fen).mirror(), game, online_cfg,
draw_or_resign_cfg).draw_offered
wdl1_move = get_online_move_wrapper(li, chess.Board(endgame_wdl1_fen).mirror(), game, online_cfg, draw_or_resign_cfg)
assert not wdl1_move.resigned and not wdl1_move.draw_offered
if is_lichess_ovh_up:
assert get_online_move_wrapper(li, chess.Board(endgame_wdl2_fen), game, online_cfg, draw_or_resign_cfg).resigned
assert get_online_move_wrapper(li, chess.Board(endgame_wdl0_fen), game, online_cfg, draw_or_resign_cfg).draw_offered
wdl1_move = get_online_move_wrapper(li, chess.Board(endgame_wdl1_fen), game, online_cfg, draw_or_resign_cfg)
assert not wdl1_move.resigned and not wdl1_move.draw_offered
# Test with reversed colors.
assert get_online_move_wrapper(li, chess.Board(endgame_wdl2_fen).mirror(), game, online_cfg,
draw_or_resign_cfg).resigned
assert get_online_move_wrapper(li, chess.Board(endgame_wdl0_fen).mirror(), game, online_cfg,
draw_or_resign_cfg).draw_offered
wdl1_move = get_online_move_wrapper(li, chess.Board(endgame_wdl1_fen).mirror(), game, online_cfg, draw_or_resign_cfg)
assert not wdl1_move.resigned and not wdl1_move.draw_offered

# Test online_egtb with chessdb.
assert get_online_move_wrapper(li, chess.Board(endgame_wdl2_fen), game, online_cfg_2, draw_or_resign_cfg).resigned
assert get_online_move_wrapper(li, chess.Board(endgame_wdl0_fen), game, online_cfg_2, draw_or_resign_cfg).draw_offered
wdl1_move = get_online_move_wrapper(li, chess.Board(endgame_wdl1_fen), game, online_cfg_2, draw_or_resign_cfg)
assert not wdl1_move.resigned and not wdl1_move.draw_offered
# Test with reversed colors.
assert get_online_move_wrapper(li, chess.Board(endgame_wdl2_fen).mirror(), game, online_cfg_2, draw_or_resign_cfg).resigned
assert get_online_move_wrapper(li, chess.Board(endgame_wdl0_fen).mirror(), game, online_cfg_2,
draw_or_resign_cfg).draw_offered
wdl1_move = get_online_move_wrapper(li, chess.Board(endgame_wdl1_fen).mirror(), game, online_cfg_2, draw_or_resign_cfg)
assert not wdl1_move.resigned and not wdl1_move.draw_offered
if is_chessdb_cn_up:
assert get_online_move_wrapper(li, chess.Board(endgame_wdl2_fen), game, online_cfg_2, draw_or_resign_cfg).resigned
assert get_online_move_wrapper(li, chess.Board(endgame_wdl0_fen), game, online_cfg_2, draw_or_resign_cfg).draw_offered
wdl1_move = get_online_move_wrapper(li, chess.Board(endgame_wdl1_fen), game, online_cfg_2, draw_or_resign_cfg)
assert not wdl1_move.resigned and not wdl1_move.draw_offered
# Test with reversed colors.
assert get_online_move_wrapper(li, chess.Board(endgame_wdl2_fen).mirror(), game, online_cfg_2,
draw_or_resign_cfg).resigned
assert get_online_move_wrapper(li, chess.Board(endgame_wdl0_fen).mirror(), game, online_cfg_2,
draw_or_resign_cfg).draw_offered
wdl1_move = get_online_move_wrapper(li, chess.Board(endgame_wdl1_fen).mirror(), game, online_cfg_2, draw_or_resign_cfg)
assert not wdl1_move.resigned and not wdl1_move.draw_offered

# Test opening book.
assert get_book_move(chess.Board(opening_fen), game, polyglot_cfg).move == chess.Move.from_uci("h4f6")

0 comments on commit 37eeafa

Please sign in to comment.