I have written my own GUI for playing and teaching chess. The GUI was written using HTML for the appearance, and JavaScript for the behavior of the pieces. Currently the program does not follow any of the rules of chess. It is up to the user to follow the rules of chess correctly. This allows the freedom to set up illegal positions or move the same side multiple times. This is very useful when trying to teach chess to beginners.
I am now looking at the idea that I would like to hook my program up to a chess engine. I haven't a clue on how to go about this. Most chess engines like StockFish or Rybka use a UCI for communicating with the GUI. I don't know how to make my program UCI compatible. I am not interested in writing my own chess engine, I would simply like to download an engine and have it interact with the GUI that I have written.
My board is made up of div tags, the pieces are just PNGs that can be dragged and dropped around on the board with complete freedom independent of chess rules. Ideally, I'd like to be able to set up any random position on my GUI, and have that position sent to the engine for analysis, with the best move recommendations returned. I don't even really need the program to move the pieces on the board for me as I can do that myself.
Does anyone have an idea of how I might get started on this project?
The UCI protocol spec is found here:
http://wbec-ridderkerk.nl/html/UCIProtocol.html
As a high level it defines a set of commands to be sent from the GUI to the engine and vice versa.
You can see that you can use the protocol to set up any position with the
position
command followed by a FEN string (other variants are available).As an example the command:
Would give the engine the position after 1 e4 c6
You can then use the
go
command (with various options for time restrictions, etc.) to have the engine calculate a move.You could run the risk of confusing the engine by attempting to send illegal moves and/or multiple successive moves by the same colour (whilst we are on this theme also avoid trying to send an illegal position e.g. black in check with white to play).
As long as your code handled these illegal oddities at the gui end (or in some intermediate layer) by stopping any ongoing game whilst illegal manoeuvrings take place before sending the resulting position to start a new game, then any UCI engine should cope just fine.
There are thousands of UCI chess engines out there for almost any conceivable platform - many of them free and/or open source. This list should give you a decent start:
http://computer-chess.org/doku.php?id=computer_chess:wiki:lists:chess_engine_list
I'd guess that your choice would depend, to some extent, on the Operating System you intend to deploy this on (if your gui is html/js then I'd guess on some webserver somewhere but is that LAMP, WAMP, ASP.Net, or any other variety I've probably never heard of! :-) )
So long as you can get AN engine executable loaded and pass in commands & read responses through the standard I/O you're away!
Good Luck - do let me know if you get it deployed somewhere. Would be nice to be able to cheat the machines! :-)