X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=book.c;h=dc814586ecd335bd8a3743945ba2315f6286477d;hb=dd94bfa89dd6dd1238c3f7063e532ab3ed2d0858;hp=1c7f2feeba6ec7251bbc4aadd180dd3ffe9f240b;hpb=a02eb1349bbc0ad33bf36648b4c5b7d2ce197928;p=xboard.git diff --git a/book.c b/book.c index 1c7f2fe..dc81458 100644 --- a/book.c +++ b/book.c @@ -2,7 +2,7 @@ * book.c -- code for probing Polyglot opening books * * This code was first released in the public domain by Michel Van den Bergh. - * The array Random64 is taken from the Polyglot source code. + * The array Random64 is taken from the Polyglot source code. * I am pretty sure that a table of random numbers is never protected * by copyright. * @@ -28,6 +28,8 @@ * ------------------------------------------------------------------------ */ +#include "config.h" + #include #include #include @@ -65,7 +67,7 @@ typedef unsigned short uint16; typedef unsigned int uint32; typedef struct { - uint64 key; + uint64 key; uint16 move; uint16 weight; uint16 learnPoints; @@ -358,7 +360,7 @@ hash (int moveNr) f = boards[moveNr][EP_STATUS]; if(f >= 0 && f < 8){ if(!WhiteOnMove(moveNr)){ - // the test for neighboring Pawns might not be needed, + // the test for neighboring Pawns might not be needed, // as epStatus already kept track of it, but better safe than sorry. if((f>0 && boards[moveNr][3][f-1]==BlackPawn)|| (f<7 && boards[moveNr][3][f+1]==BlackPawn)){ @@ -515,7 +517,7 @@ move_to_string (char move_s[6], uint16 move) if(gameInfo.variant != VariantNormal) return; - // correct FRC-style castlings in variant normal. + // 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")){ safeStrCpy(move_s,"e1g1", 6); @@ -567,7 +569,7 @@ ReadFromBookFile (int moveNr, char *book, entry_t entries[]) static FILE *f = NULL; static char curBook[MSG_SIZ]; - if(book == NULL) return -1; + if(book == NULL) return -1; if(!f || strcmp(book, curBook)){ // keep book file open until book changed strncpy(curBook, book, MSG_SIZ); if(f) fclose(f); @@ -665,14 +667,14 @@ MCprobe (moveNr) char *ProbeBook (int moveNr, char *book) -{ // +{ // entry_t entries[MOVE_BUF]; int count; int i, j; static char move_s[6]; int total_weight; - if(moveNr >= 2*appData.bookDepth) return NULL; + if(moveNr >= 2*appData.bookDepth) return NULL; if(mcMode) return MCprobe(moveNr); if((count = ReadFromBookFile(moveNr, book, entries)) <= 0) return NULL; // no book, or no hit @@ -757,7 +759,12 @@ TextToMoves (char *text, int moveNum, entry_t *entries) if(w == 1) text = strstr(text, "1 ") + 2; // skip weight that could be recognized as move number one valid = ParseOneMove(text, moveNum, &moveType, &fromX, &fromY, &toX, &toY, &promoChar); text = strstr(text, yy_textstr) + strlen(yy_textstr); // skip what we parsed - if(!valid || moveType != NormalMove) continue; + if(!valid || moveType != NormalMove && moveType != WhiteDrop && moveType != BlackDrop + && moveType != WhitePromotion && moveType != BlackPromotion + && moveType != WhiteCapturesEnPassant && moveType != BlackCapturesEnPassant + && moveType != WhiteKingSideCastle && moveType != BlackKingSideCastle + && moveType != WhiteQueenSideCastle && moveType != BlackQueenSideCastle + && moveType != WhiteNonPromotion && moveType != BlackNonPromotion) continue; if(*text == ' ' && sscanf(text+1, "{%hd/%hd}", &entries[count].learnPoints, &entries[count].learnCount) == 2) { text = strchr(text+1, '}') + 1; } else { @@ -787,6 +794,7 @@ DisplayBook (int moveNr) p = MovesToText(count, entries); EditTagsPopUp(p, NULL); free(p); + addToBookFlag = FALSE; return TRUE; } @@ -979,6 +987,15 @@ AddGameToBook (int always) } void +PlayBookMove(char *text, int index) +{ + char *start = text+index, *end = start; + while(start > text && start[-1] != ' ' && start[-1] != '\t') start--; + while(*end && *++end != ' ' && *end != '\n'); *end = NULLCHAR; // find clicked word + if(start != end) TypeInDoneEvent(start); // fake it was typed in move type-in +} + +void FlushBook () { FILE *f;