There indeed is a bit of a bug here; the loop that adds the moves of a game to the book terminates one move early, by testing i<forwardMostMove instead of <=. As a result the last (half)move of a game is ignored. In your test-case the second (half)move of each game is also ignored, because these are black moves, and black lost. A Polyglot book only counts the wins.

Normally this does not matter, because with real games it is pointless to put the entire game in the book, as you could only arrive there by reproducing that entire game. Normally only the moves up to Book Depth are considered, and this masks the bug.

As to entering moves already in the book: yes, this could be considered a bit sloppy, but why would one ever do that? And if we want XBoard to flag it, what should be done instead? Refuse the move with an error message? Increase the count of the move by 1? This whole feature is designed for creating books from scratch by hand. (I used it to create my Mini-Shogi book of hand-picked lines). The weight 1 it assigns to the move is almost always not the desired one, so after entering the allowed moves from the position you would in principle correct the weights to the desired value in the book-edit window, and you would spot the duplicat at that point, and delete the line before comitting the window with the new weights.

BTW, having a duplicat would not spoil the move choice compared to incrementing the count of the already present move, in the normal book setting (with Book Variation = 50%). Only when you apply some non-linear transformation to the weights (like playing best-move only, or totally random ignoring the weights) it would matter.

Alan Bennet schreef op 23-10-2025 21:42:
Hi,

"Edit Book" - "add next move" allows to add a move that is already in the list. I think this behavior has negative consequences for move selection. see user session below. A workaround is to manually delete duplicate row(s). There are some other quirks with saving/editing the book but those are for a separate topic.

##   := quirk
#### := issue being reported

--
Alan


$ xboard --version
xboard version 4.9.1

configure options: prefix=/usr; datarootdir=/usr/share; datadir=/usr/share; gamedatadir=/usr/share/games/xboard; desktopdir=/usr/share/applications; mimedir=/usr/share/mime/packages; iconsdir=/usr/share/icons/hicolor/48x48/apps; svgiconsdir=/usr/share/icons/hicolor/scalable/apps; infodir=/usr/share/info; sysconfigdir=; update_mimedb=yes; NLS=yes; GTK=yes; Xaw3d=no; Xaw=no; ptys=pipes; zippy=yes; sigint=yes

$ grep -e "[Pp]olyglot" -e "[Bb]ook" ~/.xboardrc
-saveOutOfBookInfo true
-adapterCommand 'polyglot -noini -ec "%fcp" -ed "%fd" -uci NalimovCache=%defaultCacheSizeEGTB -pg ShowTbHits=true'
-polyglotDir ""
-usePolyglotBook true
-polyglotBook "/home/REDACTED/chesspgbook/book.bin"
-bookDepth 12
-bookVariation 50
-discourageOwnBooks false

$ ls -Gg --time-style=+%Y.%m.%dT%H%M -Gg ~/chesspgbook/
total 1456
-rwxr-xr-x 1 1487264 2023.03.03T1358 Performance.bin

$ cat ~/Documents/tmp/test.pgn
[White "fischer"]
[Result "1-0"]

e4 e5 Nf3 1-0

[White "spassky"]
[Result "1-0"]

d4 Nf6 c4 1-0

[White "kramnik"]
[Result "1-0"]

Nf3 d5 d4 1-0

$ xboard &
[1] 21626

GUI | File | Load Game | Recently Used | test.pgn

GUI | File | Save Games as Book

## success here because 3 games
## but if only 1 game in PGN ,
##   xboard complains "Game list not loaded or empty"

$ ls -Gg --time-style=+%Y.%m.%dT%H%M -Gg ~/chesspgbook/
total 1456
-rw-r--r-- 1       0 2025.10.23T1454 book.bin
-rwxr-xr-x 1 1487264 2023.03.03T1358 Performance.bin

## 0-byte file, xboard does not commit the book until Quit
## at this moment GUI | Edit | Edit Book does nothing

