Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when parsing UCI options #1113

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/setup-ubuntu-latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ sudo apt-get install -y stockfish
# Crafty
sudo apt-get install -y crafty

# Fairy-stockfish
sudo apt-get install -y fairy-stockfish

# Gaviota libgtb
git clone https://github.com/michiguel/Gaviota-Tablebases.git --depth 1
cd Gaviota-Tablebases
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/setup-windows-latest.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh -e

echo Download ...
echo Download stockfish ...
choco install wget
wget https://github.com/official-stockfish/Stockfish/releases/download/sf_16/stockfish-windows-x86-64-avx2.zip

Expand All @@ -10,3 +10,7 @@ echo Unzip ..
echo Setup path ...
mv stockfish-windows-x86-64-avx2.exe stockfish.exe
pwd >> $GITHUB_PATH

echo Download fairy-stockfish ...
wget https://github.com/fairy-stockfish/Fairy-Stockfish/releases/latest/download/fairy-stockfish-largeboard_x86-64.exe
mv fairy-stockfish-largeboard_x86-64.exe fairy-stockfish.exe
3 changes: 2 additions & 1 deletion chess/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,8 @@ def _option(self, arg: str) -> None:
var = []

parameters = list(option_parts.keys()) + ['var']
option_regex = fr"\s*({'|'.join(parameters)})\s*"
inner_regex = '|'.join([fr"\b{parameter}\b" for parameter in parameters])
option_regex = fr"\s*({inner_regex})\s*"
for token in re.split(option_regex, arg.strip()):
if token == "var" or (token in option_parts and not option_parts[token]):
current_parameter = token
Expand Down
20 changes: 20 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3142,6 +3142,26 @@ def test_sf_quit(self):
with self.assertRaises(chess.engine.EngineTerminatedError), engine:
engine.ping()

@catchAndSkip(FileNotFoundError, "need fairy-stockfish")
def test_fairy_sf_initialize(self):
with chess.engine.SimpleEngine.popen_uci("fairy-stockfish", setpgrp=True, debug=True):
pass

def test_uci_option_parse(self):
async def main():
protocol = chess.engine.UciProtocol()
mock = chess.engine.MockTransport(protocol)

mock.expect("uci", ["option name UCI_Variant type combo default chess var bughouse var chess var mini var minishogi var threekings", "uciok"])
await protocol.initialize()
mock.assert_done()

mock.expect("isready", ["readyok"])
await protocol.ping()
mock.assert_done()

asyncio.run(main())

@catchAndSkip(FileNotFoundError, "need crafty")
def test_crafty_play_to_mate(self):
logging.disable(logging.WARNING)
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ passenv = LD_LIBRARY_PATH
whitelist_externals =
stockfish
crafty
fairy-stockfish
commands =
python test.py --verbose
python -m doctest README.rst --verbose
Expand Down
Loading