Skip to content

Commit 97152ae

Browse files
committed
Allow command line parameters for engines (to support lc0 backend selection)
1 parent 8643015 commit 97152ae

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ A sample content for stockfish in Linux would be:
9595
}
9696
```
9797

98+
An example for `lc0` (Leela Chess Zero) with CUDA backend:
99+
100+
```json
101+
"name": "lc0",
102+
"path": "/home/user/lc0/build/release/lc0",
103+
"engine_params": ["--backend=cuda"],
104+
"active": true
105+
```
106+
107+
Note: The field "engine_params" is optional and can contain a list of additional parameters for the engine that are given on start.
108+
98109
Note: Windows users need to use paths with `\\` or `/` for proper json encoding.
99110

100111
### Start
@@ -142,7 +153,7 @@ Do NOT use `sudo` on subsequent starts, or the communication might fail. If scan
142153

143154
All engine descriptions in directory 'engines' will now contain the default-UCI options for each engine. Those can be edited e.g. to enable tablebases or other UCI options.
144155

145-
![Console mchess](https://raw.github.com/domschl/python-mchess/master/images/MchessAlpha.png)
156+
![Console mchess](https://raw.github.com/domschl/python-mchess/master/images/TurquoiseAlpha.png)
146157
_Console output of python module, allows terminal interactions: enter 'help' for an overview of console commands_
147158

148159
## Usage
@@ -215,6 +226,7 @@ The mandatory fields in `<engine-name>.json` are:
215226
| -------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
216227
| `name` | e.g. `"stockfish"` | Name of executable of the engine, e.g. `stockfish`. Unfortunately this name must be precisely equal to the name of the json file, and must be referenced in `preferences.json` as either `computer_player_name` or `computer_player2_name` and within `active_agents`. That is subject to improvement in the future. |
217228
| `path` | e.g. `"/usr/local/bin/stockfish"` | Path to the engine executable. Windows users must either use `\\` or `/` in json files as path separators. |
229+
| `engine_params` | `["--backend=cuda"]` | Optional list of additional parameters for the engine that are given on start. This entry should be ommited, if no parameter are necessary. |
218230
| `active` | `true` | `mchess.py` currently uses only the first two active engines. If more engines are configured, the unused ones should be set to `false` |
219231

220232
Once the UCI engine is started for the first time, the UCI-options of the engine are enumerated and added to the `<engine-name>.json` config file. That allows further customization of each engine. Some commonly used options are:

images/TurquoiseAlpha.png

86.6 KB
Loading

images/WebClientAlpha.png

-54.7 KB
Loading

mchess/async_uci_agent.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,11 @@ def send_agent_state(self, state, msg=""):
180180

181181
async def uci_open_engine(self):
182182
try:
183-
transport, engine = await chess.engine.popen_uci(
184-
self.engine_json['path'])
183+
if 'engine_params' in self.engine_json:
184+
engine_path = [self.engine_json['path']] + self.engine_json['engine_params']
185+
else:
186+
engine_path = self.engine_json['path']
187+
transport, engine = await chess.engine.popen_uci(engine_path)
185188
self.engine = engine
186189
self.transport = transport
187190
self.log.info(f"Engine {self.name} opened.")
@@ -344,8 +347,11 @@ async def async_go(self, board, mtime, ponder=False, analysis=False):
344347
# sc = str(info['score'])
345348
# else:
346349
# cp = float(str(info['score']))/100.0
347-
# sc = '{:.2f}'.format(cp)
348-
sc = info['score'].relative.score(mate_score=10000) / 100.0
350+
# sc = '{:.2f}'.format(cp)
351+
if info['score'].is_mate():
352+
sc = f"#{info['score'].relative.mate()}"
353+
else:
354+
sc = info['score'].relative.score(mate_score=10000) / 100.0
349355
except Exception as e:
350356
self.log.error(
351357
f"Score transform failed {info['score']}: {e}")

0 commit comments

Comments
 (0)