]> git.sesse.net Git - pgn-extract/blobdiff - output.c
Store a hash of the previous board, to be able to disambigutate transpositions. ...
[pgn-extract] / output.c
index bb9ee772c58f1fca6323ebca8241e04cfa3a97d6..2792bd807fbb043fed42aa7c9fdd68dc941f5442 100644 (file)
--- a/output.c
+++ b/output.c
@@ -36,6 +36,7 @@
 #include "output.h"
 #include "mymalloc.h"
 #include "eco.h"
+#include "farmhash-c.h"
 
 
             /* Functions for outputting games in the required format. */
@@ -1231,12 +1232,15 @@ output_sesse_bin_game(Game current_game,FILE *outputfile,
         timestamp = 32503680000;
     }
 
+    uint16_t prev_board_hash = 0;
+
     for (move = current_game.moves; move != NULL; move = move->next) {
         unsigned int opening = move->eco ? move->eco->cumulative_hash_value : 0;  // Truncate to 32 bits.
 
         // key
-        putc(move->bpfen_len, outputfile);
+        putc(move->bpfen_len + sizeof(prev_board_hash), outputfile);
         fwrite(move->bpfen, move->bpfen_len, 1, outputfile);
+        fwrite(&prev_board_hash, sizeof(prev_board_hash), 1, outputfile);
 
         // value
         putc(result_int, outputfile);
@@ -1248,6 +1252,8 @@ output_sesse_bin_game(Game current_game,FILE *outputfile,
         fwrite(&start_position, sizeof(start_position), 1, outputfile);
         putc(strlen((char *)move->move), outputfile);
         fwrite(move->move, strlen((char *)move->move), 1, outputfile);
+
+        prev_board_hash = farmhash_32(move->bpfen, move->bpfen_len);
     }
 }