Skip to content

Commit

Permalink
Merge pull request #1113 from MarkZH/options-fix
Browse files Browse the repository at this point in the history
Fix error when parsing UCI options
  • Loading branch information
niklasf committed Oct 9, 2024
1 parent 08697b2 commit fa4f014
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
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 @@ -3134,6 +3134,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

0 comments on commit fa4f014

Please sign in to comment.