UCI: checking for legality after getting "position..?

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

UCI: checking for legality after getting "position..?

Postby Volker Pittlik » 29 Aug 2005, 13:19

Maybe thoose who have UCI implemented in their engine can give me an advice. I can't find anything in the descpription of UCI if the moves received from the GUI after "position startpos moves <move1> .... <movei>" are necessarily legal or if the engine should check the legality by itself.

I tend to send an info string in case I detect an illegal move, but this takes time the more moves has been played and I don't know if there is something like a common practise. The undefined situation may lead to strange program behaviour. The following test illustrates that. Engine: Fruit_2.1 (playing black), GUI; Arena_1.1.

Open the debug window and start a new game. After getting "readyok" from the engine send "position startpos moves e2e5" and "go wtime 132000 btime 132000 winc 12000 binc 12000" (of course other times will work too) to it.

The engine accepted the illegal move, starts calculating and after a while replied with "d6". In this situation Arena adjudicated the game as won for White due to an illegal move.

I neither want to critizise the GUI or the engine. I think it is just an open question.

Volker
User avatar
Volker Pittlik
 
Posts: 1031
Joined: 24 Sep 2004, 10:14
Location: Murten / Morat, Switzerland

Re: UCI: checking for legality after getting "position.

Postby Roman Hartmann » 29 Aug 2005, 13:47

Hi Volker,
I guess most engine programmers probably just assume that the GUI will send only valid moves. Doesn't also make too much sense to check for legalitiy of moves in the GUI and in the engine as well. My own engine will (or at least it should) reject illegal moves and send an error message though. That's because the move generator is called before each move is done and is checked for legality.

Roman
User avatar
Roman Hartmann
 
Posts: 155
Joined: 11 Oct 2004, 14:21

Re: UCI: checking for legality after getting "position.

Postby Pradu » 29 Aug 2005, 13:49

Both engine and GUI should check for legality. Winboard, for example, dosen't keep track of castling privilages well, so you HAVE to check for legality when using Winboard. It is safer doing this even though it may seem redundant.
User avatar
Pradu
 
Posts: 343
Joined: 12 Jan 2005, 19:17
Location: Chandler, Arizona, USA

Re: UCI: checking for legality after getting "position.

Postby Daniel Mehrmann » 29 Aug 2005, 15:24

Volker Pittlik wrote:Maybe thoose who have UCI implemented in their engine can give me an advice. I can't find anything in the descpription of UCI if the moves received from the GUI after "position startpos moves <move1> .... <movei>" are necessarily legal or if the engine should check the legality by itself.

I tend to send an info string in case I detect an illegal move, but this takes time the more moves has been played and I don't know if there is something like a common practise. The undefined situation may lead to strange program behaviour. The following test illustrates that. Engine: Fruit_2.1 (playing black), GUI; Arena_1.1.

Open the debug window and start a new game. After getting "readyok" from the engine send "position startpos moves e2e5" and "go wtime 132000 btime 132000 winc 12000 binc 12000" (of course other times will work too) to it.

The engine accepted the illegal move, starts calculating and after a while replied with "d6". In this situation Arena adjudicated the game as won for White due to an illegal move.

I neither want to critizise the GUI or the engine. I think it is just an open question.

Volker


Hi Volker !

The GUI are the "boss" in the UCI protocol. So, the GUI should only send legal moves and the engines don't need to check it.

Best,
Daniel
User avatar
Daniel Mehrmann
 
Posts: 127
Joined: 02 Oct 2004, 06:10
Location: Germany

Re: UCI: checking for legality after getting "position.

Postby Volker Annuss » 29 Aug 2005, 15:52

Hello Volker,

I agree with Daniel, that the GUI should only send legal moves. And when an engine gets an illegal move from the GUI, something bad has happened and you will get unexpected behaviour, whatever the engine does.

The UCI protocol specification does not help much:
* if the engine or the GUI receives an unknown command or token it should just ignore it and try to parse the rest of the string in this line.
Examples: "joho debug on\n" should switch the debug mode on given that joho is not defined, "debug joho on\n" will be undefined however.


Is an illegal move an illegal token? I think it is, so the next question is what to do with it. Parse the rest of the string, would mean look for legal moves after the illegal one, but the second example "debug joho on" suggests, the opposite.

Hermann detects illegal moves and uses the position just before the illegal move. An info string is sent only if debug is on.

Greetings,
Volker
Volker Annuss
 
Posts: 49
Joined: 25 Jan 2005, 11:14

Re: UCI: checking for legality after getting "position.

Postby Volker Pittlik » 29 Aug 2005, 21:39

Thanks for all replies.
Meanwhile I asked Stefan Meyer-Kahlen about this and related problems and he wrote me the following (quoted with his permission):

- The GUI is expected to send only legal moves.
- Shredder Classic should only send legal moves.

Although the GUI should send only legal moves I still tend to check legality. In case the move is illegal I notice that in the log file and send a message if debug is on under an UCI enabled GUI. If there is an illegal move my engine stops searching.

A sidenote: SMK also confirmed that Shredder Classic omits the "Halfmove clock" and "Fullmove number" field in the FEN string after "position..." at the moment when starting a FRC game. For example:

only

rqbkrbnn/pppppppp/8/8/8/8/PPPPPPPP/RQBKRBNN w EAea -

is send to the engine instead of

rqbkrbnn/pppppppp/8/8/8/8/PPPPPPPP/RQBKRBNN w EAea - 0 1

if a FRC game is started. The engine has to deal with the two missing fields.

Regards

Volker
User avatar
Volker Pittlik
 
Posts: 1031
Joined: 24 Sep 2004, 10:14
Location: Murten / Morat, Switzerland


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 26 guests