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: 1289
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.
benvining
Posts: 36
Joined: Fri May 30, 2025 10:18 pm
Full name: Ben Vining

Re: uci protocol

Post by benvining »

For repetition detection you only need to store the 9 most recent Zobrist hash values, you don't need to store 50 moves
User avatar
Steve Maughan
Posts: 1289
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: uci protocol

Post by Steve Maughan »

benvining wrote: Fri Aug 29, 2025 7:32 pm For repetition detection you only need to store the 9 most recent Zobrist hash values, you don't need to store 50 moves
I don't believe that's correct. The repetition could occur any time is the last 50 non-capturing, non-promoting moves, and non-pawn moves. The repeated moves do not need to sequential.

— Steve
http://www.chessprogramming.net - Juggernaut & Maverick Chess Engine
Uri Blass
Posts: 10846
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: uci protocol

Post by Uri Blass »

Steve Maughan wrote: Fri Aug 29, 2025 8:20 pm
benvining wrote: Fri Aug 29, 2025 7:32 pm For repetition detection you only need to store the 9 most recent Zobrist hash values, you don't need to store 50 moves
I don't believe that's correct. The repetition could occur any time is the last 50 non-capturing, non-promoting moves, and non-pawn moves. The repeated moves do not need to sequential.

— Steve
You do not need to repeat moves for repetition but only to repeat the position and of course the last 50 moves of both sides can be relevant assuming no capture and no pawn move in them.

1.Nf3 Nf6 2.Ng1 Ng8 3.Nc3 Nc6 4.Nb1 Nb8 is a draw by repetition when all the moves are different(Nf3 did not repeat more than once and the same for other moves)