I can reproduce this puzzling behavior. As you aready show in the
hex-dumps, the book is OK. Which means that the features Save Games to
Book and Commit to Book do work properly. The problem appears to be in
the routines that prepare the list of book entries for display in the
Edit Book window.
This happens in a rather roundabout way, because before I implemented
the feature there already existed a routine move_to_string, which
converted the move to long-algebraic format (for sending to the engine
after a book hit). But I wanted the moves in the Edit Book window to
display as SAN. So what I did was read back the long-algebraic move text
to get individual from-square and to-square coordinates, and then call
the existing routine CoordsToAlgebraic to produce the SAN. (Getting
those from the long-algebraic notation was much more straightforward
than getting those from the binary book encoding, which is dependent on
board size due to support of variants.)
But this last step is subject to the condition that extracing the
coordinates from the long-algebraic produced at least 4 coordinates. If
not, it would be skipped, but this would leave any previously converted
move in the move-text buffer. Apparently something goes wrong in
producing and reading back the long algebraic for Rh1 (which should be
e1h1), so that it is printed as Rg1 (which appeared before it).
I will put in some debug printf to see what is going on here... Anyway,
thanks for reporting this.
char *
MovesToText(int count, entry_t *entries)
{
int i, totalWeight = 0;
char algMove[12];
char *p = (char*) malloc(40*count+1);
for(i=0; i<count; i++) totalWeight += entries[i].weight;
*p = 0;
for(i=0; i<count; i++) {
char buf[MSG_SIZ], c1, c2, c3; int i1, i2, i3;
move_to_string(algMove, entries[i].move);
if(sscanf(algMove, "%c%d%*c%*d,%c%d%c%d", &c1, &i1, &c2, &i2, &c3,
&i3) == 6)
snprintf(algMove, 12, "%c%dx%c%d-%c%d", c1, i1, c2, i2, c3, i3); //
cast double-moves in format SAN parser will understand
else if(sscanf(algMove, "%c%d%c%d%c", &c1, &i1, &c2, &i2, &c3) >=
4) {
CoordsToAlgebraic(boards[currentMove], PosFlags(currentMove),
i1-ONE+'0', c1-AAA, i2-ONE+'0', c2-AAA, c3, algMove);
}
buf[0] = NULLCHAR;
if(entries[i].learnCount || entries[i].learnPoints)
snprintf(buf, MSG_SIZ, " {%d/%d}", entries[i].learnPoints,
entries[i].learnCount);
snprintf(p+strlen(p), 40, "%5.1f%% %5d %s%s\n",
100*entries[i].weight/(totalWeight+0.001),
entries[i].weight, algMove, buf);
//lastEntries[i] = entries[i];
}
return p;
}
Alan Bennet schreef op 26-10-2025 07:12:
Hi,
Thanks again for replying. I have a new issue with "add next move", but
first to tidy up the previous email.
On 10/25/25 08:36, h.g.muller" via XBoard and WinBoard bugs wrote:
It would not be so easy to implement adequate error reporting /
warning here.
Okay. I don't _really_ need it, because if I make a mistake I can fix
it.
... Perhaps hand-creating a book is a feature that just should not be
used at 3 am. ;-)
Indeed!
... a PGN with a single game is immediately loaded in the memory
buffer as the current game, but when there are more games in the file
a Game List is created,
Expected behavior then. I can just make sure there is more than one
game.
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
New issue. For the following move list I am having trouble adding the
move 24.Rh1 to the book. It keeps adding 24.Rg1 instead. Or it's doing
something else. Very spooky, just in time for Halloween.
1.e4 d5 2.exd5 Qxd5 3.Nc3 Qa5 4.d4 Nf6 5.Nf3 c6 6.Bd2 Bf5 7.Bc4 e6
8.Qe2 Bb4 9.O-O-O Nbd7 10.a3 Bxc3 11.Bxc3 Qc7 12.Ne5 Nd5 13.Bd2 b5
14.Bb3 Nxe5 15.dxe5 O-O-O 16.g4 Bg6 17.f4 h5 18.h3 a6 19.Qf3 f5 20.exf6
gxf6 21.Rhe1 hxg4 22.hxg4 e5 23.f5 Bf7
User debug session below. Note that I am using the xboard feature that
allows me to add the same move more than once. :)
--
Alan
$ xboard -v
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 "-bookDepth" ~/.xboardrc
-bookDepth 51
$ cat ~/Documents/tmp/Rf1-Rg1-Rh1.pgn
[White "Rf1"]
[Result "1/2-1/2"]
1. e4 d5 2. exd5 Qxd5 3. Nc3 Qa5 4. d4 Nf6 5. Nf3 c6 6. Bd2 Bf5
7. Bc4 e6 8. Qe2 Bb4 9. O-O-O Nbd7 10. a3 Bxc3 11. Bxc3 Qc7 12.
Ne5 Nd5 13. Bd2 b5 14. Bb3 Nxe5 15. dxe5 O-O-O 16. g4 Bg6 17. f4
h5 18. h3 a6 19. Qf3 f5 20. exf6 gxf6 21. Rhe1 hxg4 22. hxg4 e5
23. f5 Bf7
24. Rf1 Rhe8 25. Rfe1
1/2-1/2
[White "Rg1"]
[Result "1/2-1/2"]
1. e4 d5 2. exd5 Qxd5 3. Nc3 Qa5 4. d4 Nf6 5. Nf3 c6 6. Bd2 Bf5
7. Bc4 e6 8. Qe2 Bb4 9. O-O-O Nbd7 10. a3 Bxc3 11. Bxc3 Qc7 12.
Ne5 Nd5 13. Bd2 b5 14. Bb3 Nxe5 15. dxe5 O-O-O 16. g4 Bg6 17. f4
h5 18. h3 a6 19. Qf3 f5 20. exf6 gxf6 21. Rhe1 hxg4 22. hxg4 e5
23. f5 Bf7
24. Rg1 Rhe8 25. Rge1
1/2-1/2
[White "Rh1"]
[Result "1/2-1/2"]
1. e4 d5 2. exd5 Qxd5 3. Nc3 Qa5 4. d4 Nf6 5. Nf3 c6 6. Bd2 Bf5
7. Bc4 e6 8. Qe2 Bb4 9. O-O-O Nbd7 10. a3 Bxc3 11. Bxc3 Qc7 12.
Ne5 Nd5 13. Bd2 b5 14. Bb3 Nxe5 15. dxe5 O-O-O 16. g4 Bg6 17. f4
h5 18. h3 a6 19. Qf3 f5 20. exf6 gxf6 21. Rhe1 hxg4 22. hxg4 e5
23. f5 Bf7
24. Rh1 Rhe8 25. Rhe1
1/2-1/2
$ rm ~/chesspgbook/book.bin
$ xboard -ncp &
[1] 29001
GUI | File | Load Game | Recently Used | Rf1-Rg1-Rh1.pgn
GUI | File | Save Games as Book
GUI | File | Quit
$ 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 | grep -F "612d49983aa49672"
612d49983aa49672 0105 0001 00010001 ## Rf1
612d49983aa49672 0106 0001 00010001 ## Rg1
612d49983aa49672 0107 0001 00010001 ## Rh1
[1]+ Done xboard -ncp
$ xboard -ncp &
[1] 29061
GUI | Edit | Edit Book
GUI | right-click through the book until 23...Bf7 is played
33.3% 1 Rf1 {1/1}
33.3% 1 Rg1 {1/1}
33.3% 1 Rg1 {1/1} ## where is Rh1 ??
GUI | add next move | drag Re1-h1
33.3% 1 Rf1 {1/1}
33.3% 1 Rg1 {1/1}
33.3% 1 Rg1 {1/1}
0.0% 1 Rh1 ## so far so good
GUI | commit changes
25.0% 1 Rf1 {1/1}
25.0% 1 Rg1 {1/1}
25.0% 1 Rg1 {1/1}
25.0% 1 Rg1 ## what happened ??
GUI | File | Quit
$ 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 | grep -F "612d49983aa49672"
612d49983aa49672 0105 0001 00010001 ## Rf1
612d49983aa49672 0106 0001 00010001 ## Rg1
612d49983aa49672 0106 0001 00010001 ## Rg1
612d49983aa49672 0107 0001 00000000 ## Rh1 spooky
[1]+ Done xboard -ncp
$