jwiegley / emacs-chess

A complete chess client written in Emacs Lisp.
http://www.newartisans.com/2008/05/emacs-chess-now-hosted-at-github/
GNU General Public License v3.0
122 stars 19 forks source link

Engine Analysis? #16

Open epeld opened 7 years ago

epeld commented 7 years ago

Hi! I just discovered that I can read pgn games with emacs-chess, which is very nice.

Is there a way to have an engine analyze the game while I am viewing it?

mlang commented 7 years ago

That was always planned, but is not implemented yet as far as I remember.

jwiegley commented 7 years ago

Indeed. I always used ChessDB for this myself.

epeld commented 7 years ago

OK I would like to try to make it work for me. It doesn't have to be pretty, just a command I could bind to a key to analyze a position for, say 1 second, would be enough.

I've seen there are already functions for sending a position to a running UCI engine. So I figure if I can just find a command to get the FEN for the current position I would be halfway there.

The other half of the problem would be to enumerate all available running engine processes so I can send a command to one of them. The chess-engine module seems promising, but I can't figure out what the 'engine' parameter should be that most functions expect as an argument. Is it the buffer, the process or something else?

Greatful for any help!

epeld commented 7 years ago

Progress! (chess-pos-to-fen (chess-game-pos chess-module-game)) gives me a FEN-string (although I didn't know that the move numbers could be omitted, as in: 4r/p4pk//2p4p/P1P/1p/q4PP/6K w - - .)

Now all I need to do is to launch a stockfish process, send it "uci\n" followed by "position fen" followed by "go infinite" and put its process-buffer in a split frame next to the chessboard.

epeld commented 7 years ago

Hi again! I made it work :) Not sure if it is of any use to anyone else but it works quite well for quick analyses.

I used this script: https://github.com/epeld/chess-engine.lisp/blob/master/analysis.el

Then I ran e.g (local-set-key (kbd "C-c C-e") 'chess-analysis-analyse) (local-set-key (kbd "C-c C-g") 'uci-stop) from inside the chessboard-buffer and now I get a 'bestmove' suggestion everytime I press C-c C-e :)