uci protocol

Discussion of chess software programming and technical issues.

Moderator: Ras

abulmo2
Posts: 470
Joined: Fri Dec 16, 2016 11:04 am
Location: France
Full name: Richard Delorme

Re: uci protocol

Post by abulmo2 »

Steve Maughan wrote: Tue Aug 05, 2025 9:41 pm With respect, you're trying to solve a problem that doesn't really exist. From a human perspective, sending the start position (or FEN) and all moves seems wasteful. But UCI is a stateless protocol, where the engine is not expected to remember anything (although it can choose to retain history tables etc). In practice the verbose communication has zero impact on playing strength. A decent engine can play a whole game with 1 second + 0.05 second increments without the verbose communication playing a significant role.

— Steve
I concur with you. I tried to measure the time spent to decipher the position command using gprof or perf (under Linux) with the same ultrabullet time control you mention (1 + 0.05 sec), I got less than 0.1% of the time spent to interpret the position command. So pretty much negligible.
The command is also very simple to implement. Less than 10 lines of code in C for example:

Code: Select all

void uci_position(Uci *uci, const char *line) {
	char *fen, *moves;
	Move move;

	if (parse_find(line, "startpos")) board_init(&uci->board);
	else if ((fen = parse_find(line, "fen")) != NULL) board_set(&uci->board, fen);
	if ((moves = parse_find(line, "moves")) != NULL) {
		while ((moves = parse_move(moves, &uci->board, &move)) != NULL) board_update(&uci->board, move);
	}
}
Richard Delorme
ericlangedijk
Posts: 27
Joined: Thu Aug 08, 2013 5:13 pm

Re: uci protocol

Post by ericlangedijk »

Ok. Convinced.
One more thing: I noticed (testing with Stockfish) If you enter somewhere an illegal move in the command, it just stops there.
Does that mean we parse each move and check if it is actually inside our movelist? Thus meaning with every position+fen+moves command we need to generate the moves foreach move?
op12no2
Posts: 550
Joined: Tue Feb 04, 2014 12:25 pm
Location: Gower, Wales
Full name: Colin Jenkins

Re: uci protocol

Post by op12no2 »

That's the easiest way to do it yes and same argument - drop in ocean... :)
ericlangedijk
Posts: 27
Joined: Thu Aug 08, 2013 5:13 pm

Re: uci protocol

Post by ericlangedijk »

Yes I think you are right.
Parsing the fen is fast. Making the moves (and checking them) is more expensive.
I did some measurements with 15 moves. Bigger ones I still need to make.
It took around 12 microseconds.

Speaking of that: is there some online tool which makes a fen-string with moves from a PGN-game?
ericlangedijk
Posts: 27
Joined: Thu Aug 08, 2013 5:13 pm

Re: uci protocol

Post by ericlangedijk »

Now for repetition detection...
For that I believe it is needed, when a game is going on, the complete movelist is sent each and every move isn't it?
User avatar
Steve Maughan
Posts: 1288
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: uci protocol

Post by Steve Maughan »

ericlangedijk wrote: Thu Aug 28, 2025 11:43 am Now for repetition detection...
For that I believe it is needed, when a game is going on, the complete movelist is sent each and every move isn't it?
Yes!

— Steve
http://www.chessprogramming.net - Juggernaut & Maverick Chess Engine
User avatar
RubiChess
Posts: 643
Joined: Fri Mar 30, 2018 7:20 am
Full name: Andreas Matthies

Re: uci protocol

Post by RubiChess »

ericlangedijk wrote: Thu Aug 28, 2025 11:43 am Now for repetition detection...
For that I believe it is needed, when a game is going on, the complete movelist is sent each and every move isn't it?
The complete list is sent but for repetition detection your engine only needs to store the moves beginning after the last irreversible move which keeps this list inside a 50-moves buffer.