switch to new tbhits protocol
[xboard.git] / engine-intf.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\r
2           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">\r
4 <head>\r
5 <title>Chess Engine Communication Protocol</title>\r
6 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\r
7 <style type="text/css">\r
8   .header { \r
9   border-top:2px solid black;\r
10   border-bottom:2px solid black;\r
11   }\r
12   .version1 { color: red;}\r
13   .version43 { color: green;}\r
14   .version44 { color: blue; }\r
15   .version47 { color: purple; }\r
16 \r
17   table tr { text-align: left}\r
18   tr > td:first-child { font-weight:bold;}\r
19   dt { font-weight:bold;}\r
20 \r
21   </style>\r
22 \r
23 </head>\r
24 \r
25 <body>\r
26 <div class="header">\r
27 <h1>Chess Engine Communication Protocol</h1>\r
28 <h2><a href="http://www.tim-mann.org/">Tim Mann</a> &amp; <a href="http://home.hccnet.nl/h.g.muller/winboardF.html">H.G.Muller</a></h2>\r
29 <p>\r
30 Version 2; implemented in xboard/WinBoard 4.2.1 and later. (Sept 3, 2009)<br />\r
31 Changes since version 1 are indicated in <span class="version1">red</span>.<br />\r
32 Changes for WinBoard 4.3.xx are indicated in <span class="version43">green</span>.<br />\r
33 Changes for WinBoard 4.4.xx are indicated in <span class="version44">blue</span>.\r
34 </p>\r
35 </div>\r
36 \r
37 <ul>\r
38 <li><a href="#1">1. Introduction</a></li>\r
39 <li><a href="#2">2. Connection</a></li>\r
40 <li><a href="#3">3. Debugging</a></li>\r
41 <li><a href="#4">4. How it got this way</a></li>\r
42 <li><a href="#5">5. WinBoard requires Win32 engines</a></li>\r
43 <li><a href="#6">6. Hints on input/output</a></li>\r
44 <li><a href="#7">7. Signals</a></li>\r
45 <li><a href="#8">8. Commands from xboard to the engine</a></li>\r
46 <li><a href="#9">9. Commands from the engine to xboard</a></li>\r
47 <li><a href="#10">10. Thinking Output</a></li>\r
48 <li><a href="#11">11. Time control</a></li>\r
49 <li><a href="#12">12. Analyze Mode</a></li>\r
50 <li><a href="#13">13. Idioms and backward compatibility features</a></li>\r
51 </ul>\r
52 \r
53 <hr />\r
54 \r
55 <h2><a name="1">1. Introduction</a></h2>\r
56 \r
57 <p>\r
58 This document is a set of rough notes on the protocol that xboard and\r
59 WinBoard use to communicate with gnuchessx and other chess engines.\r
60 These notes may be useful if you want to connect a different chess\r
61 engine to xboard.  Throughout the notes, "xboard" means both xboard\r
62 and WinBoard except where they are specifically contrasted.\r
63 </p>\r
64 \r
65 <p>\r
66 There are two reasons I can imagine someone wanting to do this: \r
67 </p>\r
68 \r
69 <ol>\r
70 <li>You have, or are developing, a chess engine but you don't want to\r
71 write your own graphical interface. </li>\r
72 <li>You have, or are developing,a chess engine, and you want to\r
73 interface it to the Internet Chess Server.</li>\r
74 </ol>\r
75 \r
76 <p>\r
77 In case (2), if you are using xboard, you will need to configure the\r
78 "Zippy" code into it, but WinBoard includes this code already.  See\r
79 the file <a\r
80 href="http://www.tim-mann.org/xboard/zippy.README">zippy.README</a>\r
81 in the xboard or WinBoard distribution for more information.\r
82 </p>\r
83 \r
84 <p>\r
85 These notes are unpolished, but I've attempted to make them complete\r
86 in this release.  If you notice any errors, omissions, or misleading\r
87 statements, let me know.\r
88 </p>\r
89 \r
90 <p>\r
91 I'd like to hear from everyone who is trying to interface their own\r
92 chess engine to xboard/WinBoard. Please join the mailing list for \r
93 authors of xboard/WinBoard compatible chess engines and post a message \r
94 about what you're doing. The list is now hosted by Yahoo Groups; you \r
95 can join at <a href="http://groups.yahoo.com/group/chess-engines" \r
96 >http://groups.yahoo.com/group/chess-engines</a>, or you can read the\r
97 list there without joining.  The list is filtered to prevent spam.\r
98 </p>\r
99 \r
100 <p class="version43">\r
101 Note that the WinBoard 4.3.xx line was developed independently of the\r
102 original GNU project, by H.G.Muller.\r
103 If you have questions about WinBoard 4.3.xx, or want to report bugs in it,\r
104 report them in the appropriate section of the \r
105 <a href="http://www.open-aurec.com/wbforum/">WinBoard forum</a>.\r
106 </p>\r
107 \r
108 <h2><a name="2">2. Connection</a></h2>\r
109 \r
110 <p>\r
111 An xboard chess engine runs as a separate process from xboard itself,\r
112 connected to xboard through a pair of anonymous pipes.  The engine\r
113 does not have to do anything special to set up these pipes.  xboard\r
114 sets up the pipes itself and starts the engine with one pipe as its\r
115 standard input and the other as its standard output.  The engine then\r
116 reads commands from its standard input and writes responses to its\r
117 standard output.  This is, unfortunately, a little more complicated to\r
118 do right than it sounds; see <a href="#6">section 6</a> below.\r
119 </p>\r
120 \r
121 <p>\r
122 And yes, contrary to some people's expectations, exactly the same\r
123 thing is true for WinBoard.  Pipes and standard input/output are\r
124 implemented in Win32 and work fine.  You don't have to use DDE, COM,\r
125 DLLs, BSOD, or any of the other infinite complexity that\r
126 Microsoft has created just to talk between two programs.  A WinBoard\r
127 chess engine is a Win32 console program that simply reads from its\r
128 standard input and writes to its standard output.  See sections \r
129 <a href="#5">5</a> and <a href="#6">6</a> below for additional details.\r
130 </p>\r
131 \r
132 <h2><a name="3">3. Debugging</a></h2>\r
133 \r
134 <p>\r
135 To diagnose problems in your engine's interaction with xboard, use the\r
136 -debug flag on xboard's command line to see the messages that are\r
137 being exchanged.  In WinBoard, these messages are written to the file\r
138 WinBoard.debug instead of going to the screen.\r
139 </p>\r
140 \r
141 <p>\r
142 You can turn debug mode on or off while WinBoard is running by\r
143 pressing Ctrl+Alt+F12.  You can turn debug mode on or off while xboard\r
144 is running by binding DebugProc to a shortcut key (and pressing the\r
145 key!); see the instructions on shortcut keys in the xboard man page.\r
146 </p>\r
147 \r
148 <p>\r
149 While your engine is running under xboard/WinBoard, you can send a\r
150 command directly to the engine by pressing Shift+1 (xboard) or Alt+1\r
151 (WinBoard 4.0.3 and later).  This brings up a dialog that you can type\r
152 your command into.  Press Shift+2 (Alt+2) instead to send to the\r
153 second chess engine in Two Machines mode.  On WinBoard 4.0.2 and earlier,\r
154 Ctrl+Alt is used in place of Alt; this had to be changed due to a conflict\r
155 with typing the @-sign on some European keyboards.\r
156 </p>\r
157 \r
158 <h2><a name="4">4. How it got this way</a></h2>\r
159 \r
160 <p>\r
161 Originally, xboard was just trying to talk to the existing\r
162 command-line interface of GNU Chess 3.1+ and 4, which was designed\r
163 for people to type commands to.  So the communication protocol is very\r
164 ad-hoc.  It might have been good to redesign it early on, but because\r
165 xboard and GNU Chess are separate programs, I didn't want to force\r
166 people to upgrade them together to versions that matched.  I\r
167 particularly wanted to keep new versions of xboard working with old\r
168 versions of GNU Chess, to make it easier to compare the play of old\r
169 and new gnuchess versions.  I didn't foresee the need for a clean\r
170 protocol to be used with other chess engines in the future.\r
171 </p>\r
172 \r
173 <p>\r
174 Circumstances have changed over the years, and now there are many more\r
175 engines that work with xboard.  I've had to make the protocol\r
176 description more precise, I've added some features that GNU Chess\r
177 does not support, and I've specified the standard semantics of a few\r
178 features to be slightly different from what GNU Chess 4 does.\r
179 </p>\r
180 \r
181 <p class="version1">\r
182 This release of the protocol specification is the first to carry a\r
183 version number of its own -- version 2.  Previous releases simply\r
184 carried a last-modified date and were loosely tied to specific \r
185 releases of xboard and WinBoard.  The version number "1" applies\r
186 generally to all those older versions of the protocol.\r
187 </p>\r
188 \r
189 <p class="version1">\r
190 Protocol version 2 remains compatible with older engines but has\r
191 several new capabilities.  In particular, it adds the \r
192 "feature" command, a new mechanism for making backward-compatible\r
193 changes and extensions to the protocol.  Engines that do not support a\r
194 particular new feature do not have to use it; new features are not\r
195 enabled unless the engine specifically requests them using the feature\r
196 command.  If an engine does not send the feature command at all, the\r
197 protocol behavior is nearly identical to version 1.  Several new\r
198 features can be selected by the feature command in version 2,\r
199 including the "ping" command (recommended for all engines), the\r
200 "setboard" command, and many optional parameters.  Additional features\r
201 will probably be added in future versions.\r
202 </p>\r
203 \r
204 <p class="version43">\r
205 If it is necessary to have a separate name, \r
206 it would be best to refer to the protocol including the green additions as version 2f.\r
207 I really don't think it is a different protocol from version 2, though.\r
208 I just tried to clarify some ambiguities in the original definition,\r
209 now that the WinBoard 4.3.xx line has implemented them in a specific way.\r
210 The hand-shaking protocol for features as defined in protocol 2 perfectly\r
211 allows addition of an occasional new features without any need for stepping up the protocol version number,\r
212 and I think refraining from the latter would enormously lower the barrier for actual\r
213 implementation of these features in engines.\r
214 <br />\r
215 The two really new things are the engine debug comments, and the "nps" command.\r
216 The former merely tries to regulate an extremely common existing pactice \r
217 of having engines dump debug messages on WinBoard in an unprotected way, \r
218 as usually you get away with that.\r
219 </p>\r
220 \r
221 <h2><a name="5">5. WinBoard requires Win32 engines</a></h2>\r
222 \r
223 <p>\r
224 Due to some Microsoft brain damage that I don't understand, WinBoard\r
225 does not work with chess engines that were compiled to use a DOS\r
226 extender for 32-bit addressing.  (Probably not with 16-bit DOS or\r
227 Windows programs either.)  WinBoard works only with engines that are\r
228 compiled for the Win32 API.  You can get a free compiler that targets\r
229 the Win32 API from <a href="http://sources.redhat.com/cygwin/"\r
230 >http://sources.redhat.com/cygwin/</a>.  I think DJGPP 2.x should also\r
231 work if you use the RSXNTDJ extension, but I haven't tried it.  Of\r
232 course, Microsoft Visual C++ will work.  Most likely the other\r
233 commercial products that support Win32 will work too (Borland, etc.),\r
234 but I have not tried them.  Delphi has been successfully used to write\r
235 engines for WinBoard; if you want to do this, Tony Werten has donated\r
236 some <a href="http://www.tim-mann.org/winboard/delphi.txt" >sample\r
237 code</a> that should help you get started.\r
238 </p>\r
239 \r
240 <h2><a name="6">6. Hints on input/output</a></h2>\r
241 \r
242 <p>\r
243 Beware of using buffered I/O in your chess engine.  The C stdio\r
244 library, C++ streams, and the I/O packages in most other languages use\r
245 buffering both on input and output.  That means two things.  First,\r
246 when your engine tries to write some characters to xboard, the library\r
247 stashes them in an internal buffer and does not actually write them to\r
248 the pipe connected to xboard until either the buffer fills up or you\r
249 call a special library routine asking for it to be flushed.  (In C\r
250 stdio, this routine is named <tt>fflush</tt>.)  Second, when your engine tries\r
251 to read some characters from xboard, the library does not read just\r
252 the characters you asked for -- it reads all the characters that are\r
253 currently available (up to some limit) and stashes any characters you\r
254 are not yet ready for in an internal buffer.  The next time you ask to\r
255 read, you get the characters from the buffer (if any) before the\r
256 library tries to read more data from the actual pipe.\r
257 </p>\r
258 \r
259 <p>\r
260 Why does this cause problems?  First, on the output side, remember\r
261 that your engine produces output in small quantities (say, a few\r
262 characters for a move, or a line or two giving the current analysis),\r
263 and that data always needs to be delivered to xboard/WinBoard for\r
264 display immediately.  If you use buffered output, the data you print\r
265 will sit in a buffer in your own address space instead of being\r
266 delivered.\r
267 </p>\r
268 \r
269 <p>\r
270 You can usually fix the output buffering problem by asking for the\r
271 buffering to be turned off.  In C stdio, you do this by calling\r
272 <tt>setbuf(stdout, NULL)</tt>.  A more laborious and error-prone\r
273 method is to carefully call <tt>fflush(stdout)</tt> after every line\r
274 you output; I don't recommend this.  In C++, you can try\r
275 <tt>cout.setf(ios::unitbuf)</tt>, which is documented in current\r
276 editions of "The C++ Programming Language," but not older ones.\r
277 Another C++ method that might work is\r
278 <tt>cout.rdbuf()-&gt;setbuf(NULL, 0)</tt>.  Alternatively, you can\r
279 carefully call <tt>cout.flush()</tt> after every line you output;\r
280 again, I don't recommend this.\r
281 </p>\r
282 \r
283 <p>\r
284 Another way to fix the problem is to use unbuffered operating system\r
285 calls to write directly to the file descriptor for standard output.\r
286 On Unix, this means <tt>write(1, ...)</tt> -- see the man page for write(2).\r
287 On Win32, you can use either the Unix-like <tt>_write(1, ...)</tt> or Win32\r
288 native routines like <tt>WriteFile</tt>.\r
289 </p>\r
290 \r
291 <p>\r
292 Second, on the input side, you are likely to want to poll during your\r
293 search and stop it if new input has come in.  If you implement\r
294 pondering, you'll need this so that pondering stops when the user\r
295 makes a move.  You should also poll during normal thinking on your\r
296 move, so that you can implement the "?" (move now) command, and so\r
297 that you can respond promptly to a "result", "force", or "quit"\r
298 command if xboard wants to end the game or terminate your engine.\r
299 Buffered input makes polling more complicated -- when you poll, you\r
300 must stop your search if there are <em>either</em> characters in the buffer\r
301 <em>or</em> characters available from the underlying file descriptor.\r
302 </p>\r
303 \r
304 <p>\r
305 The most direct way to fix this problem is to use unbuffered operating\r
306 system calls to read (and poll) the underlying file descriptor\r
307 directly.  On Unix, use <tt>read(0, ...)</tt> to read from standard input, and\r
308 use <tt>select()</tt> to poll it.  See the man pages read(2) and select(2).\r
309 (Don't follow the example of GNU Chess 4 and use the FIONREAD ioctl to\r
310 poll for input.  It is not very portable; that is, it does not exist\r
311 on all versions of Unix, and is broken on some that do have it.)  On\r
312 Win32, you can use either the Unix-like <tt>_read(0, ...)</tt> or the native\r
313 Win32 <tt>ReadFile()</tt> to read.  Unfortunately, under Win32, the function to\r
314 use for polling is different depending on whether the input device is\r
315 a pipe, a console, or something else.  (More Microsoft brain damage\r
316 here -- did they never hear of device independence?)  For pipes, you\r
317 can use <tt>PeekNamedPipe</tt> to poll (even when the pipe is unnamed).\r
318 For consoles, \r
319 you can use <tt>GetNumberOfConsoleInputEvents</tt>.  For sockets only, you can\r
320 use <tt>select()</tt>.  It might be possible to use\r
321 <tt>WaitForSingleObject</tt> more \r
322 generally, but I have not tried it.  Some code to do these things can\r
323 be found in Crafty's utility.c, but I don't guarantee that it's all\r
324 correct or optimal.\r
325 </p>\r
326 \r
327 <p>\r
328 A second way to fix the problem might be to ask your I/O library not\r
329 to buffer on input.  It should then be safe to poll the underlying\r
330 file descriptor as described above.  With C, you can try calling\r
331 <tt>setbuf(stdin, NULL)</tt>.  However, I have never tried this.  Also, there\r
332 could be problems if you use <tt>scanf()</tt>, at least with certain patterns,\r
333 because <tt>scanf()</tt> sometimes needs to read one extra character and "push\r
334 it back" into the buffer; hence, there is a one-character pushback\r
335 buffer even if you asked for stdio to be unbuffered.  With C++, you\r
336 can try <tt>cin.rdbuf()-&gt;setbuf(NULL, 0)</tt>, but again, I have never tried\r
337 this.\r
338 </p>\r
339 \r
340 <p>\r
341 A third way to fix the problem is to check whether there are\r
342 characters in the buffer whenever you poll.  C I/O libraries generally\r
343 do not provide any portable way to do this.  Under C++, you can use\r
344 <tt>cin.rdbuf()-&gt;in_avail()</tt>.  This method has been reported to\r
345 work with \r
346 EXchess.  Remember that if there are no characters in the buffer, you\r
347 still have to poll the underlying file descriptor too, using the\r
348 method described above.\r
349 </p>\r
350 \r
351 <p>\r
352 A fourth way to fix the problem is to use a separate thread to read\r
353 from stdin.  This way works well if you are familiar with thread\r
354 programming.  This thread can be blocked waiting for input to come in\r
355 at all times, while the main thread of your engine does its thinking.\r
356 When input arrives, you have the thread put the input into a buffer\r
357 and set a flag in a global variable.  Your search routine then\r
358 periodically tests the global variable to see if there is input to\r
359 process, and stops if there is.  WinBoard and my Win32 ports of ICC\r
360 timestamp and FICS timeseal use threads to handle multiple input\r
361 sources.\r
362 </p>\r
363 \r
364 <h2><a name="7">7. Signals</a></h2>\r
365 \r
366 <p>Engines that run on Unix need to be concerned with two Unix\r
367 signals: <tt>SIGTERM</tt> and <tt>SIGINT</tt>.  This applies both to\r
368 engines that run under xboard and (the unusual case of) engines that\r
369 WinBoard remotely runs on a Unix host using the -firstHost or\r
370 -secondHost feature.  It does not apply to engines that run on\r
371 Windows, because Windows does not have Unix-style signals.\r
372 <span class="version1">\r
373 Beginning with version 2, you can now turn off the use of\r
374 either or both\r
375 signals.  See the "feature" command in <a href="#6">section 9</a> below.\r
376 </span>\r
377 </p>\r
378 \r
379 <p>First, when an engine is sent the "quit" command, it is also given\r
380 a <tt>SIGTERM</tt> signal shortly afterward to make sure it goes away.\r
381 If your engine reliably responds to "quit", and the signal causes\r
382 problems for you, you should either ignore it by calling\r
383 <tt>signal(SIGTERM, SIG_IGN)</tt> at the start of your program,\r
384 or disable it with the "feature" command.</p>\r
385 \r
386 <p>Second, xboard will send an interrupt signal (<tt>SIGINT</tt>) at\r
387 certain times when it believes the engine may not be listening to user\r
388 input (thinking or pondering).  WinBoard currently does this only when\r
389 the engine is running remotely using the -firstHost or -secondHost\r
390 feature, not when it is running locally.  You probably need to know\r
391 only enough about this grungy feature to keep it from getting in your\r
392 way.\r
393 </p>\r
394 \r
395 <p>\r
396 The <tt>SIGINT</tt>s are basically tailored to the needs of GNU Chess 4\r
397 on systems where its input polling code is broken or disabled.\r
398 Because they work in a rather peculiar way, it is recommended that you\r
399 either ignore <tt>SIGINT</tt> by having your engine call\r
400 <tt>signal(SIGINT, SIG_IGN)</tt>, or disable it with the "feature"\r
401 command.</p>\r
402 \r
403 <p>\r
404 Here are details for the curious.  If xboard needs to send a command\r
405 when it is the chess engine's move (such as before the "?" command), \r
406 it sends a <tt>SIGINT</tt> first.  If xboard needs to send commands when it is\r
407 not the chess engine's move, but the chess engine may be pondering\r
408 (thinking on its opponent's time) or analyzing (analysis or analyze\r
409 file mode), xboard sends a <tt>SIGINT</tt> before the first such command only.\r
410 Another <tt>SIGINT</tt> is not sent until another move is made, even if xboard\r
411 issues more commands.  This behavior is necessary for GNU Chess 4.  The\r
412 first <tt>SIGINT</tt> stops it from pondering until the next move, but on some\r
413 systems, GNU Chess 4 will die if it receives a <tt>SIGINT</tt> when not \r
414 actually thinking or pondering.\r
415 </p>\r
416 \r
417 <p>\r
418 There are two reasons why WinBoard does not send the Win32 equivalent\r
419 of <tt>SIGINT</tt> (which is called <tt>CTRL_C_EVENT</tt>) to local\r
420 engines.  First, the Win32 GNU Chess 4 port does not need it.  Second, I\r
421 could not find a way to get it to work.  Win32 seems to be designed\r
422 under the assumption that only console applications, not windowed\r
423 applications, would ever want to send a <tt>CTRL_C_EVENT</tt>.\r
424 </p>\r
425 \r
426 <h2><a name="8">8. Commands from xboard to the engine</a></h2>\r
427 \r
428 <p>\r
429 All commands from xboard to the engine end with a newline (\n), even\r
430 where that is not explicitly stated.  All your output to xboard must\r
431 be in complete lines; any form of prompt or partial line will cause\r
432 problems.\r
433 </p>\r
434 \r
435 <p>\r
436 At the beginning of each game, xboard sends an initialization string.\r
437 This is currently "new\nrandom\n" unless the user changes it with the\r
438 initString or secondInitString option.\r
439 </p>\r
440 \r
441 <p>\r
442 xboard normally reuses the same chess engine process for multiple\r
443 games.  At the end of a game, xboard will send the "force" command\r
444 (see below) to make sure your engine stops thinking about the current\r
445 position.  It will later send the initString again to start a new\r
446 game.  If your engine can't play multiple games, you can disable reuse\r
447 <span class="version1">\r
448 either with the "feature" command (beginning in protocol version\r
449 2; see below) or \r
450 </span>\r
451 with xboard's -xreuse (or -xreuse2) command line\r
452 option.  xboard will then ask the process to quit after each game and\r
453 start a new process for the next game.\r
454 </p>\r
455 \r
456 <dl>\r
457 <dt>xboard</dt>\r
458 <dd>This command will be sent once immediately after your engine\r
459 process is started.  You can use it to put your engine into "xboard\r
460 mode" if that is needed.  If your engine prints a prompt to ask for\r
461 user input, you must turn off the prompt and output a newline when the\r
462 "xboard" command comes in.\r
463 </dd>\r
464 \r
465 <dt class="version1">protover N</dt>\r
466 <dd class="version1">\r
467 <p>Beginning in protocol version 2 (in which N=2), this command will\r
468 be sent immediately after the "xboard" command.  If you receive some\r
469 other command immediately after "xboard" (such as "new"), you can\r
470 assume that protocol version 1 is in use.  The "protover" command is\r
471 the only new command that xboard always sends in version 2.  All other\r
472 new commands to the engine are sent only if the engine first enables\r
473 them with the "feature" command.  Protocol versions will always be\r
474 simple integers so that they can easily be compared.\r
475 </p>\r
476 \r
477 <p>Your engine should reply to the protover command by sending the\r
478 "feature" command (see below) with the list of non-default feature\r
479 settings that you require, if any.</p>\r
480 \r
481 <p>Your engine should never refuse to run due to receiving a higher\r
482 protocol version number than it is expecting!  New protocol versions\r
483 will always be compatible with older ones by default; the larger\r
484 version number is simply a hint that additional "feature" command\r
485 options added in later protocol versions may be accepted.\r
486 </p>\r
487 </dd>\r
488 \r
489 <dt class="version1">accepted</dt>\r
490 <dt class="version1">rejected</dt>\r
491 <dd class="version1">\r
492 These commands may be sent to your engine in reply to the "feature"\r
493 command; see its documentation below.\r
494 </dd>\r
495 \r
496 <dt>new</dt>\r
497 <dd>Reset the board to the standard chess starting position.  Set\r
498 White on move.  Leave force mode and set the engine to play Black.\r
499 Associate the engine's clock with Black and the opponent's clock with\r
500 White.  Reset clocks and time controls to the start of a new game.\r
501 Use wall clock for time measurement.\r
502 Stop clocks.  Do not ponder on this move, even if pondering is on.\r
503 Remove any search depth limit previously set by the sd command.\r
504 </dd>\r
505 \r
506 <dt>variant VARNAME</dt>\r
507 <dd>If the game is not standard chess, but a variant, this command is\r
508 sent after "new" and before the first move or "edit" command.  Currently\r
509 defined variant names are:\r
510 \r
511 <table>\r
512 <tr><td>wildcastle</td><td>Shuffle chess where king can castle from d file</td></tr>\r
513 <tr><td>nocastle</td><td>Shuffle chess with no castling at all</td></tr>\r
514 <tr><td>fischerandom</td><td>Fischer Random</td></tr>\r
515 <tr><td>bughouse</td><td>Bughouse, ICC/FICS rules</td></tr>\r
516 <tr><td>crazyhouse</td><td>Crazyhouse, ICC/FICS rules</td></tr>\r
517 <tr><td>losers</td><td>Win by losing all pieces or getting mated (ICC)</td></tr>\r
518 <tr><td>suicide</td><td>Win by losing all pieces including king,\r
519     or by having fewer pieces when one player has no legal moves (FICS)</td></tr>\r
520 <tr class="version1"><td>giveaway</td><td>Win by losing all pieces including king,\r
521     or by having no legal moves (ICC)</td></tr>\r
522 <tr><td>twokings</td><td>Weird ICC wild 9</td></tr>\r
523 <tr><td>kriegspiel</td><td>Kriegspiel (engines not supported)</td></tr>\r
524 <tr><td>atomic</td><td>Atomic</td></tr>\r
525 <tr><td>3check</td><td>Win by giving check 3 times</td></tr>\r
526 <tr class="version43"><td>xiangqi </td><td>Chinese Chess (9x10 board)</td></tr>\r
527 <tr class="version43"><td>shogi </td><td>Japanese Chess (9x9 bord)</td></tr>\r
528 <tr class="version43"><td>capablanca</td><td>Capablanca Chess (10x8 board, with Archbishop and Chancellor)</td></tr>\r
529 <tr class="version43"><td>gothic  </td><td>Gothic Chess (10x8 board, same with better opening setup)</td></tr>\r
530 <tr class="version43"><td>falcon  </td><td>Falcon Chess (10x8 board, with two Falcon pieces)</td></tr>\r
531 <tr class="version43"><td>shatranj  </td><td>ancient Arabic Chess, with Elephants and General in stead of B and Q</td></tr>\r
532 <tr class="version43"><td>courier  </td><td>Courier Chess (12x8 board, a medieval precursor of modern Chess</td></tr>\r
533 <tr class="version43"><td>knightmate  </td><td>King moves as Knight and vice versa</td></tr>\r
534 <tr class="version43"><td>berolina</td><td>    Pawns capture straight ahead, and move diagonally</td></tr>\r
535 <tr class="version43"><td>janus</td><td>    Janus Chess (10x8, with two Archbishops)</td></tr>\r
536 <tr class="version43"><td>caparandom  </td><td>shuffle variant like FRC (10x8 board)</td></tr>\r
537 <tr class="version43"><td>cylinder  </td><td>Pieces wrap around between side edges, like board is a cylinder</td></tr>\r
538 <tr class="version44"><td>super  </td><td>Superchess: a shuffle variant with 4 fairy pieces on 8x8 board</td></tr>\r
539 <tr class="version44"><td>great  </td><td>Great Shatranj: sliders are replaced by corresponding short-range pieces on a 10x8 board</td></tr>\r
540 <tr><td>unknown</td><td>Unknown variant (not supported)</td></tr>\r
541 </table>\r
542 \r
543 As of XBoard 4.8, engines can define arbitrary variant names; see the "feature" and "setup" commands in <a href="#9">section 9</a>.\r
544 </dd>\r
545 \r
546 <dt>quit</dt>\r
547 <dd>The chess engine should immediately exit.  This command is used\r
548 when xboard is itself exiting, and also between games if the -xreuse\r
549 command line option is given (or -xreuse2 for the second engine).\r
550 See also <a href="#7">Signals</a> above.\r
551 </dd>\r
552 \r
553 <dt>random</dt>\r
554 <dd>This command is specific to GNU Chess 4.  You can either ignore it\r
555 completely (that is, treat it as a no-op) or implement it as GNU Chess\r
556 does.  The command toggles "random" mode (that is, it sets random =\r
557 !random).  In random mode, the engine adds a small random value to its\r
558 evaluation function to vary its play.  The "new" command sets random\r
559 mode off.\r
560 </dd>\r
561 \r
562 <dt>force</dt>\r
563 <dd>Set the engine to play neither color ("force mode").  Stop clocks.\r
564 The engine should check that moves received in force mode are legal\r
565 and made in the proper turn, but should not think, ponder, or make\r
566 moves of its own.\r
567 </dd>\r
568 \r
569 <dt>go</dt>\r
570 <dd>Leave force mode and set the engine to play the color that is on\r
571 move.  Associate the engine's clock with the color that is on move,\r
572 the opponent's clock with the color that is not on move.  Start the engine's\r
573 clock.  Start thinking and eventually make a move.\r
574 </dd>\r
575 \r
576 <dt class="version1">playother</dt>\r
577 <dd class="version1">\r
578 (This command is new in protocol version 2.  It is not\r
579 sent unless you enable it with the feature command.)\r
580 Leave force mode and set the engine to play the color that is <i>not</i> on\r
581 move.  Associate the opponent's clock with the color that is on move,\r
582 the engine's clock with the color that is not on move.  Start the opponent's\r
583 clock.  If pondering is enabled, the engine should begin pondering.\r
584 If the engine later receives a move, it should start thinking and eventually\r
585 reply.\r
586 </dd>\r
587 \r
588 <dt>white</dt>\r
589 <dd>\r
590 <p><span class="version1">\r
591 (This command is obsolete as of protocol version 2, but is still\r
592 sent in some situations to accommodate older engines unless you disable it \r
593 with the feature command.)\r
594 </span>\r
595 Set White on move.  Set the engine to play Black.  Stop clocks.\r
596 </p>\r
597 </dd>\r
598   \r
599 <dt>black </dt>\r
600 <dd>\r
601 <span class="version1">\r
602 (This command is obsolete as of protocol version 2, but is still\r
603 sent in some situations to accommodate older engines unless you disable it \r
604 with the feature command.)\r
605 </span>\r
606 Set Black on move.  Set the engine to play White.  Stop clocks.\r
607 </dd>\r
608 \r
609 <dt>level MPS BASE INC</dt>\r
610 <dd>Set time controls.  See the <a href="#11">Time Control</a> section below.\r
611 </dd>\r
612   \r
613 <dt>st TIME</dt>\r
614 <dd>Set time controls.  See the <a href="#11">Time Control</a> section\r
615 below. \r
616 </dd>\r
617 \r
618 <dt>sd DEPTH</dt>\r
619 <dd>\r
620 <p>The engine should limit its thinking to DEPTH ply.\r
621 <span class="version43">The commands "level" or "st" and "sd" can be used together in an orthogonal way.\r
622 If both are issued, the engine should observe both limitations:</span>\r
623 In the protocol, the "sd" command isn't a time control.  It doesn't\r
624 say that your engine has unlimited time but must search to exactly the\r
625 given depth.  It says that you should pay attention to the time\r
626 control as normal, but cut off the search at the specified depth even\r
627 if you have time to search deeper.  If you don't have time to search\r
628 to the specified depth, given your normal time management algorithm,\r
629 then you will want to stop sooner than the given depth.\r
630 </p><p>\r
631 The "new" command should set the search depth back to unlimited.  This\r
632 is already stated in the spec.  The "level" command should not affect\r
633 the search depth.  As it happens, xboard/WinBoard currently always\r
634 sends sd (if needed) right after level, but that isn't part of the\r
635 spec.</p>\r
636 </dd>\r
637 \r
638 <dt><span class="version43">nps NODE_RATE</span></dt>\r
639 <dd><span class="version43">The engine should not use wall-clock time to make its timing decisions,\r
640 but an own internal time measure based on the number of nodes it has searched\r
641 (and will report as "thinking output", see <a href="#10">section 10</a>),\r
642 converted to seconds through dividing by the given NODE_RATE.\r
643 Example: after receiving the commands "st 8" and "nps 10000",\r
644 the engine should never use more that 80,000 nodes in the search for any move.\r
645 In this mode, the engine should report user CPU time used (in its thinking output), \r
646 rather than wall-clock time.\r
647 This even holds if NODE_RATE is given as 0,\r
648 but in that case it should also use the user CPU time for its timing decisions.\r
649 The effect of an "nps" command should persist until the next "new" command.\r
650 </span>\r
651 </dd>\r
652 \r
653 <dt>time N</dt>\r
654 <dd>Set a clock that always belongs to the engine.  N is a number in\r
655   centiseconds (units of 1/100 second).  Even if the engine changes to\r
656   playing the opposite color, this clock remains with the engine.\r
657 </dd>\r
658 \r
659 <dt>otim N</dt>\r
660 \r
661 <dd><p>Set a clock that always belongs to the opponent.  N is a number in\r
662 centiseconds (units of 1/100 second).  Even if the opponent changes to\r
663 playing the opposite color, this clock remains with the opponent.\r
664 </p><p>\r
665 If needed for purposes of board display in force mode (where the\r
666 engine is not participating in the game) the time clock should be\r
667 associated with the last color that the engine was set to play, the\r
668 otim clock with the opposite color.\r
669 </p>\r
670 <p>\r
671 <span class="version43">This business of "clocks remaining with the engine" is apparently so ambiguous\r
672 that many engines implement it wrong.\r
673 The clocks in fact always remain with the color.\r
674 Which clock reading is relayed with "time", and which by "otim", is determined by which side the engine plays.\r
675 Note that the way the clocks operate and receive extra time (in accordance with the selected time control)\r
676 is not affected in any way by which moves are made by the engine, which by the opponent, and which were forced.\r
677 </span>\r
678 </p>\r
679 <p>\r
680 <span class="version1">\r
681 Beginning in protocol version 2, if you can't handle the time and\r
682 otim commands, you can use the "feature" command to disable them; see\r
683 below.  \r
684 </span>\r
685 The following techniques from older protocol versions also\r
686 work: You can ignore the time and otim commands (that is, treat them\r
687 as no-ops), or send back "Error (unknown command): time" the first\r
688 time you see "time".\r
689 </p></dd>\r
690 \r
691 <dt>MOVE</dt>\r
692 <dd>\r
693 <p>See below for the syntax of moves.  If the move is illegal, print\r
694 an error message; see the section "<a href="#9">Commands from the engine to\r
695 xboard</a>".  If the move is legal and in turn, make it.  If not in force\r
696 mode, stop the opponent's clock, start the engine's clock, start\r
697 thinking, and eventually make a move.\r
698 </p><p>\r
699 When xboard sends your engine a move, it normally sends coordinate\r
700 algebraic notation.  Examples:\r
701 </p>\r
702 <table>\r
703 <tr><td>Normal moves:</td><td>e2e4</td></tr>\r
704 <tr><td>Pawn promotion:</td><td>e7e8q</td></tr>\r
705 <tr><td>Castling:</td><td>e1g1, e1c1, e8g8, e8c8</td></tr>\r
706 <tr><td>Bughouse/crazyhouse drop:</td><td>P@h3</td></tr>\r
707 <tr><td>ICS Wild 0/1 castling:</td><td>d1f1, d1b1, d8f8, d8b8</td></tr>\r
708 <tr><td>FischerRandom castling:</td><td>O-O, O-O-O (oh, not zero)</td></tr>\r
709 </table>\r
710 \r
711 <p class="version43">\r
712 Note that on boards with more than 9 ranks, counting of the ranks starts at 0.\r
713 </p>\r
714 <p class="version1">\r
715 Beginning in protocol version 2, you can use the feature command\r
716 to select SAN (standard algebraic notation) instead; for example, e4,\r
717 Nf3, exd5, Bxf7+, Qxf7#, e8=Q, O-O, or P@h3.  Note that the last form,\r
718 P@h3, is a extension to the PGN standard's definition of SAN, which does\r
719 not support bughouse or crazyhouse.\r
720 </p>\r
721 \r
722 <p>\r
723 xboard doesn't reliably detect illegal moves, because it does not keep\r
724 track of castling unavailability due to king or rook moves, or en\r
725 passant availability.  If xboard sends an illegal move, send back an\r
726 error message so that xboard can retract it and inform the user; see\r
727 the section "<a href="#9">Commands from the engine to xboard</a>".\r
728 </p>\r
729 </dd>\r
730 <dt class="version1">usermove MOVE</dt>\r
731 <dd class="version1">\r
732 By default, moves are sent to the engine without a command name;\r
733 the notation is just sent as a line by itself.\r
734 Beginning in protocol version 2, you can use the feature command\r
735 to cause the command name "usermove" to be sent before the move.\r
736 Example: "usermove e2e4".\r
737 </dd>\r
738 \r
739 <dt>?</dt>\r
740 <dd><p>Move now.  If your engine is thinking, it should move immediately;\r
741   otherwise, the command should be ignored (treated as a no-op).  It\r
742   is permissible for your engine to always ignore the ? command.  The\r
743   only bad consequence is that xboard's Move Now menu command will do\r
744   nothing.\r
745 </p><p>\r
746 It is also permissible for your engine to move immediately if it gets\r
747 any command while thinking, as long as it processes the command right\r
748 after moving, but it's preferable if you don't do this.  For example,\r
749 xboard may send post, nopost, easy, hard, force, quit,\r
750 <span class="version1">\r
751 or other commands\r
752 </span>\r
753 while the engine is on move.\r
754 </p>\r
755 </dd>\r
756 \r
757 <dt class="version1">ping N</dt>\r
758 <dd class="version1">\r
759 <p>In this command, N is a decimal number.  When you receive the command,\r
760 reply by sending the string <strong>pong N</strong>, where N is the\r
761 same number you received.  Important: You must not reply to a "ping"\r
762 command until you have finished executing all commands that you\r
763 received before it.  Pondering does not count; if you receive a ping\r
764 while pondering, you should reply immediately and continue pondering.\r
765 Because of the way xboard uses the ping command, if you implement the\r
766 other commands in this protocol, you should never see a "ping" command\r
767 when it is your move; however, if you do, you must not send the "pong"\r
768 reply to xboard until after you send your move.  For example, xboard\r
769 may send "?" immediately followed by "ping".  If you implement the "?"\r
770 command, you will have moved by the time you see the subsequent ping\r
771 command.  Similarly, xboard may send a sequence like "force", "new",\r
772 "ping".  You must not send the pong response until after you have\r
773 finished executing the "new" command and are ready for the new game to\r
774 start.\r
775 </p>\r
776 <p>\r
777 The ping command is new in protocol version 2 and will not be sent\r
778 unless you enable it with the "feature" command.  Its purpose is to\r
779 allow several race conditions that could occur in previous versions of\r
780 the protocol to be fixed, so it is highly recommended that you\r
781 implement it.  It is especially important in simple engines that do\r
782 not ponder and do not poll for input while thinking, but it is needed in all\r
783 engines.  \r
784 </p>\r
785 </dd>\r
786 \r
787 <dt>draw</dt>\r
788 <dd>The engine's opponent offers the engine a draw.  To accept the\r
789 draw, send "offer draw".  To decline, ignore the offer (that is, send\r
790 nothing).  If you're playing on ICS, it's possible for the draw offer\r
791 to have been withdrawn by the time you accept it, so don't assume the\r
792 game is over because you accept a draw offer.  Continue playing until\r
793 xboard tells you the game is over.  See also "offer draw" below.\r
794 </dd>\r
795 \r
796 <dt>result RESULT {COMMENT}</dt>\r
797 <dd>After the end of each game, xboard will send you a result command.\r
798 You can use this command to trigger learning.  RESULT is either 1-0,\r
799 0-1, 1/2-1/2, or *, indicating whether white won, black won, the game\r
800 was a draw, or the game was unfinished.  The COMMENT string is purely\r
801 a human-readable comment; its content is unspecified and subject to\r
802 change.  In ICS mode, it is passed through from ICS uninterpreted.\r
803 Example: <pre>result 1-0 {White mates}</pre>\r
804 <p>\r
805 Here are some notes on interpreting the "result" command.  Some apply\r
806 only to playing on ICS ("Zippy" mode).\r
807 </p>\r
808 \r
809 <p>\r
810 If you won but did not just play a mate, your opponent must have\r
811 resigned or forfeited.  If you lost but were not just mated, you\r
812 probably forfeited on time, or perhaps the operator resigned manually.\r
813 If there was a draw for some nonobvious reason, perhaps your opponent\r
814 called your flag when he had insufficient mating material (or vice\r
815 versa), or perhaps the operator agreed to a draw manually.\r
816 </p>\r
817 \r
818 <p>\r
819 You will get a result command even if you already know the game ended\r
820 -- for example, after you just checkmated your opponent.  In fact, if\r
821 you send the "RESULT {COMMENT}" command (discussed below), you will\r
822 simply get the same thing fed back to you with "result" tacked in\r
823 front.  You might not always get a "result *" command, however.  In\r
824 particular, you won't get one in local chess engine mode when the user\r
825 stops playing by selecting Reset, Edit Game, Exit or the like.\r
826 </p>\r
827 </dd>\r
828 \r
829 <dt><span class="version1">setboard FEN</span></dt>\r
830 <dd>\r
831 <p><span class="version1">\r
832 The setboard command is the new way to set up positions, beginning\r
833 in protocol version 2.  It is not used unless it has been selected\r
834 with the feature command.  Here FEN is a position in Forsythe-Edwards\r
835 Notation, as defined in the PGN standard.</span>\r
836 <span class="version43">Note that this PGN standard referred to here\r
837 only applies to normal Chess;\r
838 Obviously in variants that cannot be described by a FEN for normal Chess,\r
839 e.g. because the board is not 8x8, other pieces then PNBRQK participate, \r
840 there are holdings that need to be specified, etc., \r
841 xboard will use a FEN format that is standard or suitable for that variant.\r
842 In particular, in FRC or CRC, WinBoard will use Shredder-FEN or X-FEN standard,\r
843 i.e. it can use the rook-file indicator letter to represent a castling right \r
844 (like HAha) whenever it wants, but if it uses KQkq, this will always refer \r
845 to the outermost rook on the given side.</span>\r
846 </p>\r
847 \r
848 <p class="version1">\r
849 <em>Illegal positions:</em> Note that either setboard or edit can\r
850 be used to send an illegal position to the engine.  The user can\r
851 create any position with xboard's Edit Position command (even, say,\r
852 an empty board, or a board with 64 white kings and no black ones).\r
853 If your engine receives a position that it considers illegal, \r
854 I suggest that you send the response "tellusererror Illegal position",\r
855 and then respond to any attempted move with "Illegal move" until\r
856 the next new, edit, or setboard command.\r
857 </p>\r
858 </dd>\r
859 \r
860 <dt>edit</dt>\r
861 <dd>\r
862 <p><span class="version1">\r
863 The edit command is the old way to set up positions.  For compatibility\r
864 with old engines, it is still used by default, but new engines may prefer\r
865 to use the feature command (see below) to cause xboard to use setboard instead.\r
866 </span>\r
867 The edit command puts the chess engine into a special mode, where\r
868 it accepts the following subcommands:</p>\r
869 <table>\r
870 <tr><td>c</td><td>change current piece color, initially white</td></tr>\r
871 <tr><td>Pa4 (for example)</td><td>place pawn of current color on a4</td></tr>\r
872 <tr><td>xa4 (for example)</td><td>empty the square a4 (not used by xboard)</td></tr>\r
873 <tr><td>#</td><td>clear board</td></tr>\r
874 <tr><td>.</td><td>leave edit mode</td></tr>\r
875 </table>\r
876 <p class="version1">\r
877 See the Idioms section below for additional subcommands used in\r
878 ChessBase's implementation of the protocol.\r
879 </p>\r
880 \r
881 <p>The edit command does not change the side to move.  To set up a\r
882 black-on-move position, xboard uses the following command sequence:\r
883 </p>\r
884 <pre>\r
885     new\r
886     force\r
887     a2a3\r
888     edit\r
889     &lt;edit commands&gt;\r
890     .\r
891 </pre>\r
892 \r
893 <p>\r
894 This sequence is used to avoid the "black" command, which is now\r
895 considered obsolete and which many engines never did implement as \r
896 specified in this document.\r
897 </p>\r
898 \r
899 <p>\r
900 After an edit command is complete, if a king and a rook are on their\r
901 home squares, castling is assumed to be available to them.  En passant\r
902 capture is assumed to be illegal on the current move regardless of the\r
903 positions of the pawns.  The clock for the 50 move rule starts at\r
904 zero, and for purposes of the draw by repetition rule, no prior\r
905 positions are deemed to have occurred.\r
906 <span class="version43">\r
907 In FRC or CRC, any rook and king put on the back rank should be considered to\r
908 have castling rights, even if it later becomes apparent that they cannot be both in the\r
909 initial position, because the position just set up is asymmetric.\r
910 It is upto WinBoard to find work-around in cases where this is not desired,\r
911 similar to the "black kludge" shown above, by setting up an earlier position,\r
912 and then do a move to destroy castling rights or create e.p. rights.\r
913 (Don't bet your life on it...)\r
914 </span>\r
915 </p>\r
916 </dd>\r
917 \r
918 <dt>hint</dt>\r
919 <dd>If the user asks for a hint, xboard sends your engine the command\r
920 "hint".  Your engine should respond with "Hint: xxx", where xxx is a\r
921 suggested move.  If there is no move to suggest, you can ignore the\r
922 hint command (that is, treat it as a no-op).\r
923 </dd>\r
924 \r
925 <dt>bk</dt>\r
926 <dd>If the user selects "Book" from the xboard menu, xboard will send\r
927 your engine the command "bk".  You can send any text you like as the\r
928 response, as long as each line begins with a blank space or tab (\t)\r
929 character, and you send an empty line at the end.  The text pops up in\r
930 a modal information dialog.\r
931 </dd>\r
932 \r
933 <dt>undo</dt>\r
934 <dd>If the user asks to back up one move, xboard will send you the\r
935 "undo" command.  xboard will not send this command without putting you\r
936 in "force" mode first, so you don't have to worry about what should\r
937 happen if the user asks to undo a move your engine made.  (GNU Chess 4\r
938 actually switches to playing the opposite color in this case.)\r
939 </dd>\r
940 \r
941 <dt>remove</dt>\r
942 <dd>If the user asks to retract a move, xboard will send you the\r
943 "remove" command.  It sends this command only when the user is on\r
944 move.  Your engine should undo the last two moves (one for each\r
945 player) and continue playing the same color.\r
946 </dd>\r
947 \r
948 <dt>hard</dt>\r
949 <dd>Turn on pondering (thinking on the opponent's time, also known as\r
950 "permanent brain").  xboard will not make any assumption about what\r
951 your default is for pondering or whether "new" affects this setting.\r
952 </dd>\r
953 \r
954 <dt>easy</dt>\r
955 <dd>Turn off pondering.</dd>\r
956   \r
957 <dt>post</dt>\r
958 <dd>Turn on thinking/pondering output.  \r
959 See <a href="#10">Thinking Output</a> section.</dd>\r
960 \r
961 <dt>nopost</dt>\r
962 <dd>Turn off thinking/pondering output.</dd>\r
963   \r
964 <dt>analyze</dt>\r
965 <dd>Enter analyze mode.  See <a href="#12">Analyze Mode</a> section.</dd>\r
966 \r
967 <dt>name X </dt>\r
968 <dd>This command informs the engine of its\r
969 opponent's name.  When the engine is playing on a chess server, xboard\r
970 obtains the opponent's name from the server. \r
971 <span class="version1">\r
972 When the engine is\r
973 playing locally against a human user, xboard obtains the user's login\r
974 name from the local operating system.  When the engine is playing\r
975 locally against another engine, xboard uses either the other engine's\r
976 filename or the name that the other engine supplied in the myname\r
977 option to the feature command.  By default, xboard uses the name\r
978 command only when the engine is playing on a chess server.  Beginning\r
979 in protocol version 2, you can change this with the name option to the\r
980 feature command; see below.\r
981 </span>\r
982 </dd>\r
983 \r
984 <dt>rating</dt>\r
985 <dd>In ICS mode, xboard obtains the ICS opponent's rating from the\r
986 "Creating:" message that appears before each game.  (This message may\r
987 not appear on servers using outdated versions of the FICS code.)  In\r
988 Zippy mode, it sends these ratings on to the chess engine using the\r
989 "rating" command.  The chess engine's own rating comes first, and if\r
990 either opponent is not rated, his rating is given as 0.  \r
991 <span class="version1">\r
992 In the future this command may also be used in other modes, if ratings\r
993 are known.\r
994 </span>\r
995 Example: <pre>rating 2600 1500</pre>\r
996 </dd>\r
997 \r
998 <dt><span class="version1">ics HOSTNAME</span></dt>\r
999 <dd class="version1">\r
1000 If HOSTNAME is "-", the engine is playing against a local\r
1001 opponent; otherwise, the engine is playing on an Internet Chess Server\r
1002 (ICS) with the given hostname.  This command is new in protocol\r
1003 version 2 and is not sent unless the engine has enabled it with\r
1004 the "feature" command.  Example: "ics freechess.org"\r
1005 </dd>\r
1006 \r
1007 <dt>computer</dt>\r
1008 <dd>The opponent is also a computer chess engine.  Some engines alter\r
1009 their playing style when they receive this command.\r
1010 </dd>\r
1011 \r
1012 <dt class="version1">pause</dt>\r
1013 <dt class="version1">resume</dt>\r
1014 <dd class="version1">(These commands are new in protocol\r
1015 version 2 and will not be sent unless feature pause=1 is set.  At\r
1016 this writing, xboard actually does not use the commands at all, but it\r
1017 or other interfaces may use them in the future.)\r
1018 The "pause" command puts the engine into a special state where it\r
1019 does not think, ponder, or otherwise consume significant CPU time.\r
1020 The current thinking or pondering (if any) is suspended and both\r
1021 player's clocks are stopped.  The only command that the interface may\r
1022 send to the engine while it is in the paused state is "resume".  The\r
1023 paused thinking or pondering (if any) resumes from exactly where it\r
1024 left off, and the clock of the player on move resumes running from\r
1025 where it stopped.\r
1026 </dd>\r
1027 \r
1028 <dt class="version44">memory N</dt>\r
1029 <dd class="version44">\r
1030 This command informs the engine on how much memory it is allowed to use maximally, in MegaBytes.\r
1031 On receipt of this command, the engine should adapt the size of its hash tables accordingly.\r
1032 This command does only fix the total memory use,\r
1033 the engine has to decide for itself \r
1034 (or be configured by the user by other means) \r
1035 how to divide up the available memory between the various tables it wants to use \r
1036 (e.g. main hash, pawn hash, tablebase cache, bitbases).\r
1037 This command will only be sent to engines that have requested it through the memory feature,\r
1038 and only at the start of a game,\r
1039 as the first of the commands to relay engine option settings just before each "new" command.\r
1040 </dd>\r
1041 \r
1042 <dt class="version44">cores N</dt>\r
1043 <dd class="version44">\r
1044 This command informs the engine on how many CPU cores it is allowed to use maximally.\r
1045 This could be interpreted as the number of search threads for SMP engines. \r
1046 (Threads that do not consume significant amounts of CPU time, like I/O threads, need not be included in the count.)\r
1047 This command will only be sent to engines that have requested it through the smp feature.\r
1048 The engine should be able to respond to the "cores" command any time during a game,\r
1049 but it is allowed to finish a search in progress before procesing the command.\r
1050 (Obeying the command should take priority over finishing a ponder search, though.)\r
1051 In any case it will be sent at the start of every game\r
1052 as the last command to relay engine option settings before the "new" command.\r
1053 </dd>\r
1054 \r
1055 <dt class="version44">egtpath TYPE PATH</dt>\r
1056 <dd class="version44">\r
1057 This command informs the engine in which directory (given by the PATH argument)\r
1058 it can find end-game tables of the specified TYPE.\r
1059 The TYPE argument can be any character string which does not contain spaces.\r
1060 Currently <strong>nalimov</strong> and <strong>scorpio</strong> are defined types, \r
1061 for Nalimov tablebases and Scorpio bitbases, respectively,\r
1062 but future developers of other formats are free to define their own format names.\r
1063 The GUI simply matches the TYPE names the engine says it supports \r
1064 with those that the user supplied when configuring xboard.\r
1065 For every match, it sends a separate "y" command.\r
1066 The PATH argument would normally (for Nalimov) be the pathname of the directory the EGT files are in,\r
1067 but could also be the name of a file, or in fact anything the particular EGT type requires.\r
1068 It is upto the developer of the EGT format to specify the syntax of this parameter.\r
1069 This command will only be sent to engines that have told the GUI they support EGTs of the given TYPE\r
1070 through the egt feature.\r
1071 It will be sent at the start of each game, before the "new" command.\r
1072 </dd>\r
1073 \r
1074 <dt class="version44">option NAME[=VALUE]</dt>\r
1075 <dd class="version44">\r
1076 This command changes the setting of the option NAME defined by the engine \r
1077 (through an earlier feature command)\r
1078 to the given VALUE.\r
1079 XBoard will in general have no idea what the option means,\r
1080 and will send the command only when a user changes the value of this option through a menu,\r
1081 or at startup of the engine \r
1082 (before the first 'cores' command or, if that is not sent, the first 'new' command)\r
1083 in reaction to command-line options.\r
1084 The NAME echoes back to the engine the string that was identified as an option NAME\r
1085 in the feature command defining the option.\r
1086 The VALUE is of the type (numeric or text or absent) that was implied by the option type\r
1087 specified in this feature command,\r
1088 i.e. with 'spin' and 'check' options VALUE will be a decimal integer (in the latter case 0 or 1),\r
1089 with 'combo' and 'string' options VALUE will be a text string,\r
1090 and with 'button' and 'save' options no VALUE will be sent at all.\r
1091 </dd>\r
1092 \r
1093 <dt class="version47">exclude MOVE</dt>\r
1094 <dt class="version47">include MOVE</dt>\r
1095 <dt class="version47">exclude all</dt>\r
1096 <dt class="version47">include all</dt>\r
1097 <dd class="version47">\r
1098 These commands change the set of moves that the engine should consider in the root node of its search,\r
1099 by removing or adding the mentioned MOVE from this set.\r
1100 After reaching a new position, (e.g. through a usermove, undo, new or setboard command),\r
1101 or after receiving "include all",\r
1102 this set should always be reset to all legal moves from that position.\r
1103 If the set of moves changes during a search, \r
1104 the engine could start a new search from scratch, or it can try to be smart, \r
1105 and continue the current search with the new set of moves\r
1106 (e.g. after exclusion of a move that has not been searched yet in the current iteration).\r
1107 After "exclude all", the engine would have no legal moves in the root,\r
1108 which logically should make it behave as if it is (stale)mated,\r
1109 but it is allowed to defer any effects of this command on a search in progress\r
1110 to when the set gets non-empty again through addition of a move.\r
1111 These commands will only be sent to engines that have requested such through the exclude feature.\r
1112 </dd>\r
1113 \r
1114 <dt class="version47">setscore SCORE DEPTH</dt>\r
1115 <dd class="version47">\r
1116 This command instructs the engine to treat future search requests on the current position\r
1117 (also when it is encountered inside a larger search tree)\r
1118 upto the given DEPTH as if these result is SCORE centi-Pawn in favor of the side that has the move in this position.\r
1119 It is entirely up to the engine to decide when the effect of this option should expire.\r
1120 (E.g. it could last upto the next "new" or "quit" command,\r
1121 or even into future sessions until the user explicitly clears it through an engine-defined option.)\r
1122 This command will only be sent to engines that have requested it through the setscore feature.\r
1123 </dd>\r
1124 </dl>\r
1125 \r
1126 <h3>Bughouse commands:</h3>\r
1127 \r
1128 <p>\r
1129 xboard now supports bughouse engines when in Zippy mode.  See\r
1130 <a href="http://www.tim-mann.org/xboard/zippy.README"\r
1131 >zippy.README</a> for information on Zippy mode and how to turn on the\r
1132 bughouse support.  The bughouse move format is given above.  xboard\r
1133 sends the following additional commands to the engine when in bughouse\r
1134 mode.  \r
1135 Commands to inform your engine of the partner's game state may\r
1136 be added in the future.\r
1137 </p>\r
1138 \r
1139 <dl>\r
1140 <dt>partner &lt;player&gt;</dt>\r
1141 <dd>&lt;player&gt; is now your partner for future games.  Example: <pre>partner mann</pre>\r
1142 </dd>\r
1143 \r
1144 <dt>partner</dt>\r
1145 <dd>Meaning: You no longer have a partner.\r
1146 </dd>\r
1147 \r
1148 <dt>ptell &lt;text&gt;</dt>\r
1149 <dd>Your partner told you &lt;text&gt;, either with a ptell or an ordinary tell.  \r
1150 </dd>\r
1151 \r
1152 <dt>holding [&lt;white&gt;] [&lt;black&gt;]</dt>\r
1153 <dd>White currently holds &lt;white&gt;; black currently holds &lt;black&gt;.\r
1154   Example: <pre>holding [PPPRQ] []</pre></dd>\r
1155 \r
1156 <dt>holding [&lt;white&gt;] [&lt;black&gt;] &lt;color&gt;&lt;piece&gt;</dt>\r
1157 <dd>White currently holds &lt;white&gt;; black currently holds &lt;black&gt;, after\r
1158   &lt;color&gt; acquired &lt;piece&gt;.   Example: <pre>holding [PPPRQ] [R] BR</pre></dd>\r
1159 </dl>\r
1160 \r
1161 <h2><a name="9">9. Commands from the engine to xboard</a></h2>\r
1162 \r
1163 <p class="version1">\r
1164 In general, an engine should not send any output to xboard that is not\r
1165 described in this document.  As the protocol is extended, newer\r
1166 versions of xboard may recognize additional strings as commands that\r
1167 were previously not assigned a meaning.\r
1168 </p>\r
1169 \r
1170 <dl>\r
1171 \r
1172 <dt class="version1"> feature FEATURE1=VALUE1 FEATURE2=VALUE2 ... </dt>\r
1173 <dd class="version1">\r
1174 <p>Beginning with version 2, the protocol includes the "feature"\r
1175 command, which lets your engine control certain optional protocol\r
1176 features.  Feature settings are written as FEATURE=VALUE, where\r
1177 FEATURE is a name from the list below and VALUE is the value to be\r
1178 assigned.  Features can take string, integer, or boolean values; the\r
1179 type of value is listed for each feature.  String values are written\r
1180 in double quotes (for example, <tt>feature myname="Miracle Chess\r
1181 0.9"</tt>), integers are written in decimal, and boolean values are\r
1182 written as 0 for false, 1 for true.  Any number of features can be set\r
1183 in one feature command, or multiple feature commands can be given.</p>\r
1184 \r
1185 <p>\r
1186 Your engine should send one or more feature commands immediately after\r
1187 receiving the "protover" command, since xboard needs to know the\r
1188 values of some features before sending further commands to the engine.\r
1189 Because engines that predate protocol version 2 do not send "feature",\r
1190 xboard uses a timeout mechanism: when it first starts your engine, it\r
1191 sends "xboard" and "protover N", then listens for feature commands for\r
1192 two seconds before sending any other commands.  To end this timeout\r
1193 and avoid the wait, set the feature "done=1" at the end of your last\r
1194 feature command.  To increase the timeout, if needed, set the feature\r
1195 "done=0" before your first feature command and "done=1" at the end.\r
1196 If needed, it is okay for your engine to set done=0 soon as it starts,\r
1197 even before it receives the xboard and protover commands.  This can be\r
1198 useful if your engine takes a long time to initialize itself.  It\r
1199 should be harmless even if you are talking to a (version 1) user\r
1200 interface that does not understand the "feature" command, since such\r
1201 interfaces generally ignore commands from the engine that they do not\r
1202 understand.\r
1203 </p>\r
1204 \r
1205 <p>\r
1206 The feature command is designed to let the protocol change without\r
1207 breaking engines that were written for older protocol versions.  When\r
1208 a new feature is added to the protocol, its default value is always\r
1209 chosen to be compatible with older versions of the protocol that did\r
1210 not have the feature.  Any feature that your engine does not set in a\r
1211 "feature" command retains its default value, so as the protocol\r
1212 changes, you do not have to change your engine to keep up with it\r
1213 unless you want to take advantage of a new feature.  Because some\r
1214 features are improvements to the protocol, while others are meant to\r
1215 cater to engines that do not implement all the protocol features, the\r
1216 recommended setting for a feature is not always the same as the\r
1217 default setting.  The listing below gives both default and recommended\r
1218 settings for most features.\r
1219 </p>\r
1220 \r
1221 <p>\r
1222 You may want to code your engine so as to be able to work with\r
1223 multiple versions of the engine protocol.  Protocol version 1 does not\r
1224 send the protover command and does not implement the feature command;\r
1225 if you send a feature command in protocol version 1, it will have no\r
1226 effect and there will be no response.  In protocol version 2 or later,\r
1227 each feature F that you set generates the response "accepted F" if the\r
1228 feature is implemented, or "rejected F" if it is not.  Thus an engine\r
1229 author can request any feature without having to keep track of which\r
1230 protocol version it was introduced in; you need only check whether the\r
1231 feature is accepted or rejected.  This mechanism also makes it\r
1232 possible for a user interface author to implement a subset of a\r
1233 protocol version by rejecting some features that are defined in that\r
1234 version; however, you should realize that engine authors are likely to\r
1235 code for xboard and may not be prepared to have a feature that they\r
1236 depend on be rejected.\r
1237 <span class="version44">If the GUI rejects an option feature because of the\r
1238 syntax of the value, it should print the value string with the\r
1239 "rejected" command, e.g. "rejected option nonsense" in response\r
1240 to receiving feature option="nonsense".</span>\r
1241 </p>\r
1242 \r
1243 <p>\r
1244 Here are the features that are currently defined.\r
1245 </p>\r
1246 \r
1247 <dl>\r
1248 <dt class="version1">ping (boolean, default 0, recommended 1)</dt>\r
1249 <dd class="version1">\r
1250 If ping=1, xboard may use the protocol's new "ping" command;\r
1251 if ping=0, xboard will not use the command.\r
1252 </dd>\r
1253 \r
1254 <dt class="version1">setboard (boolean, default 0, recommended 1)</dt>\r
1255 <dd class="version1">\r
1256 If setboard=1, xboard will use the protocol's new "setboard" command\r
1257 to set up positions; if setboard=0, it will use the older "edit" command.\r
1258 </dd>\r
1259 \r
1260 <dt class="version1">playother (boolean, default 0, recommended 1)</dt>\r
1261 <dd class="version1">\r
1262 If playother=1, xboard will use the protocol's new "playother" command\r
1263 when appropriate; if playother=0, it will not use the command.\r
1264 </dd>\r
1265 \r
1266 <dt class="version1">san (boolean, default 0)</dt>\r
1267 <dd class="version1">\r
1268 If san=1, xboard will send moves to the engine in standard algebraic\r
1269 notation (SAN); for example, Nf3.  If san=0, xboard will send moves in\r
1270 coordinate notation; for example, g1f3.  See MOVE in \r
1271 <a href="#8">section 8</a> above for more details of both kinds of notation.\r
1272 </dd>\r
1273 \r
1274 <dt class="version1">usermove (boolean, default 0)</dt>\r
1275 <dd class="version1">\r
1276 If usermove=1, xboard will send moves to the engine with the\r
1277 command "usermove MOVE"; if usermove=0, xboard will send just the move,\r
1278 with no command name.\r
1279 </dd>\r
1280 \r
1281 <dt class="version1">time (boolean, default 1, recommended 1)</dt>\r
1282 <dd class="version1">\r
1283 If time=1, xboard will send the "time" and "otim" commands to\r
1284 update the engine's clocks; if time=0, it will not.\r
1285 </dd>\r
1286 \r
1287 <dt class="version1">draw (boolean, default 1, recommended 1)</dt>\r
1288 <dd class="version1">\r
1289 If draw=1, xboard will send the "draw" command if the engine's opponent\r
1290 offers a draw; if draw=0, xboard will not inform the engine about\r
1291 draw offers.  Note that if draw=1, you may receive a draw offer while you\r
1292 are on move; if this will cause you to move immediately, you should set\r
1293 draw=0.\r
1294 </dd>\r
1295 \r
1296 <dt class="version1">sigint (boolean, default 1)</dt>\r
1297 <dd class="version1">\r
1298 If sigint=1, xboard may send SIGINT (the interrupt signal) to\r
1299 the engine as <a href="#7">section 7</a> above; if sigint=0, it will\r
1300 not.\r
1301 </dd>\r
1302 \r
1303 <dt class="version1">sigterm (boolean, default 1)</dt>\r
1304 <dd class="version1">\r
1305 If sigterm=1, xboard may send SIGTERM (the termination signal) to\r
1306 the engine as <a href="#7">section 7</a> above; if sigterm=0, it will\r
1307 not.\r
1308 </dd>\r
1309 \r
1310 <dt class="version1">reuse (boolean, default 1, recommended 1) </dt>\r
1311 <dd class="version1">\r
1312 If reuse=1, xboard may reuse your engine for multiple games.  If\r
1313 reuse=0 (or if the user has set the -xreuse option on xboard's command\r
1314 line), xboard will kill the engine process after every game and start\r
1315 a fresh process for the next game.\r
1316 </dd>\r
1317 \r
1318 <dt class="version1">analyze (boolean, default 1, recommended 1)</dt>\r
1319 <dd class="version1">\r
1320 If analyze=0, xboard will not try to use the "analyze" command; it\r
1321 will pop up an error message if the user asks for analysis mode.  If\r
1322 analyze=1, xboard will try to use the command if the user asks for\r
1323 analysis mode.\r
1324 </dd>\r
1325 \r
1326 <dt class="version1">myname (string, default determined from engine filename)</dt>\r
1327 <dd class="version1">\r
1328 This feature lets you set the name that xboard will use for your\r
1329 engine in window banners, in the PGN tags of saved game files, and when\r
1330 sending the "name" command to another engine.\r
1331 </dd>\r
1332 \r
1333 <dt class="version1">variants (string, see text below)</dt>\r
1334 <dd><span class="version1">\r
1335 This feature indicates which chess variants your engine accepts.\r
1336 It should be a comma-separated list of variant names.  See the table\r
1337 under the "variant" command in <a href="#8">section 8</a> above.  If\r
1338 you do not set this feature, xboard will assume by default that your\r
1339 engine supports all variants.  (However, the -zippyVariants\r
1340 command-line option still limits which variants will be accepted in\r
1341 Zippy mode.)  It is recommended that you set this feature to the\r
1342 correct value for your engine (just "normal" in most cases) rather\r
1343 than leaving the default in place, so that the user will get an\r
1344 appropriate error message if he tries to play a variant that your\r
1345 engine does not support.</span>\r
1346 <span class="version47">As of XBoard 4.8 a variant name not known to the GUI will be\r
1347 considered an engine-defined variant.\r
1348 The user will be given the opportunity to select such variants,\r
1349 but when this happens, the engine should define its meaning\r
1350 in detail with the aid of a "setup" command defined below,\r
1351 in order to avoid an error.</span>\r
1352 <br />\r
1353 <span class="version43">If your engine can play variants on a deviating board size,\r
1354 like capablanca on an 8x8 board, or capablanca crazyhouse,\r
1355 it can list them amongst the variants with a prefix specifying board size plus\r
1356 holdings size, like 8x8+0_capablanca or 10x8+7_capablanca.\r
1357 If it is capable of playing any variant with an arbitrary board size,\r
1358 it should list "boardsize" as one of the variants.\r
1359 If there is a maximum to the board size, this can be prefixed,\r
1360 e.g. "12x10+0_boardsize".\r
1361 </span>\r
1362 </dd>\r
1363 \r
1364 <dt class="version1">colors (boolean, default 1, recommended 0) </dt>\r
1365 <dd><span class="version1">\r
1366 If colors=1, xboard uses the obsolete "white" and "black"\r
1367 commands in a stylized way that works with most older chess engines\r
1368 that require the commands.  See the "<a href="#13">Idioms</a>" section\r
1369 below for details.  If colors=0, xboard does not use the "white" and\r
1370 "black" commands at all.\r
1371 </span>\r
1372 </dd>\r
1373 \r
1374 <dt class="version1">ics (boolean, default 0)</dt>\r
1375 <dd class="version1">\r
1376 If ics=1, xboard will use the protocol's new "ics" command\r
1377 to inform the engine of whether or not it is playing on a chess server;\r
1378 if ics=0, it will not.\r
1379 </dd>\r
1380 \r
1381 <dt class="version1">name (boolean, see text below)</dt>\r
1382 <dd class="version1">\r
1383 If name=1, xboard will use the protocol's "name" command\r
1384 to inform the engine of the opponent's name; if name=0, it will not.\r
1385 By default, name=1 if the engine is playing on a chess server; name=0 if not.\r
1386 </dd>\r
1387 \r
1388 <dt class="version1">pause (boolean, default 0)</dt>\r
1389 <dd class="version1">\r
1390 If pause=1, xboard may use the protocol's new "pause" command;\r
1391 if pause=0, xboard assumes that the engine does not support this command.\r
1392 </dd>\r
1393 \r
1394 <dt class="version43">nps (boolean, default ?)</dt>\r
1395 <dd class="version43">\r
1396 If nps=1, it means the engine supports the nps command.\r
1397 If nps=0, it means the engine does not support it, and WinBoard should refrain from sending it.\r
1398 Default is that WinBoard sends it, in an attempt to try out if the engine understand it.\r
1399 The engine should properly respond with "Error (unkown command): nps" if it does not implement it,\r
1400 (as any protocol version pre-scribes),\r
1401 or WinBoard might assume that the engine did understand the command. \r
1402 In that case the use of different time standards that ensues could lead to time forfeits for the engine.\r
1403 </dd>\r
1404 \r
1405 <dt class="version43">debug (boolean, default 0)</dt>\r
1406 <dd class="version43">\r
1407 If debug=1, it means the engine wants to send debug output prefixed by '#',\r
1408 which WinBoard should ignore, except for including it in the winboard.debug file.\r
1409 As this feature is added to protocol 2 ony late,\r
1410 so that not all protocol-2 supporting versions of WinBoard might implement it,\r
1411 it is important that engines check if WinBoard accepts the feature.\r
1412 If the feature is rejected,\r
1413 engines must refrain from sending the debug output,\r
1414 or do so at their own risk.\r
1415 </dd>\r
1416 \r
1417 <dt class="version44">memory (boolean, default 0)</dt>\r
1418 <dd class="version44">\r
1419 If memory=1, the size of the total amount of memory available for the memory-consuming tables of the engine \r
1420 (e.g. hash, EGTB cache)\r
1421 will be set by the GUI through the "memory" command.\r
1422 </dd>\r
1423 \r
1424 <dt class="version44">smp (boolean, default 0)</dt>\r
1425 <dd class="version44">\r
1426 If smp=1, the GUI will send the "cores" command to the engine to inform it how many CPU cores it can use.\r
1427 Note that sending smp=1 does not imply the engine can use more than one CPU;\r
1428 just that it wants to receive the "cores" command.\r
1429 </dd>\r
1430 \r
1431 <dt class="version44">egt (string, see text below)</dt>\r
1432 <dd class="version44">\r
1433 This feature indicates which end-game table formats the engine supports.\r
1434 It should be a comma-separated list of format names.\r
1435 See under the "egtpath" command in <a href="#8">section 8</a> above.\r
1436 If you do not set this feature, xboard will assume the engine does not support end-game tables,\r
1437 and will not send any "egtpath" commands to inform the engine about their whereabouts.\r
1438 </dd>\r
1439 \r
1440 <dt class="version44">option (string, see text below)</dt>\r
1441 <dd><span class="version44">\r
1442 This feature is used by the engine to define an option command to appear in a GUI menu,\r
1443 so that the user can change the corresponding setting of the engine through the GUI interactively.\r
1444 The string describes the option by defining a name, type, current value and (sometimes) the acceptable value range.\r
1445 Unlike other features, option features are accumulated by the GUI, \r
1446 and the GUI must be able to add a new option to the list at any time,\r
1447 even after having received feature done=1.\r
1448 There are ten different options types, each requiring a slighly different syntax of the defining string:\r
1449 <br />\r
1450 feature option="NAME -button"\r
1451 <br />\r
1452 feature option="NAME -save"\r
1453 <br />\r
1454 feature option="NAME -reset"\r
1455 <br />\r
1456 feature option="NAME -check VALUE"\r
1457 <br />\r
1458 feature option="NAME -string VALUE"\r
1459 <br />\r
1460 feature option="NAME -spin VALUE MIN MAX"\r
1461 <br />\r
1462 feature option="NAME -combo CHOICE1 /// CHOICE2 ..."\r
1463 <br />\r
1464 feature option="NAME -slider VALUE MIN MAX"\r
1465 <br />\r
1466 feature option="NAME -file VALUE"\r
1467 <br />\r
1468 feature option="NAME -path VALUE"\r
1469 <br />\r
1470 NAME is an arbitrary alphanumeric string which can contain spaces; \r
1471 the other words in capitals would be replaced by the current (default) setting of the option,\r
1472 (a character string for -string options, a decimal number for -spin and -check options,\r
1473 were the latter uses 1=checked, 0=unchecked),\r
1474 the minimum or maximum value of numeric (-spin) options, \r
1475 or arbitrary text labels (for -combo option).\r
1476 In the latter case, the current value will be preceded by an asterisk.\r
1477 The -file and -path options are similar to -string, but can be used to inform the GUI that\r
1478 the text represents a file name or folder name respectively, \r
1479 so the GUI dialog could add the appropriate browse button to the text-edit field.\r
1480 Similarly, a -slider option is like a -spin, but the GUI might make a different\r
1481 graphical representation for it.\r
1482 A -save option is like a -button, and defines an immediate command to be sent by the engine.\r
1483 With -save the GUI will make sure all current option settings are flushed to the engine\r
1484 before it sends this command.\r
1485 A -reset option is like a -button, but use of it purges the list of options before sending \r
1486 the corresponding option command to the engine.\r
1487 This enables the engine to completely redefine its options or their current settings,\r
1488 by sending a new set of option feature commands to the GUI, \r
1489 terminated by feature done=1.\r
1490 (The effect of sending an option feature for an option with the same name as was defined before, \r
1491 without first receiving a -reset option command, is undefined.)\r
1492 </span>\r
1493 \r
1494 <dt class="version47">exclude (boolean, default 0)</dt>\r
1495 <dd class="version47">\r
1496 If exclude=1 the GUI can send "exclude" and "include" commands to control which moves\r
1497 from the root position should be searched.\r
1498 </dd>\r
1499 </dd>\r
1500 \r
1501 <dt class="version47">setscore (boolean, default 0)</dt>\r
1502 <dd class="version47">\r
1503 If setscore=1 the GUI can send "setscore" commands to define the score of the current position.\r
1504 </dd>\r
1505 </dd>\r
1506 \r
1507 <dt class="version1">done (integer, no default)</dt>\r
1508 <dd><span class="version1">\r
1509 If you set done=1 during the initial two-second timeout after\r
1510 xboard sends you the "xboard" command, the\r
1511 timeout will end and xboard will not look for any more feature\r
1512 commands before starting normal operation.\r
1513 If you set done=0, the initial timeout is increased to one hour;\r
1514 in this case, you must set done=1 before xboard will enter normal operation.\r
1515 </span>\r
1516 </dd>\r
1517 </dl>\r
1518 </dd>\r
1519 \r
1520 <dt>setup FEN</dt>\r
1521 <dt>setup (PIECETOCHAR) FEN</dt>\r
1522 <dt>setup (PIECETOCHAR) WxH+S_PARENTVARIANT FEN</dt>\r
1523 <dd>The engine can optionally send a setup command to the GUI in reply\r
1524 to the variant command.\r
1525 In the simplest form this sends the FEN of the initial position.\r
1526 This can be used to implement engines for non-standard variants\r
1527 that only differ from standard variants through the initial position.\r
1528 (E.g. many of the 'wild' boards you can play on an ICS.)\r
1529 Whether the GUI should obey or ignore this command depends on the situation.\r
1530 Normally it would ignore it in variants where it knows the standard initial position\r
1531 and legality testing is on, or when the user specified an initial position.\r
1532 In other cases it will use the FEN sent by the first engine\r
1533 for setting up the initial position, as if it was an externally supplied position.\r
1534 Such a position will always be sent to a second engine that might be involved,\r
1535 and any setup commands received from the latter will always be ignored.\r
1536 (This to allow for shuffle games, where the two engines might pick different setups.)\r
1537 When no initial position is known, such as for 'catch-all' variants like fairy,\r
1538 or whenever the board width is overruled to a non-standard value,\r
1539 the FEN will be used as default initial position even when legality testing is on.\r
1540 </dd>\r
1541 <dd>Optionally the meaning of the piece ID letters in the FEN can be defined\r
1542 between parentheses; this will be interpreted as if it was the value of a\r
1543 -pieceToCharTable command-line option, mapping letters to GUI piece types.\r
1544 Also optionally behind that, the setup command can specify board width W,\r
1545 board height H and holdings size S, as well as a 'parent variant'.\r
1546 This is typically done in response to a variant command with a non-standard name,\r
1547 about which the GUI is not supposed to know anything at all.\r
1548 The engine can then specify board size, participating pieces, initial setup,\r
1549 and other rule details (inherited from the parent variant),\r
1550 saving the user the trouble to configure the GUI for this non-standard variant.\r
1551 Example:\r
1552 <pre>\r
1553   setup (PN.RQKpn.rqk) 6x6+0_fairy rnqknr/pppppp/6/6/PPPPPP/RNQKNR w - - 0 1\r
1554 </pre>\r
1555 could be used by an engine for Los-Alamos Chess in response to 'variant losalamos',\r
1556 and would automatically switch the GUI to this variant as soon as the user\r
1557 selected it from the GUI menu.\r
1558 The PIECETOCHAR element would ensure a Bishop would not be accepted as promotion choice. \r
1559 </dd>\r
1560 \r
1561 <dt>Illegal move: MOVE</dt>\r
1562 <dt>Illegal move (REASON): MOVE</dt>\r
1563 <dd>If your engine receives a MOVE command that is recognizably a move\r
1564 but is not legal in the current position, your engine must print an\r
1565 error message in one of the above formats so that xboard can pass the\r
1566 error on to the user and retract the move.  The (REASON) is entirely\r
1567 optional.  Examples:\r
1568 \r
1569 <pre>\r
1570   Illegal move: e2e4\r
1571   Illegal move (in check): Nf3\r
1572   Illegal move (moving into check): e1g1\r
1573 </pre>\r
1574 <p>\r
1575 Generally, xboard will never send an ambiguous move, so it does not \r
1576 matter whether you respond to such a move with an Illegal move message \r
1577 or an Error message.\r
1578 </p>\r
1579 </dd>\r
1580 \r
1581 <dt>Error (ERRORTYPE): COMMAND</dt>\r
1582 <dd>If your engine receives a command it does not understand or does\r
1583 not implement, it should print an error message in the above format so\r
1584 that xboard can parse it.  Examples:\r
1585 <pre>\r
1586   Error (ambiguous move): Nf3\r
1587   Error (unknown command): analyze\r
1588   Error (command not legal now): undo\r
1589   Error (too many parameters): level 1 2 3 4 5 6 7\r
1590 </pre>\r
1591 </dd>\r
1592 \r
1593 <dt>move MOVE</dt>\r
1594 <dd>Your engine is making the move MOVE.  Do not echo moves from\r
1595 xboard with this command; send only new moves made by the engine.\r
1596 \r
1597 <div class="version1">\r
1598 <p>For the actual move text from your chess engine (in place of MOVE\r
1599 above), your move should be either</p>\r
1600 <ul>\r
1601 <li>in coordinate notation (e.g.,\r
1602 e2e4, e7e8q) with castling indicated by the King's two-square move (e.g.,\r
1603 e1g1), or</li>\r
1604 <li>in Standard Algebraic Notation (SAN) as defined in the\r
1605 Portable Game Notation standard (e.g, e4, Nf3, O-O, cxb5, Nxe4, e8=Q),\r
1606 with the extension piece@square (e.g., P@f7) to handle piece placement\r
1607 in bughouse and crazyhouse.</li>\r
1608 </ul>\r
1609 <p>\r
1610 xboard itself also accepts some variants of SAN, but for compatibility\r
1611 with non-xboard interfaces, it is best not to rely on this behavior.\r
1612 </p>\r
1613 \r
1614 <p>Warning: Even though all versions of this protocol specification\r
1615 have indicated that xboard accepts SAN moves, some non-xboard\r
1616 interfaces are known to accept only coordinate notation.  See the\r
1617 Idioms section for more information on the known limitations of some\r
1618 non-xboard interfaces.  It should be safe to send SAN moves if you\r
1619 receive a "protover 2" (or later) command from the interface, but\r
1620 otherwise it is best to stick to coordinate notation for maximum\r
1621 compatibility.  An even more conservative approach would be for your\r
1622 engine to send SAN to the interface only if you have set feature san=1\r
1623 (which causes the interface to send SAN to you) and have received\r
1624 "accepted san" in reply.\r
1625 </p>\r
1626 </div>\r
1627 </dd>\r
1628 \r
1629 <dt>RESULT {COMMENT}</dt>\r
1630 <dd>When your engine detects\r
1631 that the game has ended by rule, your engine must output a line of the\r
1632 form "RESULT {comment}" (without the quotes), where RESULT is a PGN\r
1633 result code (1-0, 0-1, or 1/2-1/2), and comment is the reason.  Here\r
1634 "by rule" means that the game is definitely over because of what\r
1635 happened on the board.  In normal chess, this includes checkmate,\r
1636 stalemate, triple repetition, the 50 move rule, or insufficient\r
1637 material; it does not include loss on time or the like.\r
1638 Examples:\r
1639 <pre>\r
1640   0-1 {Black mates}\r
1641   1-0 {White mates}\r
1642   1/2-1/2 {Draw by repetition}\r
1643   1/2-1/2 {Stalemate}\r
1644 </pre>\r
1645 \r
1646 <p>\r
1647 xboard relays the result to the user, the ICS, the other engine in Two\r
1648 Machines mode, and the PGN save file as required.\r
1649 <span class="version43">Note that "definitey over" above means that sending this command \r
1650 will be taken by WinBoard as an unconditional refusal of the engine to play on,\r
1651 which might cause you to forfeit if the game was in fact not over.\r
1652 This command should thus not be used to offer draws, accept draws,\r
1653 or make draw-by-rule claims that are not yet valid in the current position\r
1654 (but will be after you move).\r
1655 For offering and claiming such draws, "offer draw" should be used.</span>\r
1656 </p>\r
1657 \r
1658 <p class="version44">\r
1659 Note that (in accordance with FIDE rules) only KK, KNK, KBK and KBKB with all bishops on the\r
1660 same color can be claimed as draws on the basis of insufficient mating material.\r
1661 The end-games KNNK, KBKN, KNKN and KBKB with unlike bishops do have mate positions,\r
1662 and cannot be claimed.\r
1663 Complex draws based on locked Pawn chains will not be recognized as draws by most interfaces,\r
1664 so do not claim in such positions, but just offer a draw or play on.\r
1665 </p>\r
1666 \r
1667 <p class="version44">\r
1668 Note to GUI programmers: RESULT commands that the engine sends immediately after its move\r
1669 might be detected by the GUI only after the opponent has moved, because of communication\r
1670 and scheduling delays, no matter how fast the engine sent it.\r
1671 Any judgement of the validity of RESULT claims based on te "current" board position\r
1672 will have to account for this uncertainty.\r
1673 </p>\r
1674 </dd>\r
1675 \r
1676 <dt>resign</dt>\r
1677 <dd>If your engine wants to resign, it can send the command "resign".\r
1678 Alternatively, it can use the "RESULT {comment}" command if the string\r
1679 "resign" is included in the comment; for example "0-1 {White\r
1680 resigns}".  xboard relays the resignation to the user, the ICS, the\r
1681 other engine in Two Machines mode, and the PGN save file as required.\r
1682 <span class="version44">Note that many interfaces work more smoothly if you resign <em>before</em>\r
1683 you move.</span>\r
1684 </dd>\r
1685 \r
1686 <dt>offer draw</dt>\r
1687 <dd>If your engine wants to offer a draw by agreement (as opposed to\r
1688 claiming a draw by rule), it can send the command "offer draw".\r
1689 xboard relays the offer to the user, the ICS, the other engine in Two\r
1690 Machines mode, and the PGN save file as required.  In Machine White,\r
1691 Machine Black, or Two Machines mode, the offer is considered valid\r
1692 until your engine has made two more moves.\r
1693 <span class="version43">This command must also be used to accept a draw offer.\r
1694 Do not use the 1/2-1/2 command for that, as the offer might be no longer valid,\r
1695 in which case a refusal to play on implied by the RESULT command might make you forfeit the game.\r
1696 "offer draw" should also be used to claim 50-move and 3-fold-repetition draws\r
1697 that will occur <em>after</em> your move, by sending it <em>before</em> making the move.\r
1698 WinBoard will grant draw offers without the opponent having any say in\r
1699 it in situations where draws can be claimed.\r
1700 Only if the draw cannot be claimed, the offer will be passed to your opponent after you make your next move,\r
1701 just before WinBoard relays this move to the opponent.\r
1702 </span>\r
1703 </dd>\r
1704 \r
1705 <dt class="version1">tellopponent MESSAGE</dt>\r
1706 <dd class="version1">\r
1707 This command lets the engine give a message to its opponent,\r
1708 independent of whether the opponent is a user on the local machine or\r
1709 a remote ICS user (Zippy mode).  MESSAGE consists of any characters,\r
1710 including whitespace, to the end of the line.  When the engine is\r
1711 playing against a user on the local machine, xboard pops up an\r
1712 information dialog containing the message.  When the engine is playing\r
1713 against an opponent on the ICS (Zippy mode), xboard sends "say\r
1714 MESSAGE\n" to the ICS.\r
1715 </dd>\r
1716 \r
1717 <dt class="version1">tellothers MESSAGE </dt>\r
1718 <dd class="version1">This command lets the engine give a message to people watching the\r
1719 game other than the engine's opponent.  MESSAGE consists of any\r
1720 characters, including whitespace, to the end of the line.  When the\r
1721 engine is playing against a user on the local machine, this command\r
1722 does nothing.  When the engine is playing against an opponent on the\r
1723 ICS (Zippy mode), xboard sends "whisper MESSAGE\n" to the ICS.\r
1724 </dd>\r
1725 \r
1726 <dt class="version1">tellall MESSAGE</dt>\r
1727 <dd class="version1">This command lets the engine give a message to its opponent and\r
1728 other people watching the game, \r
1729 independent of whether the opponent is a user on the local machine or\r
1730 a remote ICS user (Zippy mode).  MESSAGE consists of any characters,\r
1731 including whitespace, to the end of the line.  When the engine is\r
1732 playing against a user on the local machine, xboard pops up an\r
1733 information dialog containing the message.  When the engine is playing\r
1734 against an opponent on the ICS (Zippy mode), xboard sends "kibitz\r
1735 MESSAGE\n" to the ICS.\r
1736 </dd>\r
1737 \r
1738 <dt>telluser MESSAGE</dt>\r
1739 <dd>xboard pops up an information dialog containing the message.\r
1740 MESSAGE consists of any characters, including whitespace, to the end\r
1741 of the line.\r
1742 </dd>\r
1743 \r
1744 <dt>tellusererror MESSAGE</dt>\r
1745 <dd>xboard pops up an error dialog containing the message.\r
1746 MESSAGE consists of any characters, including whitespace, to the end\r
1747 of the line.\r
1748 </dd>\r
1749 \r
1750 <dt>askuser REPTAG MESSAGE</dt>\r
1751 <dd>Here REPTAG is a string containing no whitespace, and MESSAGE\r
1752 consists of any characters, including whitespace, to the end of the\r
1753 line.  xboard pops up a question dialog that says MESSAGE and\r
1754 has a typein box.  If the user types in "bar", xboard sends "REPTAG\r
1755 bar" to the engine.  The user can cancel the dialog and send nothing.\r
1756 </dd>\r
1757 \r
1758 <dt>tellics MESSAGE</dt>\r
1759 <dd>In Zippy mode, xboard sends "MESSAGE\n" to ICS.  MESSAGE consists\r
1760 of any characters, including whitespace, to the end of the line.\r
1761 </dd>\r
1762 \r
1763 <dt class="version1">tellicsnoalias MESSAGE</dt>\r
1764 <dd class="version1">\r
1765 In Zippy mode, xboard sends "xMESSAGE\n" to ICS, where "x" is a\r
1766 character that prevents the ICS from expanding command aliases, if\r
1767 xboard knows of such a character.  (On chessclub.com and chess.net,\r
1768 "/" is used; on freechess.org, "$" is used.)  MESSAGE consists of any\r
1769 characters, including whitespace, to the end of the line.\r
1770 </dd>\r
1771 \r
1772 <dt class="version43"># COMMENT</dt>\r
1773 <dd class="version43">\r
1774 The engine can send any string of printable characters, terminated by a newline,\r
1775 for inclusion in the winboard.debug file, provided the line starts with a '#' character.\r
1776 If the engine has set feature debug=1,\r
1777 it is guaranteed that WinBoard (and any future version of it) will completely ignore\r
1778 these lines in any other respect.\r
1779 </dd>\r
1780 </dl>\r
1781 \r
1782 <h2><a name="10">10. Thinking Output</a></h2>\r
1783 \r
1784 <p>\r
1785 If the user asks your engine to "show thinking", xboard sends your\r
1786 engine the "post" command.  It sends "nopost" to turn thinking off.\r
1787 In post mode, your engine sends output lines to show the progress of\r
1788 its thinking.  The engine can send as many or few of these lines as it\r
1789 wants to, whenever it wants to.  Typically they would be sent when the\r
1790 PV (principal variation) changes or the depth changes.  The thinking\r
1791 output should be in the following format:\r
1792 </p>\r
1793 \r
1794 <pre>ply score time nodes pv</pre>\r
1795 \r
1796 <p>Where:</p>\r
1797 <table>\r
1798 <tr><td>ply</td><td>Integer giving current search depth.</td></tr>\r
1799 <tr><td>score</td><td>Integer giving current evaluation in centipawns.</td></tr>\r
1800 <tr><td>time</td><td>Current search time in centiseconds (ex:1028 = 10.28 seconds).</td></tr>\r
1801 <tr><td>nodes</td><td>Nodes searched.</td></tr>\r
1802 <tr><td>*selective depth</td><td>Maximium length of any branch in the current search.</td></tr>\r
1803 <tr><td>*speed</td><td>Nodes per second in last measured time interval.</td></tr>\r
1804 <tr><td>*</td><td>Reserved for future extensions.</td></tr>\r
1805 <tr><td>*tbhits</td><td>Number of tablebase probes made in the current search.</td></tr>\r
1806 <tr><td>pv</td><td>Freeform text giving current "best" line.\r
1807 You can continue the pv onto another line if you start each\r
1808 continuation line with at least four space characters.</td></tr>\r
1809 </table>\r
1810 \r
1811 <p class="version47">\r
1812 The items marked with * are optional.\r
1813 If any of these items is present, the <b>pv</b> field must be preceeded directly by a tab character;\r
1814 if no tab character preceeds the first non-integer token,\r
1815 the <b>pv</b> field will start at the first non-blank character after <b>nodes</b>.\r
1816 Otherwise it will start after the last tab that is not behind any non-integer token.\r
1817 Of all integers between <b>nodes</b> and <b>pv</b> the last one is intepreted as <b>tbhits</b>.\r
1818 Of any remaining ones the first is interpreted as <b>selective depth</b>,\r
1819 and a second as <b>speed</b>.\r
1820 More infos could be added to this in the future.\r
1821 Note that older interfaces might consider the optional infos to be part of the <b>pv</b> field,\r
1822 and display them exactly as sent.\r
1823 It is therefore encouraged that engines use tabs or spaces to format this optional info\r
1824 so that it will display nicely in (not too wide) columns.\r
1825 </p>\r
1826 \r
1827 <p>\r
1828 Example:\r
1829 </p>\r
1830 \r
1831 <pre>  9 156 1084 48000 Nf3 Nc6 Nc3 Nf6</pre>\r
1832 \r
1833 <p>\r
1834 Meaning:\r
1835 </p>\r
1836 \r
1837 <pre>\r
1838 9 ply, score=1.56, time = 10.84 seconds, nodes=48000, PV = "Nf3 Nc6 Nc3 Nf6"\r
1839 </pre>\r
1840 \r
1841 <p>\r
1842 Longer example from actual Crafty output:\r
1843 </p>\r
1844 \r
1845 <pre>\r
1846   4    109      14   1435  1. e4 d5 2. Qf3 dxe4 3. Qxe4 Nc6\r
1847   4    116      23   2252  1. Nf3 Nc6 2. e4 e6\r
1848   4    116      27   2589  1. Nf3 Nc6 2. e4 e6\r
1849   5    141      44   4539  1. Nf3 Nc6 2. O-O e5 3. e4\r
1850   5    141      54   5568  1. Nf3 Nc6 2. O-O e5 3. e4\r
1851 </pre>\r
1852 \r
1853 <p>\r
1854 You can use the PV to show other things; for instance, while in book,\r
1855 Crafty shows the observed frequency of different reply moves in its\r
1856 book.  In situations like this where your engine is not really\r
1857 searching, start the PV with a '(' character:\r
1858 </p>\r
1859 \r
1860 <pre>\r
1861   0      0       0      0  (e4 64%, d4 24%)\r
1862 </pre>\r
1863 \r
1864 <p>\r
1865 GNU Chess output is very slightly different.  The ply number is\r
1866 followed by an extra nonblank character, and the time is in seconds,\r
1867 not hundredths of seconds.  For compatibility, xboard accepts the\r
1868 extra character and takes it as a flag indicating the different time\r
1869 units.  Example:\r
1870 </p>\r
1871 \r
1872 <pre>\r
1873  2.     14    0       38   d1d2  e8e7 \r
1874  3+     78    0       65   d1d2  e8e7  d2d3 \r
1875  3&amp;     14    0       89   d1d2  e8e7  d2d3 \r
1876  3&amp;     76    0      191   d1e2  e8e7  e2e3 \r
1877  3.     76    0      215   d1e2  e8e7  e2e3 \r
1878  4&amp;     15    0      366   d1e2  e8e7  e2e3  e7e6 \r
1879  4.     15    0      515   d1e2  e8e7  e2e3  e7e6 \r
1880  5+     74    0      702   d1e2  f7f5  e2e3  e8e7  e3f4 \r
1881  5&amp;     71    0     1085   d1e2  e8e7  e2e3  e7e6  e3f4 \r
1882  5.     71    0     1669   d1e2  e8e7  e2e3  e7e6  e3f4 \r
1883  6&amp;     48    0     3035   d1e2  e8e7  e2e3  e7e6  e3e4  f7f5  e4d4 \r
1884  6.     48    0     3720   d1e2  e8e7  e2e3  e7e6  e3e4  f7f5  e4d4 \r
1885  7&amp;     48    0     6381   d1e2  e8e7  e2e3  e7e6  e3e4  f7f5  e4d4 \r
1886  7.     48    0    10056   d1e2  e8e7  e2e3  e7e6  e3e4  f7f5  e4d4 \r
1887  8&amp;     66    1    20536   d1e2  e8e7  e2e3  e7e6  e3d4  g7g5  a2a4  f7f5 \r
1888  8.     66    1    24387   d1e2  e8e7  e2e3  e7e6  e3d4  g7g5  a2a4  f7f5 \r
1889  9&amp;     62    2    38886   d1e2  e8e7  e2e3  e7e6  e3d4  h7h5  a2a4  h5h4 \r
1890                            d4e4 \r
1891  9.     62    4    72578   d1e2  e8e7  e2e3  e7e6  e3d4  h7h5  a2a4  h5h4 \r
1892                            d4e4 \r
1893 10&amp;     34    7   135944   d1e2  e8e7  e2e3  e7e6  e3d4  h7h5  c2c4  h5h4 \r
1894                            d4e4  f7f5  e4f4 \r
1895 10.     34    9   173474   d1e2  e8e7  e2e3  e7e6  e3d4  h7h5  c2c4  h5h4 \r
1896                            d4e4  f7f5  e4f4 \r
1897 </pre>\r
1898 \r
1899 <p>If your engine is pondering (thinking on its opponent's time) in post\r
1900 mode, it can show its thinking then too.  In this case your engine may\r
1901 omit the hint move (the move it is assuming its opponent will make)\r
1902 from the thinking lines <em>if and only if</em> it sends xboard the move in\r
1903 the usual "Hint: xxx" format before sending the first line.\r
1904 </p>\r
1905 \r
1906 <h2><a name="11">11. Time control</a></h2>\r
1907 \r
1908 <p>\r
1909 xboard supports three styles of time control: conventional chess clocks,\r
1910 the ICS-style incremental clock, and an exact number of seconds per move.\r
1911 </p>\r
1912 \r
1913 <p>In conventional clock mode, every time control period is the same.\r
1914 That is, if the time control is 40 moves in 5 minutes, then after each\r
1915 side has made 40 moves, they each get an additional 5 minutes, and so\r
1916 on, ad infinitum.  At some future time it would be nice to support a\r
1917 series of distinct time controls.  This is very low on my personal\r
1918 priority list, but code donations to the xboard project are accepted,\r
1919 so feel free to take a swing at it.  I suggest you talk to me first,\r
1920 though.\r
1921 </p>\r
1922 \r
1923 <p>\r
1924 The command to set a conventional time control looks like this:\r
1925 </p>\r
1926 \r
1927 <pre>\r
1928   level 40 5 0\r
1929   level 40 0:30 0\r
1930 </pre>\r
1931 \r
1932 <p>\r
1933 The 40 means that there are 40 moves per time control.  The 5 means\r
1934 there are 5 minutes in the control.  In the second example, the 0:30\r
1935 means there are 30 seconds.  The final 0 means that we are in\r
1936 conventional clock mode.\r
1937 </p>\r
1938 \r
1939 <p class="version43">\r
1940 Note that the time parameter in this command is not a pure numeric argument,\r
1941 but in general is a character string, in order to pass the number of seconds.\r
1942 Engines are encouraged to ignore any unexpected characters at the end of this string,\r
1943 i.e. following the MIN or MIN:SEC specification.\r
1944 Future protocol versions might (under control of an appropriate feature)\r
1945 append such extra characters to this argument,\r
1946 in order to inform the engine in advance of the time control it can expect after the current session completes.\r
1947 E.g. "level 40 25+5 0" could mean that the engine has to play 40 moves in 25 minutes,\r
1948 but should expect to get only 5 minutes for the entire remainder of the game after that,\r
1949 rather than another 25 minutes for the next 40 moves.\r
1950 When the time comes, (i.e. after the 40 moves), \r
1951 it will be informed of the time-control change by receiving a new "level 0 5 0" command,\r
1952 but engines with advanced time management might want to plan for this in advance.\r
1953 </p>\r
1954 \r
1955 <p>\r
1956 The command to set an incremental time control looks like this:\r
1957 </p>\r
1958 \r
1959 <pre>\r
1960   level 0 2 12\r
1961 </pre>\r
1962 \r
1963 <p>\r
1964 Here the 0 means "play the whole game in this time control period",\r
1965 the 2 means "base=2 minutes", and the 12 means "inc=12 seconds".  As\r
1966 in conventional clock mode, the second argument to level can be in\r
1967 minutes and seconds.\r
1968 </p>\r
1969 \r
1970 <p>\r
1971 At the start of the game, each player's clock is set to base minutes.\r
1972 Immediately after a player makes a move, inc seconds are added to his\r
1973 clock.  A player's clock counts down while it is his turn.  Your flag\r
1974 can be called whenever your clock is zero or negative.  (Your clock\r
1975 can go negative and then become positive again because of the\r
1976 increment.)\r
1977 </p>\r
1978 \r
1979 <p class="version44">\r
1980 The number of moves given in the level command (when non-zero) should \r
1981 be taken as the number of moves still to do before the specified time\r
1982 will be added to the clock, if the "level" command is received after\r
1983 some moves have already been played.\r
1984 The time given should be interpreted as the time left on its clock\r
1985 (including any time left over from the previous sessions),\r
1986 and not necessarily the time that will be added to the clock\r
1987 after the specified number of moves has been played.\r
1988 This is only relevant in WinBoard 4.3.xx, which might send the engine\r
1989 "level" commands during a game,\r
1990 just before the engine has to start thinking about the first move of \r
1991 a new time-control session.\r
1992 Example: if at the start of the game "level 40 60 0" was given \r
1993 (40 moves per hour),\r
1994 and the engine receives "level 20 22 0" just before move 41,\r
1995 it should understand that it should do the next 20 moves in 22 minutes\r
1996 (pehaps because the secondary session was 20 moves per 15 minutes,\r
1997 and it had 7 minutes left on its clock after the first 40 moves).\r
1998 </p>\r
1999 \r
2000 <p>\r
2001 A special rule on some ICS implementations: if you ask for a game with\r
2002 base=0, the clocks really start at 10 seconds instead of 0.  xboard\r
2003 itself does not know about this rule, so it passes the 0 on to the\r
2004 engine instead of changing it to 0:10.\r
2005 </p>\r
2006 \r
2007 <p>\r
2008 ICS also has time odds games.  With time odds, each player has his own\r
2009 (base, inc) pair, but otherwise things work the same as in normal\r
2010 games.  The Zippy xboard accepts time odds games but ignores the fact\r
2011 that the opponent's parameters are different; this is perhaps not\r
2012 quite the right thing to do, but gnuchess doesn't understand time\r
2013 odds.  Time odds games are always unrated.\r
2014 </p>\r
2015 \r
2016 <p>\r
2017 The command to set an exact number of seconds per move looks like this:\r
2018 </p>\r
2019 \r
2020 <pre>\r
2021   st 30\r
2022 </pre>\r
2023 \r
2024 <p>\r
2025 This means that each move must be made in at most 30 seconds.  Time not used\r
2026 on one move does not accumulate for use on later moves.\r
2027 </p>\r
2028 \r
2029 <h2><a name="12">12. Analyze Mode</a></h2>\r
2030 \r
2031 <p>xboard supports analyzing fresh games, edited positions, and games\r
2032 from files.  However, all of these look the same from the chess\r
2033 engine's perspective. Basically, the engine just has to respond to the\r
2034 "analyze" command.  \r
2035 <span class="version1">\r
2036 Beginning in protocol version 2,\r
2037 if your engine does not support analyze mode, it should use\r
2038 the feature command to set analyze=0.  \r
2039 </span>\r
2040 The older method of\r
2041 printing the error message "Error (unknown command): analyze" in\r
2042 response to the "analyze" command will also work, however.\r
2043 </p>\r
2044 \r
2045 <p>\r
2046 To enter analyze mode, xboard sends the command sequence "post", "analyze".  \r
2047 Analyze mode in your engine should be\r
2048 similar to force mode, except that your engine thinks about what move\r
2049 it would make next if it were on move.  Your engine should accept the\r
2050 following commands while in analyze mode:\r
2051 </p>\r
2052 \r
2053 <ul>\r
2054 <li>Any legal move, as in force mode</li>\r
2055 <li><strong>undo</strong>&nbsp;&nbsp; Back up one move and analyze previous position.</li>\r
2056 <li><strong>new</strong>&nbsp;&nbsp; Reset position to start of game but stay in analyze mode.</li>\r
2057 <li><span class="version1"><strong>setboard</strong> if you have set feature setboard=1; otherwise <strong>edit</strong>.  Exiting edit mode returns to analyze mode.</span></li>\r
2058 <li><strong>exit</strong>&nbsp;&nbsp; Leave analyze mode.</li>\r
2059 <li><strong>.</strong>&nbsp;&nbsp; Send a search status update (optional); see below.</li>\r
2060 <li><span class="version1">\r
2061 <strong>bk</strong>&nbsp;&nbsp; Show book moves from this position,\r
2062 if any; see above.</span></li>\r
2063 <li><span class="version1">\r
2064 <strong>hint</strong>&nbsp;&nbsp; Show the predicted move from this\r
2065 position, if any; see above.</span></li>\r
2066 </ul>\r
2067   \r
2068 <p>\r
2069 If the user selects "Periodic Updates", xboard will send the string\r
2070 ".\n" to the chess engine periodically during analyze mode, unless the\r
2071 last PV received began with a '(' character.\r
2072 </p>\r
2073 \r
2074 <p>\r
2075 The chess engine should respond to ".\n" with a line like this:\r
2076 </p>\r
2077 \r
2078 <pre>\r
2079 stat01: time nodes ply mvleft mvtot <span class="version1">mvname</span>\r
2080 </pre>\r
2081 \r
2082 <p>Where:</p>\r
2083 <table>\r
2084 <tr><td>time</td><td>Elapsed search time in centiseconds (ie: 567 = 5.67 seconds).</td></tr>\r
2085 <tr><td>nodes</td><td>Nodes searched so far.</td></tr>\r
2086 <tr><td>ply</td><td>Search depth so far.</td></tr>\r
2087 <tr><td>mvleft</td><td>Number of moves left to consider at this depth.</td></tr>\r
2088 <tr><td>mvtot</td><td>Total number of moves to consider.</td></tr>\r
2089 <tr class="version1"><td>mvname</td><td>Move currently being considered (SAN or coordinate notation).  Optional;\r
2090 added in protocol version 2.</td></tr>\r
2091 </table>\r
2092 \r
2093 <p>\r
2094 Examples:\r
2095 </p>\r
2096 <pre>\r
2097   stat01: 1234 30000 7 5 30\r
2098   stat01: 1234 30000 7 5 30 Nf3\r
2099 </pre>\r
2100 \r
2101 <p>\r
2102 Meaning:\r
2103 </p>\r
2104 \r
2105 <p>After 12.34 seconds, I've searched 7 ply/30000 nodes, there are a\r
2106   total of 30 legal moves, and I have 5 more moves to search\r
2107   before going to depth 8.  In the second example, of the 30 legal\r
2108   moves, the one I am currently searching is Nf3.</p>\r
2109 \r
2110 <p>\r
2111 Implementation of the "." command is optional. If the engine does not\r
2112 respond to the "." command with a "stat01..." line, xboard will stop\r
2113 sending "."  commands.  If the engine does not implement this command,\r
2114 the analysis window will use a shortened format to display the engine\r
2115 info.\r
2116 </p>\r
2117 \r
2118 <p>\r
2119 To give the user some extra information, the chess engine can output\r
2120 the strings "++\n" and "--\n", to indicate that the current search is\r
2121 failing high or low, respectively.  You don't have to send anything\r
2122 else to say "Okay, I'm not failing high/low anymore."  xboard will\r
2123 figure this out itself.\r
2124 </p>\r
2125 \r
2126 <h2><a name="13">13. Idioms and backward compatibility features</a></h2>\r
2127 \r
2128 <p>\r
2129 Some engines have variant interpretations of the force/go/white/black,\r
2130 time/otim, and hard/easy command sets.  \r
2131 In order to accommodate these older engines, xboard uses these commands\r
2132 only according to the stylized patterns ("idioms") given in this section.\r
2133 The obsolete white and black commands\r
2134 have historically been particularly troublesome, and it is recommended\r
2135 that new engines set the feature colors=0 and/or ignore the commands.\r
2136 </p>\r
2137 \r
2138 <dl>\r
2139 \r
2140 <dt>time N</dt>\r
2141 <dt>otim N</dt>\r
2142 <dt>MOVE</dt>\r
2143 <dd>Sent when the opponent makes a move and the engine is already\r
2144 playing the opposite color.\r
2145 </dd>\r
2146 <dt>white</dt>\r
2147 <dt>go</dt>\r
2148 <dd>Sent when the engine is in force mode or playing Black but should\r
2149 switch to playing White.  This sequence is sent only when White is\r
2150 already on move.  \r
2151 <span class="version1">\r
2152 If you set the feature colors=0, "white" is not sent.\r
2153 </span>\r
2154 </dd>\r
2155 \r
2156 <dt>black</dt>\r
2157 <dt>go</dt>\r
2158 <dd>Sent when the engine is in force mode or playing White but should\r
2159 switch to playing Black.  This sequence is sent only when Black is\r
2160 already on move.  \r
2161 <span class="version1">\r
2162 If you set the feature colors=0, "black" is not sent.\r
2163 </span>\r
2164 </dd>\r
2165 \r
2166 <dt>white</dt>\r
2167 <dt>time N</dt>\r
2168 <dt>otim N</dt>\r
2169 <dt>black</dt>\r
2170 <dt>go</dt>\r
2171 <dd>Sent when Black is on move, the engine is in force mode or playing\r
2172 White, and the engine's clock needs to be updated before it starts\r
2173 playing.  \r
2174 The initial "white" is a kludge to accommodate GNU Chess\r
2175 4's variant interpretation of these commands.  \r
2176 <span class="version1">\r
2177 If you set the feature colors=0, "white" and "black" are not sent.\r
2178 </span>\r
2179 </dd>\r
2180 \r
2181 <dt>black</dt>\r
2182 <dt>time N</dt>\r
2183 <dt>otim N</dt>\r
2184 <dt>white</dt>\r
2185 <dt>go</dt>\r
2186 <dd>Sent when White is on move, the engine is in force mode or playing\r
2187 Black, and the engine's clock needs to be updated before it starts\r
2188 playing.  See previous idiom.  \r
2189 The initial "black" is a kludge to accommodate GNU Chess\r
2190 4's variant interpretation of these commands.  \r
2191 <span class="version1">\r
2192 If you set the feature colors=0, "black" and "white" are not sent.\r
2193 </span>\r
2194 </dd>\r
2195 \r
2196 <dt>hard</dt>\r
2197 <dt>easy</dt>\r
2198 <dd>Sent in sequence to turn off pondering if xboard is not sure\r
2199 whether it is on.  When xboard is sure, it will send "hard" or "easy"\r
2200 alone.  xboard does this because "easy" is a toggle in GNU Chess 4 but\r
2201 "hard" is an absolute on.\r
2202 </dd>\r
2203 </dl>\r
2204 \r
2205 <p>\r
2206 To support older engines, certain additional commands from the engine\r
2207 to xboard are also recognized.  (These are commands by themselves, not\r
2208 values to be placed in the comment field of the PGN result code.)\r
2209 These forms are not recommended for new engines; use the PGN result\r
2210 code commands or the resign command instead.\r
2211 </p>\r
2212 \r
2213 <table>\r
2214 <tr><th>Command</th>              <th>Interpreted as</th></tr>\r
2215 <tr><td>White resigns        </td><td>0-1 {White resigns}</td></tr>\r
2216 <tr><td>Black resigns        </td><td>1-0 {Black resigns}</td></tr>\r
2217 <tr><td>White                </td><td>1-0 {White mates}</td></tr>\r
2218 <tr><td>Black                </td><td>0-1 {Black mates}</td></tr>\r
2219 <tr><td>Draw                 </td><td>1/2-1/2 {Draw}</td></tr>\r
2220 <tr><td>computer mates       </td><td>1-0 {White mates} or 0-1 {Black mates}</td></tr>\r
2221 <tr><td>opponent mates       </td><td>1-0 {White mates} or 0-1 {Black mates}</td></tr>\r
2222 <tr><td>computer resigns     </td><td>0-1 {White resigns} or 1-0 {Black resigns}</td></tr>\r
2223 <tr><td>game is a draw       </td><td>1/2-1/2 {Draw}</td></tr>\r
2224 <tr><td>checkmate            </td><td>1-0 {White mates} or 0-1 {Black mates}</td></tr>\r
2225 </table>\r
2226 \r
2227 <p>\r
2228 Commands in the above table are recognized if they begin a line and\r
2229 arbitrary characters follow, so (for example) "White mates" will be\r
2230 recognized as "White", and "game is a draw by the 50 move rule" will\r
2231 be recognized as "game is a draw".  All the commands are\r
2232 case-sensitive.\r
2233 </p>\r
2234 \r
2235 <p>\r
2236 An alternative move syntax is also recognized:\r
2237 </p>\r
2238 \r
2239 <table>\r
2240 <tr><th>Command              </th><th>Interpreted as</th></tr>\r
2241 <tr><td>NUMBER ... MOVE      </td><td>move MOVE</td></tr>\r
2242 </table>\r
2243 \r
2244 <p>\r
2245 Here NUMBER means any string of decimal digits, optionally ending in a\r
2246 period.  MOVE is any string containing no whitespace.  In this command\r
2247 format, xboard requires the "..." even if your engine is playing\r
2248 White.  A command of the form NUMBER MOVE will be ignored.  This odd\r
2249 treatment of the commands is needed for compatibility with gnuchessx.\r
2250 The original reasons for it are lost in the mists of time, but I\r
2251 suspect it was originally a bug in the earliest versions of xboard,\r
2252 before I started working on it, which someone "fixed" in the wrong\r
2253 way, by creating a special version of gnuchess (gnuchessx) instead of\r
2254 changing xboard.\r
2255 </p>\r
2256 \r
2257 <p>\r
2258 Any line that contains the words "offer" and "draw" is recognized as\r
2259 "offer draw".\r
2260 </p>\r
2261 \r
2262 <p>\r
2263 The "Illegal move" message is recognized even if spelled "illegal\r
2264 move" and even if the colon (":") is omitted.  This accommodates GNU\r
2265 Chess 4, which prints messages like "Illegal move (no matching\r
2266 move)e2e4", and old versions of Crafty, which print just "illegal move".\r
2267 </p>\r
2268 \r
2269 <p>\r
2270 In Zippy mode, for compatibility with older versions of Crafty,\r
2271 xboard passes through to ICS any line that begins "kibitz", "whisper",\r
2272 "tell", or "draw".  Do not use this feature in new code.  Instead, use the\r
2273 commands "tellall", "tellothers", "tellopponent", "tellics" (if needed),\r
2274 "1/2-1/2 {COMMENT}", or "offer draw", as appropriate.\r
2275 </p>\r
2276 \r
2277 <p class="version1">\r
2278 If the engine responds to the "sd DEPTH" command with an error message\r
2279 indicating the command is not supported (such as "Illegal move: sd"),\r
2280 xboard sets an internal flag and subsequently uses the command\r
2281 "depth\nDEPTH" instead, for the benefit of GNU Chess 4.  Note the\r
2282 newline in the middle of this command!  New engines should not rely on\r
2283 this feature.\r
2284 </p>\r
2285 \r
2286 <p class="version1">\r
2287 If the engine responds to the "st TIME" command with an error message\r
2288 indicating the command is not supported (such as "Illegal move: st"),\r
2289 xboard sets an internal flag and subsequently uses the command "level\r
2290 1 TIME" instead, for the benefit of GNU Chess 4.  Note that this is\r
2291 not a standard use of the level command, as TIME seconds are not added\r
2292 after each player makes 1 move; rather, each move is made in at most\r
2293 TIME seconds.  New engines should not implement or rely on this\r
2294 feature.\r
2295 </p>\r
2296 \r
2297 <div class="version1">\r
2298 <p>\r
2299 In support of the -firstHost/-secondHost features, which allow a chess\r
2300 engine to be run on another machine using the rsh protocol, xboard recognizes\r
2301 error messages that are likely to come from rsh as fatal errors.  The following\r
2302 messages are currently recognized:\r
2303 </p>\r
2304 \r
2305 <ul>\r
2306 <li>unknown host</li>\r
2307 <li>No remote directory</li>\r
2308 <li>not found</li>\r
2309 <li>No such file</li>\r
2310 <li>can't alloc</li>\r
2311 <li>Permission denied</li>\r
2312 </ul>\r
2313 </div>\r
2314 \r
2315 <p class="version1">\r
2316 ChessBase/Fritz now implements the xboard/winboard protocol and can use\r
2317 WinBoard-compatible engines in its GUI.  ChessBase's version of the\r
2318 protocol is generally the same as version 1, except that they have\r
2319 added the commands <strong>fritz</strong>, <strong>reset</strong>, and\r
2320 <strong>ponder</strong>, and the edit subcommands\r
2321 <strong>castle</strong> and <strong>ep</strong>.  If you want your\r
2322 engine to work well with the ChessBase/Fritz GUI, you may need to\r
2323 implement these additional commands, and you should also be aware of\r
2324 the peculiar way that ChessBase uses the protocol.  See their <a\r
2325 href="http://www.chessbase.com/Products/engines/winboard/tech.htm"\r
2326 >web page</a> for documentation.\r
2327 </p>\r
2328 \r
2329 <p class="version1">\r
2330 ChessMaster 8000 also implements version 1 of the xboard/winboard\r
2331 protocol and can use WinBoard-compatible engines.  The original\r
2332 release of CM8000 also has one additional restriction: only pure\r
2333 coordinate notation (e.g., e2e4) is accepted in the move command.  A\r
2334 patch to correct this should be available from The Learning Company\r
2335 (makers of CM8000) in February 2001.\r
2336 </p>\r
2337 \r
2338 </body>\r
2339 </html>\r