Chess Asked by Salvador Dali on December 3, 2020
I am looking for a chess engine which provides a normal API which I can use with some high level programming language like C# or python. I went through the list of leaders (Houdini, Komodo, Stockfish and Rybka) and was not able to find any signs that these engines provides API (which surprised me and suggested that I am missing something).
To be less vague, here is what I need from this API:
So, does anyone knows an engine which provides a clear API to it’s functions?
I was looking around for something similar and came across Joe's Chess API:
Answered by iCodeAndMakeVideos on December 3, 2020
Batch First is a JIT compiled chess engine written in Python, compiled using Numba, which would allow easy C++ interfacing and even easier Python interfacing.
While Batch First itself is an engine not API, it heavily uses and relies upon the Python-Chess package, which is an awesome API.
The JIT compilation of Batch First, and use of NumPy arrays for representing boards, allows a more practical Python interface (at least an order of magnitude faster) for actual use in a chess engine.
The core of the engine is a zero-window k-best-first search algorithm used to evaluate ANNs in batches.
Full disclosure, I am the author of the Batch First engine.
Answered by Sam Ragusa on December 3, 2020
python-chess provides a useful API and supports UCI, apparently:
http://python-chess.readthedocs.io/en/v0.15.3/uci.html?highlight=engine
The above link gives a 'stockfish' example.
Answered by Richard Prosser on December 3, 2020
As others have said, UCI is the API you want. The full specifications of the protocol is here (the zip file extracts to a text file): http://download.shredderchess.com/div/uci.zip
It's actually very straight forward and simple, a UCI engine must respond to and reply in plain text through stdin, stdout and stderr. In fact, you should be able to launch the executable binary of any UCI engine on your platform and issue the UCI commands manually.
UCI facilitates instructions from a GUI or other engine to tell the specific engine to do whatever it is that you want it to do, including analyse a specific PGN file (the loading of it is through the GUI or similar front-end, the raw moves are then fed to the engine in extended algebraic form, such as e4 becoming e2e4). The second and third points of your requirements are standard with UCI, but it is up to each engine developer to support them (given how lean those requirements are, that should be most of them).
Here's an example of UCI in action on the command line:
bash-3.2$ ./stockfish-5-64
Stockfish 5 64 by Tord Romstad, Marco Costalba and Joona Kiiski
uci
id name Stockfish 5 64
id author Tord Romstad, Marco Costalba and Joona Kiiski
option name Write Debug Log type check default false
option name Write Search Log type check default false
option name Search Log Filename type string default SearchLog.txt
option name Book File type string default book.bin
option name Best Book Move type check default false
option name Contempt Factor type spin default 0 min -50 max 50
option name Mobility (Midgame) type spin default 100 min 0 max 200
option name Mobility (Endgame) type spin default 100 min 0 max 200
option name Pawn Structure (Midgame) type spin default 100 min 0 max 200
option name Pawn Structure (Endgame) type spin default 100 min 0 max 200
option name Passed Pawns (Midgame) type spin default 100 min 0 max 200
option name Passed Pawns (Endgame) type spin default 100 min 0 max 200
option name Space type spin default 100 min 0 max 200
option name Aggressiveness type spin default 100 min 0 max 200
option name Cowardice type spin default 100 min 0 max 200
option name Min Split Depth type spin default 0 min 0 max 12
option name Threads type spin default 1 min 1 max 128
option name Hash type spin default 32 min 1 max 16384
option name Clear Hash type button
option name Ponder type check default true
option name OwnBook type check default false
option name MultiPV type spin default 1 min 1 max 500
option name Skill Level type spin default 20 min 0 max 20
option name Emergency Move Horizon type spin default 40 min 0 max 50
option name Emergency Base Time type spin default 60 min 0 max 30000
option name Emergency Move Time type spin default 30 min 0 max 5000
option name Minimum Thinking Time type spin default 20 min 0 max 5000
option name Slow Mover type spin default 80 min 10 max 1000
option name UCI_Chess960 type check default false
uciok
isready
readyok
quit
bash-3.2$
The commands I issued were uci, isready and quit.
To utilise the UCI commands you essentially have two main choices; you can use an existing interface (e.g. ChessX, Arena and a host of others) or you can write your own code to issue instructions to an engine or group of engines. I believe there may already be Python wrappers for accessing UCI engines, but I'd need to double-check. There's definitely python-chess (import chess) and pychess (import pychess), I just can't recall the extent of their functions. I can't recall where pychess is lurking (probably github or google code), but python-chess can be installed with pip.
Answered by Ben on December 3, 2020
Here there's a port version of Stockfish in .Net: https://github.com/bpfliegel/Portfish
To use this engine (once it's compiled), you'll nedd a GUI like Arena http://wwww.playwitharena.com or ScidVSPC http://scidvspc.sourceforge.net. These applications are used to provide a nice interface and allow you to load games/positions, analyze them (I'm pretty sure you can load a game on pgn and analyze it by an engine with criteria like "n seconds per move" or "n plies per move"), run matches between engines, etc
In (almost) every chess engine you should find something like a uci.cs or an xboard.cs file which is commited to this communication task.
(A "chess engine" is a program that is capable of playing chess but has no graphical interface. The way it communicates to applications like Arena or ScidVSPC is by the UCI or xboard protocols. Most of the chess programs are written this way, so the developer can forget about the GUI stuff and focus on the "brain").
Answered by Emilio Díaz on December 3, 2020
I've googled on "chess engine api" but have not seen any real API's. As suggested in the comments of your question I would go with UCI. This is also the way GUI's communicate with chess engines.
If you're really a hardcore programmer you could always check out the open source engine Stockfish. It could very well be that there is some sort of API built in it, or you could make a clone and build your own API for it.
Answered by Rafiek on December 3, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP