How to build a computer analysis, using either a CECP or a UCI engine

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
Roland Chastain
Posts: 686
Joined: Sat Jun 08, 2013 10:07 am
Location: France
Full name: Roland Chastain

How to build a computer analysis, using either a CECP or a UCI engine

Post by Roland Chastain »

Hello everybody.

I would like to create a GUI displaying a computer analysis for a game, like the one provided by lichess (for example).

Image

Which commands could I send to an engine, in order to get informations like relative advantage of each player?

Would be interested both by CECP and UCI solutions.

Regards.

Roland
Qui trop embrasse mal étreint.

Author of Eschecs, a simple UCI chess GUI written in Pascal.
User avatar
hgm
Posts: 28398
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: How to build a computer analysis, using either a CECP or a UCI engine

Post by hgm »

In UCI you would send a comment 'go infinite' after setting up the position to analyse with the usual 'position ... moves ...' command. Terminate with 'stop' before sending any other commands.

In CECP the command is 'analyze', and you terminate that with 'exit' (which brings you back into force mode). In CECP it is allowed to send 'setup' commands, moves and 'undo' during the analysis, after which the engine starts searching the new position.

In both cases the 'thinking output' is as usual. Meaning that in CECP you might need to send a 'post' command to make sure it will be given.
User avatar
Roland Chastain
Posts: 686
Joined: Sat Jun 08, 2013 10:07 am
Location: France
Full name: Roland Chastain

Re: How to build a computer analysis, using either a CECP or a UCI engine

Post by Roland Chastain »

@hgm

Thank you.

As a first step, I made the following Tcl script (using CECP):

Code: Select all

#!/usr/bin/expect

set ENGINE /home/roland/Documents/echecs/sources/moteurs/olithink/5_11_7/olithink

spawn $ENGINE

send "xboard\n"
send "protover 2\n"
expect "done=1"

send "new\n"
send "hard\n"
send "post\n"
#send "e2e4\n"
send "setboard rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1\n"
send "analyze\n"
after 1000

send "exit\n"
send "quit\n"

#interact
expect eof
Does it look correct?

I get the following output:

Code: Select all

 1   -31      0         5  a7a6 
 2   -42      0        24  a7a6 b2b3 
 3    31      0        78  d7d5 e4d5 d8d5 
 4   -24      0       612  e7e6 d2d4 d7d5 f2f3 
 5    41      0      1570  g8f6 d2d3 d7d5 e4d5 
 6   -12      0      4321  d7d5 e4e5 d8d7 h2h3 d5d4 d2d3 
 7   -25      1      8136  d7d5 e4e5 b8a6 d2d4 c8f5 g1f3 c7c6 
 8   -20      1     12050  d7d5 e4e5 g8h6 g1f3 c8f5 d2d3 d5d4 
 1    -3      0         6  d7d5 
 2    -8      0        18  d7d5 e4e5 
 3    12      0        37  d7d5 e4e5 g8h6 
 4   -24      0       132  d7d5 e4e5 g8h6 g1f3 
 5   -23      0       424  d7d5 d2d3 d5e4 d3e4 d8d6 
 6   -20      0       827  d7d5 d2d3 d5e4 b1c3 e4d3 f1d3 
 7     1      0      2611  d7d5 d2d3 b8c6 e4d5 d8d5 b1c3 d5d4 
 8   -23      1     10252  d7d5 e4e5 d5d4 f1c4 b8c6 g1f3 c8e6 d2d3 
 9   -19      1     18300  d7d5 e4e5 d5d4 f1c4 b8c6 g1f3 g7g6 d2d3 f8h6 
10   -19      4     47045  e7e5 g1f3 b8c6 f1c4 d7d6 d2d3 f8e7 b1c3 c8e6 e1g1 
11   -17      8     86619  e7e5 g1f3 g8f6 b1c3 d7d6 h2h3 c8e6 d2d3 b8c6 c1e3 
12   -18     16    174360  d7d5 e4d5 d8d5 b1c3 d5e6 d1e2 g8f6 d2d3 b8c6 c1e3 f6g4 e3f4 g4e5 e1c1 
13   -16     23    261553  d7d5 e4d5 d8d5 d2d3 g8f6 b1c3 d5d6 g1f3 b8c6 c1e3 d6b4 d1b1 e7e6 
14   -24     41    466464  e7e5 b1c3 b8c6 g1f3 g8f6 f1b5 f8b4 b5c6 b7c6 f3e5 b4c3 d2c3 f6e4 
15   -24     75    856621  e7e5 b1c3 f8c5 g1f3 d7d6 c3a4 c5b6 a4b6 a7b6 d2d4 g8f6 c1g5 b8c6 c2c3 
Qui trop embrasse mal étreint.

Author of Eschecs, a simple UCI chess GUI written in Pascal.
User avatar
hgm
Posts: 28398
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: How to build a computer analysis, using either a CECP or a UCI engine

Post by hgm »

Looks OK. But it would probably be better to send the move(s) ("usermove e2e4" after "force") rather than the position (through 'setboard'), so that the engine has the complete game hsitory in addition to the current position. This could make a difference for repetition draws, which it otherwise would not recognize.

Also notice that you just assume here that the engine will understand 'setboard' (and I assumed that the plain move needs to be prefixed with 'usermove'). This might not be the case for all engines, and it should formally be deduced from the 'feature' replies to 'protover 2' whether you have to send positions with 'setboard' or 'edit', and whether the 'usermove' prefix is necessary for relaying moves.