Package: polyglot
Version: 2.0.4+git20210322-1
Severity: normal

Dear Maintainer,

The weights-value is an uint16_t meaning the maximum value is 65535.
Now when merging books with records that have that value or when the sum
of two records goes above 65535, then the outcome is a truncated value.
For example 65535 + 10 -> 9. So a preferred move suddeny becomes
seldomly choosen.

The problem lays in book_merge.c and I believe this patch could fix the
problem:


--- book_merge.c.org    2025-09-20 09:06:20.971695075 +0200
+++ book_merge.c        2025-09-20 09:11:43.913873878 +0200
@@ -161,7 +161,12 @@
             do {
                for(j=0; j<n; j++) {
                   if(e[i].move == e[j].move) {
-                     e[j].count += e[i--].count;
+                     uint16_t target = e[j].count;
+                     uint16_t to_add = e[i--].count;
+                     if (to_add >= 65535 - target)
+                        e[j].count = 65535;
+                     else
+                        e[j].count += to_add;
                      break;
                   }
                }

I encountered this problem while processing the
https://database.lichess.org/ dumps, so this is not only a theoretical
problem.


-- System Information:
Debian Release: 13.1
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.12.43+deb13-amd64 (SMP w/4 CPU threads; PREEMPT)
Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8) (ignored: LC_ALL set to 
en_US.UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages polyglot depends on:
ii  libc6  2.41-12

Versions of packages polyglot recommends:
ii  stockfish  17-1

polyglot suggests no packages.

-- no debconf information

Reply via email to