X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=book.c;h=bd3a49ff14521f327b200f04a672c68a5d1e4d0f;hb=b382d988c6f886f3a49483df9e3e36de0b6b0824;hp=b57407358cc993113c69e4f35d615e7416accb5e;hpb=91e0735ab1cbc57465e0252bc95b90bc2ab13caa;p=xboard.git diff --git a/book.c b/book.c index b574073..bd3a49f 100644 --- a/book.c +++ b/book.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "common.h" #include "backend.h" @@ -444,13 +445,13 @@ void move_to_string(char move_s[6], uint16 move) // correct FRC-style castlings in variant normal. // [HGM] This is buggy code! e1h1 could very well be a normal R or Q move. if(!strcmp(move_s,"e1h1")){ - strcpy(move_s,"e1g1"); + safeStrCpy(move_s,"e1g1", 6); }else if(!strcmp(move_s,"e1a1")){ - strcpy(move_s,"e1c1"); + safeStrCpy(move_s,"e1c1", 6); }else if(!strcmp(move_s,"e8h8")){ - strcpy(move_s,"e8g8"); + safeStrCpy(move_s,"e8g8", 6); }else if(!strcmp(move_s,"e8a8")){ - strcpy(move_s,"e8c8"); + safeStrCpy(move_s,"e8c8", 6); } } @@ -466,7 +467,7 @@ char *ProbeBook(int moveNr, char *book) static char move_s[6]; int total_weight; - if(book == NULL) return NULL; + if(book == NULL || moveNr >= 2*appData.bookDepth) return NULL; // if(gameInfo.variant != VariantNormal) return NULL; // Zobrist scheme only works for normal Chess, so far f=fopen(book,"rb"); if(!f){ @@ -497,11 +498,21 @@ char *ProbeBook(int moveNr, char *book) if(count == MOVE_BUF) break; entries[count++] = entry; } + if(appData.bookStrength != 50) { // transform weights + double power = 0, maxWeight = 0.0; + if(appData.bookStrength) power = (100.-appData.bookStrength)/appData.bookStrength; + for(i=0; i maxWeight) maxWeight = entries[i].weight; + for(i=0; i 0) + entries[i].weight = appData.bookStrength || weight == 1.0 ? 1e4*exp(power * log(weight)) + 0.5 : 0.0; + } + } total_weight = 0; for(i=0; i> 15; // create random < total_weight + j = (random() & 0xFFF) * total_weight >> 12; // create random < total_weight total_weight = 0; for(i=0; i