#include <stdio.h>
#include <string.h>
+#include <time.h>
+#include <stdlib.h>
#include "common.h"
#include "backend.h"
uint64 hash(int moveNr)
{
- char c;
- int p, r, f, i, p_enc, squareNr, pieceGroup;
+ int r, f, p_enc, squareNr, pieceGroup;
uint64 key=0, Zobrist;
for(f=BOARD_LEFT; f<BOARD_RGHT; f++){
if(appData.debugMode) fprintf(debugFP, "book key = %08x%08x\n", (unsigned int)(key>>32), (unsigned int)key);
offset=find_key(f, key, &entry);
- if(entry.key != key) return NULL;
+ if(entry.key != key) {
+ fclose(f);
+ return NULL;
+ }
entries[0] = entry;
count=1;
fseek(f, 16*(offset+1), SEEK_SET);
for(i=0; i<count; i++){
total_weight += entries[i].weight;
}
- srandom( time(0) );
j = (random() & 0x7FFF) * total_weight >> 15; // create random < total_weight
total_weight = 0;
for(i=0; i<count; i++){
move_to_string(move_s, entries[i].move);
if(appData.debugMode) fprintf(debugFP, "book move field = %d\n", entries[i].move);
+ fclose(f);
return move_s;
}