]> git.sesse.net Git - pgn-extract/commitdiff
Make the binary output include the final position.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 15 Dec 2014 20:57:35 +0000 (21:57 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 15 Dec 2014 20:57:35 +0000 (21:57 +0100)
output.c

index 2792bd807fbb043fed42aa7c9fdd68dc941f5442..9c57e3195f1678ddf9db3e5f3421cd19b26c6597 100644 (file)
--- a/output.c
+++ b/output.c
@@ -66,7 +66,8 @@ static void print_algebraic_game(Game current_game,FILE *outputfile,
                            unsigned move_number,Boolean white_to_move,
                            Board *final_board);
 static void output_sesse_bin_game(Game current_game,FILE *outputfile,
-                                  unsigned move_number,Boolean white_to_move);
+                                  unsigned move_number,Boolean white_to_move,
+                                  Board *final_board);
 static void print_epd_game(Game current_game,FILE *outputfile,
                            unsigned move_number,Boolean white_to_move,
                            Board *final_board);
@@ -1006,7 +1007,8 @@ output_game(Game current_game,FILE *outputfile)
                output_cm_game(outputfile,move_number,white_to_move,current_game);
                break;
            case SESSE_BIN:
-               output_sesse_bin_game(current_game,outputfile,move_number,white_to_move);
+               output_sesse_bin_game(current_game,outputfile,move_number,white_to_move,
+                                      final_board);
                break;
            default:
                fprintf(GlobalState.logfile,
@@ -1170,7 +1172,8 @@ print_algebraic_game(Game current_game,FILE *outputfile,
 
 static void
 output_sesse_bin_game(Game current_game,FILE *outputfile,
-                      unsigned move_number,Boolean white_to_move)
+                      unsigned move_number,Boolean white_to_move,
+                      Board* final_board)
 {
     const char *result = NULL;
     Move *move;
@@ -1233,9 +1236,10 @@ output_sesse_bin_game(Game current_game,FILE *outputfile,
     }
 
     uint16_t prev_board_hash = 0;
+    unsigned int opening;
 
     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.
+        opening = move->eco ? move->eco->cumulative_hash_value : 0;  // Truncate to 32 bits.
 
         // key
         putc(move->bpfen_len + sizeof(prev_board_hash), outputfile);
@@ -1255,6 +1259,28 @@ output_sesse_bin_game(Game current_game,FILE *outputfile,
 
         prev_board_hash = farmhash_32(move->bpfen, move->bpfen_len);
     }
+
+    // Final position.
+    char *bpfen;
+    int bpfen_len;
+    build_BPFEN_string(final_board, &bpfen, &bpfen_len);
+
+    // key
+    putc(bpfen_len + sizeof(prev_board_hash), outputfile);
+    fwrite(bpfen, bpfen_len, 1, outputfile);
+    fwrite(&prev_board_hash, sizeof(prev_board_hash), 1, outputfile);
+
+    // value
+    putc(result_int, outputfile);
+    fwrite(&white_elo, sizeof(white_elo), 1, outputfile);
+    fwrite(&black_elo, sizeof(black_elo), 1, outputfile);
+    fwrite(&opening, sizeof(opening), 1, outputfile);  // Not perfect, but should be OK.
+    fwrite(&timestamp, sizeof(timestamp), 1, outputfile);
+    fwrite(&file_num, sizeof(file_num), 1, outputfile);
+    fwrite(&start_position, sizeof(start_position), 1, outputfile);
+    putc(0, outputfile);  // No move.
+
+    free(bpfen);
 }
 
 static void