GUI | File | Quit

$ ls -Gg --time-style=+%Y.%m.%dT%H%M -Gg ~/chesspgbook/
total 1460
-rw-r--r-- 1      64 2025.10.23T1456 book.bin
-rwxr-xr-x 1 1487264 2023.03.03T1358 Performance.bin
[1]+  Done                    xboard

$ hexdump -e '1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x " 1/1 "%.02x" 1/1 "%.02x " 1/1 "%.02x" 1/1 "%.02x " 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%02x " "\n"' ~/chesspgbook/book.bin
463b96181691fc9c 031c 0001 00000001
463b96181691fc9c 02db 0001 00000001
463b96181691fc9c 0195 0001 00000001
ffffffffffffffff 0000 0000 00000000

## only 3 moves in the book, should be 9
## i am going to investigate
##   and maybe send another report

$ xboard &
[1] 21795

GUI | Edit | Edit Book

 33.3%     1 e4 {1/0}
 33.3%     1 d4 {1/0}
 33.3%     1 Nf3 {1/0}

GUI | manually edit the weights (1,1,1) to (2,3,4)

 33.3%     2 e4 {1/0}
 33.3%     3 d4 {1/0}
 33.3%     4 Nf3 {1/0}

GUI | commit changes

 22.2%     2 e4 {1/0}
 33.3%     3 d4 {1/0}
 44.4%     4 Nf3 {1/0}

GUI | add next move | c2c4

 22.2%     2 e4 {1/0}
 33.3%     3 d4 {1/0}
 44.4%     4 Nf3 {1/0}
  0.0%     1  c4

GUI | commit changes

 20.0%     2 e4 {1/0}
 30.0%     3 d4 {1/0}
 40.0%     4 Nf3 {1/0}
 10.0%     1 c4

GUI | add next move | d2d4      #### d2d4 already in list

 20.0%     2 e4 {1/0}
 30.0%     3 d4 {1/0}
 40.0%     4 Nf3 {1/0}
 10.0%     1 c4
  0.0%     1  d4

#### i think xboard should give an ERR instead of adding the duplicate

GUI | commit changes

 18.2%     2 e4 {1/0}
 27.3%     3 d4 {1/0}
 36.4%     4 Nf3 {1/0}
  9.1%     1 c4
  9.1%     1 d4

$ hexdump -e '1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x " 1/1 "%.02x" 1/1 "%.02x " 1/1 "%.02x" 1/1 "%.02x " 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%02x " "\n"' ~/chesspgbook/book.bin
463b96181691fc9c 031c 0002 00000001
463b96181691fc9c 02db 0003 00000001
463b96181691fc9c 0195 0004 00000001
463b96181691fc9c 029a 0001 00000000
463b96181691fc9c 02db 0001 00000000
ffffffffffffffff 0000 0000 00000000

GUI | manually delete the row " 9.1% 1 d4 "

## if delete just the weight, xboard does some weird math

 18.2%     2 e4 {1/0}
 27.3%     3 d4 {1/0}
 36.4%     4 Nf3 {1/0}
  9.1%     1 c4

GUI | commit changes

 20.0%     2 e4 {1/0}
 30.0%     3 d4 {1/0}
 40.0%     4 Nf3 {1/0}
 10.0%     1 c4

$ hexdump -ve '1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x " 1/1 "%.02x" 1/1 "%.02x " 1/1 "%.02x" 1/1 "%.02x " 1/1 "%.02x" 1/1 "%.02x" 1/1 "%.02x" 1/1 "%02x " "\n"' ~/chesspgbook/book.bin
463b96181691fc9c 031c 0002 00000001
463b96181691fc9c 02db 0003 00000001
463b96181691fc9c 0195 0004 00000001
463b96181691fc9c 029a 0001 00000000
ffffffffffffffff 0000 0000 00000000
ffffffffffffffff 0000 0000 00000000

GUI | File | Quit

$

Reply via email to