Safe I/O (repeated)

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

Moderator: Andres Valverde

Safe I/O (repeated)

Postby Fabien Letouzey » 11 Feb 2005, 10:03

Hi all,

This is a request to engine authors that I already made a few months ago.

---

When reading input please test for end-of-file, and let the engine quit if encountered. In other words, interpret EOF as "quit" (input has ended so no more commands will ever be received).

I know this is not supposed to happen since the interface should send "quit" first, but the interface (e.g. PolyGlot) can be killed by third-party software before doing so. Be assured that this does happen.

The most popular function for reading input is probably fgets(). Just test the return value for equality with NULL. If you want to go further you can use feof() or ferror() when receiving NULL. In any case it is safe to quit when receiving NULL.

---

Here's how you can test whether an engine is safe or not,
no need to be a programmer:

On Windows:

1) launch the engine in a console
2) press ^Z (control-Z)
3) validate with Return

On Unix (e.g. Linux, Mac OS X, etc ...):

1) launch the engine in a shell
2) press ^D

Engines should quit at this point. Error messages are fine.
Check with Crafty.

Buggy engines will display a new prompt, start using CPU time, or fill
the console (and log files) with output. Sadly many engines do this,
including commercial ones.

---

Thanks for listening,

Fabien.
Fabien Letouzey
 
Posts: 110
Joined: 03 Dec 2004, 10:17
Location: France

Re: Safe I/O (repeated)

Postby Alessandro Scotti » 13 Feb 2005, 01:02

Hi Fabien,
thanks for reminding this, I did make a mental note when I saw your first post and, obviously, forgot about it five minutes later. I've now added end of input detection to Kiwi, and posted a "beta" of version 0.5a on my site just in case you need to perform some tests.
User avatar
Alessandro Scotti
 
Posts: 306
Joined: 20 Nov 2004, 00:10
Location: Rome, Italy


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 6 guests