Skip to content

Commit fa4f014

Browse files
committed
Merge pull request #1113 from MarkZH/options-fix
Fix error when parsing UCI options
1 parent 08697b2 commit fa4f014

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

.github/workflows/setup-ubuntu-latest.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ sudo apt-get install -y stockfish
66
# Crafty
77
sudo apt-get install -y crafty
88

9+
# Fairy-stockfish
10+
sudo apt-get install -y fairy-stockfish
11+
912
# Gaviota libgtb
1013
git clone https://github.com/michiguel/Gaviota-Tablebases.git --depth 1
1114
cd Gaviota-Tablebases

.github/workflows/setup-windows-latest.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh -e
22

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

@@ -10,3 +10,7 @@ echo Unzip ..
1010
echo Setup path ...
1111
mv stockfish-windows-x86-64-avx2.exe stockfish.exe
1212
pwd >> $GITHUB_PATH
13+
14+
echo Download fairy-stockfish ...
15+
wget https://github.com/fairy-stockfish/Fairy-Stockfish/releases/latest/download/fairy-stockfish-largeboard_x86-64.exe
16+
mv fairy-stockfish-largeboard_x86-64.exe fairy-stockfish.exe

chess/engine.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,8 @@ def _option(self, arg: str) -> None:
13671367
var = []
13681368

13691369
parameters = list(option_parts.keys()) + ['var']
1370-
option_regex = fr"\s*({'|'.join(parameters)})\s*"
1370+
inner_regex = '|'.join([fr"\b{parameter}\b" for parameter in parameters])
1371+
option_regex = fr"\s*({inner_regex})\s*"
13711372
for token in re.split(option_regex, arg.strip()):
13721373
if token == "var" or (token in option_parts and not option_parts[token]):
13731374
current_parameter = token

test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,6 +3134,26 @@ def test_sf_quit(self):
31343134
with self.assertRaises(chess.engine.EngineTerminatedError), engine:
31353135
engine.ping()
31363136

3137+
@catchAndSkip(FileNotFoundError, "need fairy-stockfish")
3138+
def test_fairy_sf_initialize(self):
3139+
with chess.engine.SimpleEngine.popen_uci("fairy-stockfish", setpgrp=True, debug=True):
3140+
pass
3141+
3142+
def test_uci_option_parse(self):
3143+
async def main():
3144+
protocol = chess.engine.UciProtocol()
3145+
mock = chess.engine.MockTransport(protocol)
3146+
3147+
mock.expect("uci", ["option name UCI_Variant type combo default chess var bughouse var chess var mini var minishogi var threekings", "uciok"])
3148+
await protocol.initialize()
3149+
mock.assert_done()
3150+
3151+
mock.expect("isready", ["readyok"])
3152+
await protocol.ping()
3153+
mock.assert_done()
3154+
3155+
asyncio.run(main())
3156+
31373157
@catchAndSkip(FileNotFoundError, "need crafty")
31383158
def test_crafty_play_to_mate(self):
31393159
logging.disable(logging.WARNING)

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ passenv = LD_LIBRARY_PATH
66
whitelist_externals =
77
stockfish
88
crafty
9+
fairy-stockfish
910
commands =
1011
python test.py --verbose
1112
python -m doctest README.rst --verbose

0 commit comments

Comments
 (0)