Skip to content

Commit

Permalink
Replace Sjeng with Arasan and add Stockfish for Mac (lichess-bot-devs…
Browse files Browse the repository at this point in the history
  • Loading branch information
AttackingOrDefending authored Oct 15, 2024
1 parent 516d04d commit f545037
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest, windows-latest, macos-latest]
python: [3.9, "3.13"]


Expand Down
3 changes: 3 additions & 0 deletions test_bot/buggy_engine_macos
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

python3 test_bot/buggy_engine.py
63 changes: 33 additions & 30 deletions test_bot/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from lib import lichess_bot

platform = sys.platform
archive_ext = "zip" if platform == "win32" else "tar"
file_extension = ".exe" if platform == "win32" else ""
stockfish_path = f"./TEMP/sf{file_extension}"

Expand All @@ -35,9 +36,8 @@ def download_sf() -> None:
if os.path.exists(stockfish_path):
return

windows_or_linux = "windows" if platform == "win32" else "ubuntu"
sf_base = f"stockfish-{windows_or_linux}-x86-64-modern"
archive_ext = "zip" if platform == "win32" else "tar"
windows_linux_mac = "windows" if platform == "win32" else ("macos" if platform == "darwin" else "ubuntu")
sf_base = f"stockfish-{windows_linux_mac}-x86-64-modern"
archive_link = f"https://github.com/official-stockfish/Stockfish/releases/download/sf_16/{sf_base}.{archive_ext}"

response = requests.get(archive_link, allow_redirects=True)
Expand All @@ -53,7 +53,7 @@ def download_sf() -> None:
exe_ext = ".exe" if platform == "win32" else ""
shutil.copyfile(f"./TEMP/stockfish/{sf_base}{exe_ext}", stockfish_path)

if windows_or_linux == "ubuntu":
if platform != "win32":
st = os.stat(stockfish_path)
os.chmod(stockfish_path, st.st_mode | stat.S_IEXEC)

Expand All @@ -72,18 +72,24 @@ def download_lc0() -> None:
zip_ref.extractall("./TEMP/")


def download_sjeng() -> None:
"""Download Sjeng."""
if os.path.exists("./TEMP/sjeng.exe"):
def download_arasan() -> None:
"""Download Arasan."""
if os.path.exists(f"./TEMP/arasan{file_extension}"):
return

response = requests.get("https://sjeng.org/ftp/Sjeng112.zip", allow_redirects=True)
if platform == "win32":
response = requests.get("https://arasanchess.org/arasan24.2.2.zip", allow_redirects=True)
else:
response = requests.get("https://arasanchess.org/arasan-linux-binaries-24.2.2.tar.gz", allow_redirects=True)
response.raise_for_status()
with open("./TEMP/sjeng_zip.zip", "wb") as file:
with open(f"./TEMP/arasan.{archive_ext}", "wb") as file:
file.write(response.content)
with zipfile.ZipFile("./TEMP/sjeng_zip.zip", "r") as zip_ref:
zip_ref.extractall("./TEMP/")
shutil.copyfile("./TEMP/Release/Sjeng112.exe", "./TEMP/sjeng.exe")
archive_open = zipfile.ZipFile if archive_ext == "zip" else tarfile.TarFile
with archive_open(f"./TEMP/arasan.{archive_ext}", "r") as archive_ref:
archive_ref.extractall("./TEMP/")
shutil.copyfile(f"./TEMP/arasanx-64{file_extension}", f"./TEMP/arasan{file_extension}")
if platform != "win32":
st = os.stat(f"./TEMP/arasan{file_extension}")
os.chmod(f"./TEMP/arasan{file_extension}", st.st_mode | stat.S_IEXEC)


os.makedirs("TEMP", exist_ok=True)
Expand Down Expand Up @@ -211,8 +217,6 @@ def run_bot(raw_config: CONFIG_DICT_TYPE, logging_level: int, opponent_path: str
@pytest.mark.timeout(180, method="thread")
def test_sf() -> None:
"""Test lichess-bot with Stockfish (UCI)."""
if platform != "linux" and platform != "win32":
pytest.skip("Platform must be Linux or Windows.")
with open("./config.yml.default") as file:
CONFIG = yaml.safe_load(file)
CONFIG["token"] = ""
Expand Down Expand Up @@ -261,28 +265,28 @@ def test_lc0() -> None:
"bo vs b - zzzzzzzz.pgn"))


@pytest.mark.timeout(180, method="thread")
def test_sjeng() -> None:
"""Test lichess-bot with Sjeng (XBoard)."""
if platform != "win32":
pytest.skip("Platform must be Windows.")
@pytest.mark.timeout(150, method="thread")
def test_arasan() -> None:
"""Test lichess-bot with Arasan (XBoard)."""
if platform != "linux" and platform != "win32":
pytest.skip("Platform must be Windows or Linux.")
with open("./config.yml.default") as file:
CONFIG = yaml.safe_load(file)
CONFIG["token"] = ""
CONFIG["engine"]["dir"] = "./TEMP/"
CONFIG["engine"]["working_dir"] = "./TEMP/"
CONFIG["engine"]["protocol"] = "xboard"
CONFIG["engine"]["name"] = "sjeng.exe"
CONFIG["engine"]["name"] = f"arasan{file_extension}"
CONFIG["engine"]["ponder"] = False
CONFIG["pgn_directory"] = "TEMP/sjeng_game_record"
logger.info("Downloading Sjeng")
CONFIG["pgn_directory"] = "TEMP/arasan_game_record"
logger.info("Downloading Arasan")
try:
download_sjeng()
download_arasan()
except Exception:
logger.exception("Could not download the Sjeng chess engine")
pytest.skip("Could not download the Sjeng chess engine")
logger.exception("Could not download the Arasan chess engine")
pytest.skip("Could not download the Arasan chess engine")
win = run_bot(CONFIG, logging_level)
logger.info("Finished Testing Sjeng")
logger.info("Finished Testing Arasan")
assert win
assert os.path.isfile(os.path.join(CONFIG["pgn_directory"],
"bo vs b - zzzzzzzz.pgn"))
Expand All @@ -291,9 +295,6 @@ def test_sjeng() -> None:
@pytest.mark.timeout(180, method="thread")
def test_homemade() -> None:
"""Test lichess-bot with a homemade engine running Stockfish (Homemade)."""
if platform != "linux" and platform != "win32":
pytest.skip("Platform must be Linux or Windows.")

try:
download_sf()
except Exception:
Expand Down Expand Up @@ -328,6 +329,8 @@ def engine_path(CONFIG: CONFIG_DICT_TYPE) -> str:
if platform == "win32":
path += ".bat"
else:
if platform == "darwin":
path += "_macos"
st = os.stat(path)
os.chmod(path, st.st_mode | stat.S_IEXEC)
return path
Expand Down

0 comments on commit f545037

Please sign in to comment.