UCI parser and encoder library in python
Project description
ucilark - UCI parser and encoder library in python
The Universal Chess Interface (UCI) is an open communication protocol that enables chess engines to communicate with user interfaces.
ucilark parses from a UCI line string to a UCI_msg object containing dicts, and can encode the other way around.
Parsing is based on python lark toolkit.
Overview
- usage examples bellow
- the Lark-flavoured EBNF grammar definition of supported messages : uci.lark
- (only a subset of the UCI specification is supported)
- the code at ucilark.py
- some tests at test_ucilark.py.
Installation
pip install ucilark
Usage examples
UCI message: position
from ucilark import UCI_msg
line = "position fen 1r1n1rk1/ppq2p2/2b2bp1/2pB3p/2P4P/4P3/PBQ2PP1/1R3RK1 w - - 0 1"
m = UCI_msg.parse(line)
print(m.cmd)
# "position"
print(m.args)
# {'fen': {'movefen': '1r1n1rk1/ppq2p2/2b2bp1/2pB3p/2P4P/4P3/PBQ2PP1/1R3RK1', 'active': 'w', 'castling': '-', 'enpassant': '-', 'halfmove_clock': 0, 'fullmove_clock': 1}}
assert m.encode() == line
UCI message: info
from ucilark import UCI_msg
line = "info depth 23 seldepth 33 multipv 2 score cp 0 nodes 3358561 nps 7547328 hashfull 13 tbhits 0 time 445 pv d7d5 e4e3 d5f3 e3f3 e7e6 f3e4 f7g6 e4d4 e6f5 f4h6 g6e8 d4d5 e8b5 h6e3 f5g4 d5c5 b5a6 e3d2 a6b7 d2h6 g4f3"
m = UCI_msg.parse(line)
print(m.cmd)
# "info"
print(m.args)
# {'depth': 23, 'seldepth': 33, 'multipv': 2, 'score': {'cp': '0'}, 'nodes': 3358561, 'nps': 7547328, 'hashfull': 13, 'tbhits': 0, 'time': 445, 'pv': ['d7d5', 'e4e3', 'd5f3', 'e3f3', 'e7e6', 'f3e4', 'f7g6', 'e4d4', 'e6f5', 'f4h6', 'g6e8', 'd4d5', 'e8b5', 'h6e3', 'f5g4', 'd5c5', 'b5a6', 'e3d2', 'a6b7', 'd2h6', 'g4f3']}
assert m.encode() == line
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ucilark-0.2.tar.gz.
File metadata
- Download URL: ucilark-0.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ba9f17bc2e03b45b49d4cc7721cfdb7127edb98e07ba767eac7733f088f3caa
|
|
| MD5 |
014631fb7dc2d93dbeb2035a9065e71f
|
|
| BLAKE2b-256 |
4b7a8540892580fffaa71b69b4613b7fe3c9bceda1ac03efce6eaf096c033b4e
|
File details
Details for the file ucilark-0.2-py3-none-any.whl.
File metadata
- Download URL: ucilark-0.2-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09708de31535f1edf174bc0f12362e31d8b24ccce3223907a9df57f8869d22ae
|
|
| MD5 |
1a02a78f87290e07b3179585ee930f86
|
|
| BLAKE2b-256 |
602c6b7fba92762163e2d62ef3d0cd3a7b3f0bef86b61c723bcba04b808826e6
|