]> git.sesse.net Git - remoteglot-book/blobdiff - binlookup.cpp
Build with the new transposition data from pgn-extract. A lot of UI is still missing...
[remoteglot-book] / binlookup.cpp
index 08455ebd0850769cb0c9440f2bbe19cc52bfee90..894da9dcf0dbd2ec9eccbe89e4eef004fa62c5e5 100644 (file)
@@ -6,7 +6,9 @@
 #include <memory>
 #include <string>
 #include <string.h>
+#include <farmhash.h>
 #include "count.pb.h"
+#include "merge_count.h"
 #include "hash.h"
 
 using namespace std;
@@ -53,18 +55,33 @@ int main(int argc, char **argv)
                        srcs[bucket] = mtbl_reader_source(mtbls[bucket]);
                }
 
-               mtbl_iter *it = mtbl_source_get(srcs[bucket], bpfen, bpfen_len);
+               // Give back the hash of the position to be kind to the user
+               uint16_t board_hash = util::Hash32((const char *)bpfen, bpfen_len);
+               printf("%d\n", board_hash);
+
+               mtbl_iter *it = mtbl_source_get_prefix(srcs[bucket], bpfen, bpfen_len);
 
                const uint8_t *key, *val;
                size_t len_key, len_val;
 
-               if (mtbl_iter_next(it, &key, &len_key, &val, &len_val)) {
-                       Count c;
-                       c.ParseFromArray(val, len_val);
-                       printf("%d %d %d %u %f %f %d %ld %d %ld",
+               Count c;
+               bool has_c = false;
+               while (mtbl_iter_next(it, &key, &len_key, &val, &len_val)) {
+                       if (has_c) {
+                               Count tmpc;
+                               tmpc.ParseFromArray(val, len_val);
+                               c = merge_count(c, tmpc);
+                       } else {
+                               c.ParseFromArray(val, len_val);
+                               has_c = true;
+                       }
+               }
+
+               if (has_c) {
+                       printf("%d %d %d %u %ld %ld %d %ld %d %ld",
                                c.white(), c.draw(), c.black(), c.opening_num(),
-                               double(c.sum_white_elo()) / c.num_elo(),
-                               double(c.sum_black_elo()) / c.num_elo(),
+                               c.sum_white_elo(),
+                               c.sum_black_elo(),
                                c.num_elo(), c.first_timestamp(),
                                c.pgn_file_num(),
                                c.pgn_start_position());