version 1.4.46b
[polyglot.git] / polyglot.pod
1 =head1 NAME
2
3 PolyGlot -  Winboard protocol to UCI protocol adapter
4          -  book engine for Polyglot books 
5          -  a collection of utilities for creating and analyzing opening books
6          -  a utility for analyzing epd files
7          -  a perft counter
8
9 =head1 SYNOPSIS
10
11 polyglot [configfile] [-noini] [-ec engine] [-ed enginedirectory] [-en enginename] [-log] [-lf logfile] [-hash value] [-bk book] [-pg <name>=<value>]* [-uci <name>=<value>]*
12
13 polyglot make-book [-pgn inputfile] [-bin outputfile] [-max-ply ply] [-min-game games] [-min-score score] [-only-white] [-only-black] [-uniform]
14
15 polyglot merge-book -in1 inputfile1 -in2 inputfile2 [-out outputfile]
16
17 polyglot info-book [-bin inputfile] [-exact]
18
19 polyglot dump-book [-bin inputfile] -color color [-out outputfile]
20
21 polyglot [configfile] epd-test [engineoptions] [-epd inputfile] [-min-depth depth] [-max-depth depth] [-max-time time] [-depth-delta delta] 
22
23 polyglot perft [-fen fen] [-max-depth depth]
24
25 =head1 DESCRIPTION
26
27 =head2 PolyGlot as adapter and book engine
28
29 PolyGlot is a "UCI adapter".  It connects a GUI interface (such as
30 XBoard, Winboard, Arena or Chessbase) to a UCI chess engine.
31
32 By specifying an opening book (in PolyGlot book format) chess engines can
33 transparently use such books.
34
35 PolyGlot understands the two main GUI protocols: UCI and
36 xboard. Normally the protocol will be auto detected but this can be
37 overridden in the configuration file.
38
39 In xboard mode PolyGlot fully translates between the xboard and UCI protocols.
40 In addition it tries to solve known problems with other adapters.
41 For instance, it detects and reports draws by fifty-move rule,
42 repetition, etc ... It also supports Chess960.
43
44 When in UCI mode PolyGlot mostly passes commands from the GUI
45 to the engine and vice versa, except that it will play book moves on
46 behalf of the engine when the occasion arises.
47
48 The engine options are exported as UCI options in UCI
49 mode and as "feature option=" commands in xboard mode. The latter form
50 an extension of the xboard protocol as defined by H.G. Muller.
51
52 Options which normally appear in the [PolyGlot] section of the
53 config file (see below) are exported as options with their name prefixed
54 by "Polyglot". This makes it easy to filter them in the GUI.
55
56 NOTE: Not all options are exported, only those that make sense in the
57 given mode.
58
59 =head2 Book making utilities
60
61 PolyGlot supports the "PolyGlot opening book format". This is the
62 defacto standard non-proprietary opening book format. It is fully documented
63 here
64
65 http://alpha.uhasselt.be/Research/Algebra/Toga/book_format.html
66
67 Roughly speaking a PolyGlot opening book is a collection of triples
68 (position, move, weight). A "position" is represented by a 64-bit
69 Zobrist hash key. The weight is proportional to the probability the move should
70 be played. 
71
72 Other opening book formats such as ChessBase's .ctg format and Arena's
73 .abk format are undocumented and proprietary. They can only be used 
74 by their own GUIs. 
75
76 PolyGlot can compile a pgn file into a binary PolyGlot book and furthermore
77 it can merge two such binary books into a third one.
78
79 PolyGlot can also extract some useful information from PolyGlot books. The utility
80 "dump-book" dumps the "lines" in a book for a given color. By definition
81 a line is a sequence of moves (from the starting position) in which
82 the given color makes only book moves and the other color makes 
83 arbitrary moves (i.e. not necessarily book moves).
84
85 Since a PolyGlot book is built up from positions and not lines there
86 may be (and there usually are) many positions in the book that are not
87 on a "line" as defined in the previous paragraph. It is convenient
88 to call such positions "isolated" positions. The utility "info-book"
89 counts such isolated positions.
90
91 Some of the isolated positions are provably unreachable and they
92 could in principle be deleted from the book. For example if a book
93 contains only the move "e4" in the starting position but also the
94 position after "d4 d5" then this last position is provably unreachable
95 since it requires white to make a non-book move when a book move is
96 available. Such situations arise frequently from the priority rules
97 in merging books.
98
99 Unfortunately not all isolated positions are provably unreachable and
100 it is difficult to identify the latter. If invoked with "-exact" the
101 utility info-book will attempt to count the isolated positions which
102 require a player to make a non-book move when a book move is available.
103 Due to the possibility of transpositions this is not a fool proof method.
104
105 =head2 Epd test mode
106
107 In epd test mode, PolyGlot will search positions in an epd file and
108 record the number of times the right best move was found.  The
109 arguments specify when to stop the search in any given position.
110
111 =head2 Perft counts
112
113 A perft count is the number of legal move sequence in a given position
114 up to a given depth. PolyGlot can perform such perft counts. It
115 is however much slower than other more dedicated programs.
116
117 =head1 OPTIONS
118
119 When PolyGlot is invoked as an adapter of in epd-test mode it gets its
120 options from a config file and then from the command line.  The
121 default config file is "polyglot.ini" but an alternative one may be
122 optionally included as first argument. The config file format is
123 described below.
124
125 The following engine options may be specified on the command line.
126
127 =over 4
128     
129 =item B<-noini> 
130
131 Do not use a config file, even if one was specified on the command line.
132
133 =item B<-pg>
134
135 The argument is a string of the form <name>=<value>. This option will
136 set the Polyglot option <name> to <value>. 
137
138 =item B<-uci>
139
140 The argument is a string of the form <name>=<value>. This option will
141 set the engine option <name> to <value>. 
142
143 =item B<-ec> 
144
145 This sets the EngineCommand.
146
147 =item B<-ed>
148
149 This sets the EngineDir.
150
151 =item B<-en>
152
153 This sets the EngineName.
154
155 =item B<-hash>
156
157 This is an alias for -uci "Hash=<value>".
158
159 =item B<-log>
160
161 This is an alias for -pg "Log=true".
162
163 =item B<-lf> (default: "polyglot.log")
164
165 This is an alias for -pg "LogFile=<value>".
166
167 =item B<-bk> 
168
169 This is an alias for -pg "Book=true" -pg "BookFile=<value>".
170
171 =back
172
173 When invoked as
174
175 =head2 polyglot make-book
176
177 PolyGlot supports the following options
178
179 =over 4
180
181 =item B<-pgn> (default: "book.pgn")
182
183 Input file in pgn format. 
184
185 =item B<-bin> (default: "book.bin")
186
187 Output file in PolyGlot format. 
188
189 =item B<-max-ply> (default: 1024)
190
191 Specifies the maximum ply-depth of lines included in the book.
192
193 =item B<-min-game> (default: 3)
194
195 Specifies the minimum number of games that have to contain this move for it to be included in the book.
196
197 =item B<-min-score> (default: 0.0)
198
199 Specifies the minimum score (or weight) this move should have received for 
200 it to  be included in the book. The score is 2*(wins)+(draws), globally scaled
201 to fit into 16 bits. 
202
203 =item B<-only-white>
204
205 Include only moves for white in the book.
206
207 =item B<-only-black>
208     
209 Include only moves for black in the book.
210
211 =item B<-uniform>
212     
213 Set all weights to 1. In other words, all moves will be selected with 
214 equal probability. 
215
216 =back
217
218 When invoked
219 as
220
221 =head2 polyglot merge-book
222
223 PolyGlot supports the following options
224
225 =over 4
226
227 =item B<-in1>
228     
229 First input file (in PolyGlot book format).
230
231 =item B<-in2>
232     
233 Second input file (in PolyGlot book format).
234
235 =item B<-out> (default: out.bin)
236     
237 Output file (in PolyGlot book format).
238
239 =back
240
241 Input files are not symmetrical, "in1" has priority over "in2". In other
242 words when a position occurs both in "in1" and "in2" only the
243 moves and weights from "in1" will be retained in "out".
244
245 When invoked
246 as
247
248 =head2 polyglot dump-book
249
250 PolyGlot supports the following options
251
252 =over 4
253
254 =item B<-bin> (default: book.bin)
255
256 Input file in PolyGlot book format.
257
258 =item B<-color> 
259
260 The color for whom to generate the lines.
261
262 =item B<-out> (default: book_<color>.txt)
263
264 The name of the output file.
265
266 =back
267
268 When invoked
269 as
270
271 =head2 polyglot info-book
272
273 PolyGlot supports the following options
274
275 =over 4
276
277 =item B<-bin> (default: book.bin)
278
279 Input file in PolyGlot book format.
280
281 =item B<-exact> 
282
283 Attempt to count the provably unreachable positions among the isolated ones.
284 Note that this takes a very long time. 
285
286 =back
287
288 When invoked as
289
290 =head2 polyglot epd-test
291
292 (possibly with a config file as first argument) PolyGlot supports
293 besides the generic options described above the following additional
294 options.
295
296 =over 4
297
298 =item B<-max-depth> (default: 63)
299
300 Unconditionally stop the search when this depth has
301 been reached.
302
303 =item B<-max-time> (default: 5.0)
304
305 Unconditionally stop the seach after this amount of time.
306
307 =item B<-depth-delta> (default: 3)
308
309 Stop the search if the solution as been found and the best move has
310 been constant for this many depths, on condition that the mininal
311 depth and minimal time have been reached.
312
313 =item B<-min-depth> (default: 8)
314
315 Minimal search depth when the search is stopped using "-depth-delta".
316
317 =item B<-min-time> (default: 1.0)
318
319 Minimal search time when the search is stopped using "-depth-delta".
320
321
322 =back
323
324 When invoked as
325
326 =head2 polyglot perft
327
328 PolyGlot supports the following
329 options
330
331 =over 4
332
333 =item B<-fen> (default: starting position) 
334
335 Fen at which to start searching.
336
337 =item B<-max-depth> (default: 1) 
338
339 Maximum depth to search.
340
341 =back
342
343 =head1 CONFIG FILE FORMAT
344
345 There should be a different config file for each engine.  
346
347 The config file is in the traditional INI format.  
348
349     [PolyGLot]
350     option = value
351     ...
352     [Engine]
353     option = value
354     ...
355
356 The characters "#" and ";" serve as comment characters. 
357
358 By default initial and final white space is stripped from option
359 values. If you want to avoid this, or if you want use one of
360 the comment characters # or ; in option values (such as for NalimovPath), 
361 enclose the value in quotes.
362
363 =head2 [PolyGlot] section
364
365 This section is used by PolyGlot only.  The engine is unaware of these
366 options.  The list of available options is detailed below.
367
368 =over 4
369
370 =item B<EngineName> (default: UCI name)
371
372 This is the name that will appear in the GUI.  It is
373 cosmetic only.  You can use different names for tweaked versions of
374 the same engine.
375
376 =item B<EngineDir> (default: ".")
377
378 Full path of the directory where the engine is installed.  You can use
379 "." (without the quotes) if you know that PolyGlot will be launched in
380 the engine directory or the engine is in the "path" and does not need
381 any data file.
382
383 =item B<EngineCommand>
384
385 Put here the name of the engine executable file.  You can also add
386 command-line arguments.  Path searching is used and the current
387 directory will be "EngineDir".
388
389 =item B<Log> (default: false)
390
391 Whether PolyGlot should log all transactions with the interface and
392 the engine.  This should be necessary only to locate problems.
393
394 =item B<LogFile> (default: polyglot.log)
395
396 The name of the log file.  Note that it is put where PolyGlot was
397 launched from, not into the engine directory.
398
399 WARNING: Log files are not cleared between sessions, and can become
400 very large.  It is safe to remove them though.
401
402 =item B<Resign> (default: false)
403
404 Set this to "true" if you want PolyGlot to resign on behalf of the
405 engine.
406
407 NOTE: Some engines display buggy scores from time to time although the
408 best move is correct.  Use this option only if you know what you are
409 doing (e.g. you always check the final position of games).
410
411 =item B<ResignMoves> (default: 3)
412
413 Number of consecutive moves with "resign" score (see below) before
414 PolyGlot resigns for the engine.  Positions with only one legal move
415 are ignored.
416
417 =item B<ResignScore> (default: 600)
418
419 This is the score in centipawns that will trigger resign "counting".
420
421 =item B<ShowPonder> (default: true)
422
423 Show search information during engine pondering.  Turning this off
424 might be better for interactive use in some interfaces.
425
426 =item B<ScoreWhite> (default: true)
427
428 Report score from white's point of view in xboard mode.
429
430 =item B<KibitzMove> (default: false)
431
432 Whether to kibitz when playing a move.
433
434 =item B<KibitzPV> (default: false)
435
436 Whether to kibitz when the PV is changed (new iteration or new best move).
437
438 =item B<KibitzCommand> (default: "tellall")
439
440 xboard command to use for kibitzing, normally "tellall" for kibitzing
441 or "tellothers" for whispering.
442
443 =item B<KibitzDelay> (default: 5)
444
445 How many seconds to wait before starting kibitzing.  This has an
446 effect only if "KibitzPV" is selected, move kibitzes are always sent
447 regardless of the delay.
448
449 =item B<KibitzInterval> (default: 0)
450
451 This is another form of throttling. PolyGlot will usually wait this
452 many seconds before doing the next kibitz. 
453
454 =item B<UCI> (default: false)
455
456 If true PolyGlot will not understand xboard commands. 
457
458 =item B<MateScore> (default: 10000)
459
460 Mate score reported to GUI when in xboard mode.
461
462 =item B<Book> (default: false)
463
464 Indicates whether a PolyGlot book should be used.  This has no effect
465 on the engine own book (which can be controlled with the UCI option
466 "OwnBook" in the [Engine] section).  In particular, it is possible to
467 use both a PolyGlot book and an engine book.  In that case, the engine
468 book will be used whenever PolyGlot is out of book.  Remember that
469 PolyGlot is unaware of whether the engine is itself using a book or
470 not.
471
472 =item B<BookFile> (default: book.bin)
473
474 The name of the (binary) book file.  Note that PolyGlot will look for
475 it in the directory it was launched from, not in the engine directory.
476 Of course, full path can be used in which case the current directory
477 does not matter.
478
479 =item B<BookRandom> (default: true)
480
481 Select moves according to their weights in the book. If false the move
482 with the highest weight is selected. 
483
484 =item B<BookLearn> (default: false)
485
486 Store learning information in the book (which must be writable). Currently
487 no engine actually uses this information. 
488
489 =item B<BookDepth> (default: 256)
490
491 Stop using the book after this number of moves. 
492
493 =item B<BookTreshold> (default: 5)
494
495 Do not play moves with a weight (probability) lower than this (in per mil). 
496
497 =item B<UseNice> (default: false)
498
499 Run the engine at nice level 5, or "NiceValue" if it set.  On some
500 operating systems it may be necessary to run the engine at lower
501 priority for it to be responsive to commands from PolyGlot while
502 searching.
503
504 =item B<NiceValue> (default: 5)
505
506 Nice levels go from -20 to 20 with 20 being the lowest priority.
507 On Unix only root can set negative nice levels. On Windows the standard
508 Win32 priority levels are mapped in a sensible way to Unix nice levels.
509
510
511 =item B<Affinity> (default: -1)
512
513 This a bit vector in which each bit represents the processors that a
514 process is allowed to run on. This option works only on Windows. 
515
516 =item B<Persist> (default: true)
517
518 If true then PolyGlot will implement persistence by loading options
519 from an additional INI file whose name is by default derived from the
520 engine name. At exit PolyGlot will also save its options to this INI
521 file.
522
523 =item B<PersistFile> (default: <EngineName>.ini)
524
525 The name of the file from which to take the additional options.  It is
526 probably best to stick with the default. You can safely edit this
527 file, or delete it to restore the default options.
528
529 =item B<PersistDir> (default: $HOME/.polyglot on Linux; ".\Polyglot Settings" on Windows)
530
531 The directory where the PersistFile is stored.
532
533 =back
534
535 =head2 Work arounds 
536
537 Work arounds are identical to options except that they should be used
538 only when necessary.  Their purpose is to try to hide problems with
539 various software (not just engines).  
540
541 IMPORTANT: Any of these work arounds might be removed in future
542 versions of PolyGlot.  You are strongly recommended to contact the
543 author of faulty software and truly fix the problem.
544
545 PolyGlot supports the following work arounds:
546
547 =over 4
548
549 =item B<UCIVersion> (default: 2)
550
551 The default value of 2 corresponds to UCI+.  Use 1 to select plain
552 UCI for engines that have problems with UCI+.
553
554 =item B<CanPonder> (default: false)
555
556 PolyGlot now conforms to the documented UCI behaviour: the engine will
557 be allowed to ponder only if it (the engine) declares the "Ponder" UCI
558 option.  However some engines which can actually ponder do not declare
559 the option.  This work around lets PolyGlot know that they can ponder.
560
561 =item B<SyncStop> (default: false)
562
563 When a ponder miss occurs, Polyglot interrupts the engine and
564 IMMEDIATELY launches a new search.  While there should be no problem
565 with this, some engines seem confused and corrupt their search board.
566 "SyncStop" forces PolyGlot to wait for the (now useless) ponder search
567 to finish before launching the new search.
568
569 =item B<PromoteWorkAround> (default: false)
570
571 Some engines do not specify a promotion piece, e.g. they send "e7e8"
572 instead of the correct "e7e8q".  This work around enables the
573 incorrect form (and of course promotes into a queen).
574
575 =item B<RepeatPV> (default: true)
576
577 When true, PolyGlot repeats the last pv string (which also contains
578 score,depth and time usage) it got from the engine. Some engines
579 however do not send a new pv string just before sending the move.
580 In that case the output of PolyGlot would be inconsistent. 
581 When RepeatPV is false PolyGlot does not repeat the last pv string.
582 Due to the way kibitzing is implemented, KibitzMove is disabled in that case. 
583
584 =item B<WbWorkArounds> (default: true)
585
586 The intention of these options is to provide work arounds for
587 xboard/winboard bugs should they arise.  This one decapitalizes
588 the word Draw in options that contain this word. Some versions of
589 xboard/winboard contain a bug which causes such options to be
590 interpreted as draw claims by the engine.
591
592 Engines that send options with "Draw" in their name are Rybka and HIARCS. 
593
594 =item B<WbWorkArounds2> (default: false)
595
596 Old version of Winboard clear the engine output window at depth 1. With this
597 work around PG will send info lines at depth >=2. This may or may not improve
598 the display. 
599
600 =back
601
602
603 =head2 [Engine] section
604
605 This section contains engine UCI options.  PolyGlot does not
606 understand them, but sends the information to the engine at startup
607 (converted to UCI form).  You can add any UCI option that makes sense
608 to the engine (not just the common options about hash-table size and
609 tablebases).
610
611 NOTE: use INI syntax, not UCI.  For example "OwnBook = true" is
612 correct.  It will be replaced by PolyGlot with "setoption name OwnBook
613 value true" at engine startup.
614
615 Standard UCI options are 
616
617     Hash 
618     NalimovPath
619     NalimovCache
620     OwnBook
621
622 Hidden options like "Ponder" or "UCI_xxx" are automatic
623 and should not be put in an INI file.
624
625 The other options are engine-specific.  Check their name using a UCI
626 GUI or launch the engine in a console and type "uci".
627
628 =head1 EXAMPLES
629
630 Running the UCI engine "fruit" under xboard 4.3.15 and later (this invokes PolyGlot internally).
631
632     xboard -fcp fruit -fUCI
633
634 An explicit command line for using the UCI engine "fruit" with 128M hash in xboard with logging enabled (this also works on xboard 4.2.7).
635
636     xboard -fcp "polyglot -noini -log -ec fruit -hash 128"
637
638 The equivalent config file would be:
639
640     [PolyGlot]
641     EngineCommand = fruit
642     Log = true
643     [Engine]
644     Hash=128
645
646 Compile "games.pgn" into a book "book.bin" retaining all lines of at
647 most 30 plies.
648
649     polyglot make-book -pgn games.pgn -bin book.bin -max-ply 30
650
651 Merge books "w1.bin" and "w2.bin" into a book "w.bin".
652
653     polyglot merge-book -in1 w1.bin -in2 w2.bin -out w.bin
654
655 Inspect lines for white in "w.bin"
656
657     polyglot dump-book -bin w.bin -color white -out w_white.txt
658
659 Test epd file "test.epd" with a (maximum) search time of 7 minutes per position
660
661     polyglot epd-test -epd test.epd -max-time 420
662
663 =head1 EXIT STATUS
664
665 PolyGlot always returns 0 on exit. 
666
667 =head1 AUTHORS
668
669 Main author: Fabien Letouzey<fabien_letouzey(at)hotmail.com>
670
671 Native Windows port:  Huang Chen<webmaster@elephantbase.net> ("Morning Yellow")
672
673 Various enhancements: Fonzy Bleumers<match(at)geenvis.net>
674
675 UCI port, option persistence and new WB protocol: Michel Van den Bergh
676 <michel.vandenbergh(at)uhasselt.be>
677
678
679
680 =head1 SEE ALSO
681
682 xboard(6)