X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=book.c;h=c81df43ea369f2a8d5c94a8003991e593f839e3c;hb=de010509fa0e57ba955da6512c714fbff8606af3;hp=73fb2d20fbd7aac568ba6bb6c8cc5161253c757c;hpb=e15efca6667b2673b4c1a5879a6917eab6800e58;p=polyglot.git diff --git a/book.c b/book.c index 73fb2d2..c81df43 100644 --- a/book.c +++ b/book.c @@ -60,7 +60,7 @@ bool book_is_open(){ void book_open(const char file_name[]) { ASSERT(file_name!=NULL); - if(option_get_bool("BookLearn")){ + if(option_get_bool(Option,"BookLearn")){ BookFile = fopen(file_name,"rb+"); }else{ BookFile = fopen(file_name,"rb"); @@ -121,24 +121,30 @@ int book_move(const board_t * board, bool random) { entry_t entry[1]; int move; int score; + list_t list[1]; + int i; if(BookFile==NULL) return MoveNone; ASSERT(board!=NULL); ASSERT(random==TRUE||random==FALSE); + // init + + list_clear(list); + + book_moves(list,board); best_move = MoveNone; best_score = 0; - for (pos = find_pos(board->key); pos < BookSize; pos++) { - - read_entry(entry,pos); - if (entry->key != board->key) break; + for(i=0; imove; - score = entry->count; + move = list->move[i]; + score = list->value[i]; - if (move != MoveNone && move_is_legal(move,board)) { + if (move != MoveNone && + move_is_legal(move,board) && + score>10*option_get_int(Option,"BookTreshold")) { // pick this move? @@ -163,9 +169,9 @@ int book_move(const board_t * board, bool random) { return best_move; } -// book_disp() +// book_moves() -void book_disp(const board_t * board) { +void book_moves(list_t * list, const board_t * board) { int first_pos; int sum; @@ -176,8 +182,13 @@ void book_disp(const board_t * board) { char move_string[256]; ASSERT(board!=NULL); + ASSERT(list!=NULL); + + if(BookFile==NULL) return; - if(BookFile==NULL) return; + // init + + list_clear(list); first_pos = find_pos(board->key); @@ -201,14 +212,41 @@ void book_disp(const board_t * board) { if (entry->key != board->key) break; move = entry->move; - score = entry->count; + score = (((uint32)entry->count)*((uint32)10000))/sum; // 32 bit safe! - if (score > 0 && move != MoveNone && move_is_legal(move,board)) { - move_to_san(move,board,move_string,256); - printf(" %s (%.0f%%)\n",move_string,((double)score)/((double)sum)*100.0); + if (move != MoveNone && move_is_legal(move,board)) { + list_add_ex(list,move,score); } } +} + + +// book_disp() + +void book_disp(const board_t * board) { + + char move_string[256]; + list_t list[1]; + int i; + int treshold=option_get_int(Option,"BookTreshold"); + + ASSERT(board!=NULL); + + if(BookFile==NULL) return; + + book_moves(list,board); + + for(i=0; imove[i],board,move_string,256); + if(list->value[i]>10*treshold){ + printf(" %6s %5.2f%%\n",move_string,list->value[i]/100.0); + }else{ + printf(" %6s %5.2f%% (below treshold %4.2f%%)\n", + move_string,list->value[i]/100.0,treshold/10.0); + } + } + // this is necessary by the xboard protocol printf("\n"); }