version 1.4.37b
[polyglot.git] / book.c
diff --git a/book.c b/book.c
index 5821451..950e2f9 100644 (file)
--- a/book.c
+++ b/book.c
@@ -121,24 +121,30 @@ int book_move(const board_t * board, bool random) {
    entry_t entry[1];\r
    int move;\r
    int score;\r
+   list_t list[1];\r
+   int i;\r
 \r
    if(BookFile==NULL) return MoveNone;\r
 \r
    ASSERT(board!=NULL);\r
    ASSERT(random==TRUE||random==FALSE);\r
 \r
+   // init\r
+   \r
+   list_clear(list);\r
+\r
+   book_moves(list,board);\r
 \r
    best_move = MoveNone;\r
    best_score = 0;\r
-   for (pos = find_pos(board->key); pos < BookSize; pos++) {\r
+   for(i=0; i<list_size(list); i++){\r
 \r
-      read_entry(entry,pos);\r
-      if (entry->key != board->key) break;\r
-\r
-      move = entry->move;\r
-      score = entry->count;\r
+      move = list->move[i];\r
+      score = list->value[i];\r
 \r
-      if (move != MoveNone && move_is_legal(move,board)) {\r
+      if (move != MoveNone &&\r
+          move_is_legal(move,board) &&\r
+          score/10>option_get_int(Option,"BookTreshold")) {\r
 \r
          // pick this move?\r
 \r
@@ -163,9 +169,9 @@ int book_move(const board_t * board, bool random) {
    return best_move;\r
 }\r
 \r
-// book_disp()\r
+// book_moves()\r
 \r
-void book_disp(const board_t * board) {\r
+void book_moves(list_t * list, const board_t * board) {\r
 \r
    int first_pos;\r
    int sum;\r
@@ -176,8 +182,13 @@ void book_disp(const board_t * board) {
    char move_string[256];\r
 \r
    ASSERT(board!=NULL);\r
+   ASSERT(list!=NULL);\r
+\r
+   if(BookFile==NULL) return;\r
 \r
-   if(BookFile==NULL) return; \r
+   // init\r
+\r
+   list_clear(list);\r
 \r
    first_pos = find_pos(board->key);\r
 \r
@@ -201,15 +212,34 @@ void book_disp(const board_t * board) {
       if (entry->key != board->key) break;\r
 \r
       move = entry->move;\r
-      score = entry->count;\r
+      score = (entry->count*10000)/sum;  // 32 bit safe!\r
 \r
       if (score > 0 && move != MoveNone && move_is_legal(move,board)) {\r
-         move_to_san(move,board,move_string,256);\r
-         printf(" %s (%.0f%%)\n",move_string,((double)score)/((double)sum)*100.0);\r
+          list_add_ex(list,move,score);\r
       }\r
    }\r
 \r
-   printf("\n");\r
+}\r
+\r
+\r
+// book_disp()\r
+\r
+void book_disp(const board_t * board) {\r
+\r
+   char move_string[256];\r
+   list_t list[1];\r
+   int i;\r
+\r
+   ASSERT(board!=NULL);\r
+\r
+   if(BookFile==NULL) return;\r
+\r
+   book_moves(list,board);\r
+   \r
+   for(i=0; i<list_size(list); i++){\r
+       move_to_san(list->move[i],board,move_string,256);\r
+       printf(" %6s %5.2f%%\n",move_string,list->value[i]/100.0);\r
+   }\r
 }\r
 \r
 // book_learn_move()\r