Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/numberoverzero/buscemi
python library for interacting with uci https://en.wikipedia.org/wiki/Universal_Chess_Interface
https://github.com/numberoverzero/buscemi
Last synced: 17 days ago
JSON representation
python library for interacting with uci https://en.wikipedia.org/wiki/Universal_Chess_Interface
- Host: GitHub
- URL: https://github.com/numberoverzero/buscemi
- Owner: numberoverzero
- Created: 2019-02-11T13:30:17.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-21T15:53:31.000Z (5 months ago)
- Last Synced: 2024-10-07T09:06:40.874Z (about 1 month ago)
- Language: Python
- Size: 21.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# buscemi
provides asyncio interfaces to UCI.
# High-level API
```python3
import asyncio
from buscemi import open_connection, SearchConfig, Positionasync def main():
# https://chess.stackexchange.com/a/12581
fen = "N7/P3pk1p/3p2p1/r4p2/8/4b2B/4P1KP/1R6 w - - 0 34"conn = await open_connection("stockfish")
await conn.set_options(MultiPV=3)
search = await conn.search(
position=Position(fen=fen),
config=SearchConfig(movetime=30000))seen = 0
while not search.is_done:
await search.wait_progress()
for line in search.info[seen:]:
print(line, flush=True)
seen = len(search.info)
print(search.bestmove, flush=True)await conn.close()
asyncio.run(main())
```## Definitions
```
async def open_connection(executable: str) -> Connection
``````
Connection:
@classmethod
async def from_executable(executable: str) -> Connectionasync def initialize()
async def set_options(**options)
async def search(
position: Position=None,
config: SearchConfig=None) -> Search
async def close()
``````
Search:
position: Position
config: SearchConfig
engine_options: Dict[str, Any]info: List[str]
bestmove: stris_done: bool
was_stopped: boolasync def wait_progress()
async def wait_done()
async def stop()
``````
Position:
fen: Optional[str]
moves: Tuple[str, ...]
``````
SearchConfig:
searchmoves: Tuple[str, ...] = field(default_factory=tuple)wtime: int = None
btime: int = None
winc: int = None
binc: int = None
movestogo: int = Nonedepth: int = None
nodes: int = None
mate: int = Nonemovetime: int = None
```# Low-level API
```python
import asyncio
from buscemi.connection import UciConnection, readasync def main():
# https://chess.stackexchange.com/a/12581
fen = "N7/P3pk1p/3p2p1/r4p2/8/4b2B/4P1KP/1R6 w - - 0 34"conn = await UciConnection.from_executable("stockfish")
await conn.uci()
await conn.setoption("MultiPV", "3")
await conn.ucinewgame()
await conn.position(fen=fen)
await conn.isready()
await conn.go(["movetime", "30000"])async for line in read(conn):
print(line, flush=True)
if line.startswith("bestmove"):
breakawait conn.quit()
asyncio.run(main())
```## Definitions
```
UciConnection:
@classmethod
async def from_executable(executable: str) -> UciConnectionasync def uci() -> List[str]
async def debug(enable = True)
async def isready() -> List[str]
async def setoption(name: str, value: str = None)
async def ucinewgame()
async def position(fen: str = None, moves: Iterable[str] = None)
async def go(args: List[str])
async def stop()
async def ponderhit()
async def quit()
``````
async def read(conn: UciConnection) -> AsyncIterator[str]
async def read_until(
conn: UciConnection,
pattern: Union[str, Pattern]) -> AsyncIterator[str]:
async def write(conn: UciConnection, data: str, wait = True)
```