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