12 #include "book_make.h"
\r
14 #include "move_do.h"
\r
15 #include "move_gen.h"
\r
16 #include "move_legal.h"
\r
23 static const int COUNT_MAX = 16384;
\r
24 static const int StringSize = 4096;
\r
26 static const int NIL = -1;
\r
30 #define opp_search(s) ((s)==BOOK?ALL:BOOK)
\r
38 // Unfortunately the minggw32 cross compiler [4.2.1-sjlj (mingw32-2)]
\r
39 // seems to have a bug with anon structs contained in unions when using -O2.
\r
40 // See the ASSERT below in "read_entry_file"...
\r
41 // To be fair this seems to be illegal in C++
\r
42 // although it is hard to understand why, and the compiler does not complain
\r
74 bool book_trans_only;
\r
75 bool extended_search;
\r
87 static double MinScore;
\r
88 static bool RemoveWhite, RemoveBlack;
\r
89 static bool Uniform;
\r
90 static bool Quiet=false;
\r
92 static book_t Book[1];
\r
96 static void book_clear ();
\r
97 static void book_insert (const char file_name[]);
\r
98 static void book_filter ();
\r
99 static void book_sort ();
\r
100 static void book_save (const char file_name[]);
\r
102 static int find_entry (const board_t * board, int move);
\r
103 static void resize ();
\r
104 static void halve_stats (uint64 key);
\r
106 static bool keep_entry (int pos);
\r
108 static int entry_score (const entry_t * entry);
\r
110 static int key_compare (const void * p1, const void * p2);
\r
112 static void write_integer (FILE * file, int size, uint64 n);
\r
113 static uint64 read_integer(FILE * file, int size);
\r
115 static void read_entry_file(FILE *f, entry_t *entry);
\r
116 static void write_entry_file(FILE * f, const entry_t * entry);
\r
122 void book_make(int argc, char * argv[]) {
\r
125 const char * pgn_file;
\r
126 const char * bin_file;
\r
129 my_string_set(&pgn_file,"book.pgn");
\r
132 my_string_set(&bin_file,"book.bin");
\r
137 RemoveWhite = false;
\r
138 RemoveBlack = false;
\r
141 for (i = 1; i < argc; i++) {
\r
145 } else if (my_string_equal(argv[i],"make-book")) {
\r
149 } else if (my_string_equal(argv[i],"-pgn")) {
\r
152 if (argv[i] == NULL) my_fatal("book_make(): missing argument\n");
\r
154 my_string_set(&pgn_file,argv[i]);
\r
156 } else if (my_string_equal(argv[i],"-bin")) {
\r
159 if (argv[i] == NULL) my_fatal("book_make(): missing argument\n");
\r
161 my_string_set(&bin_file,argv[i]);
\r
163 } else if (my_string_equal(argv[i],"-max-ply")) {
\r
166 if (argv[i] == NULL) my_fatal("book_make(): missing argument\n");
\r
168 MaxPly = atoi(argv[i]);
\r
171 } else if (my_string_equal(argv[i],"-min-game")) {
\r
174 if (argv[i] == NULL) my_fatal("book_make(): missing argument\n");
\r
176 MinGame = atoi(argv[i]);
\r
179 } else if (my_string_equal(argv[i],"-min-score")) {
\r
182 if (argv[i] == NULL) my_fatal("book_make(): missing argument\n");
\r
184 MinScore = atof(argv[i]) / 100.0;
\r
185 ASSERT(MinScore>=0.0&&MinScore<=1.0);
\r
187 } else if (my_string_equal(argv[i],"-only-white")) {
\r
189 RemoveWhite = false;
\r
190 RemoveBlack = true;
\r
192 } else if (my_string_equal(argv[i],"-only-black")) {
\r
194 RemoveWhite = true;
\r
195 RemoveBlack = false;
\r
197 } else if (my_string_equal(argv[i],"-uniform")) {
\r
203 my_fatal("book_make(): unknown option \"%s\"\n",argv[i]);
\r
209 printf("inserting games ...\n");
\r
210 book_insert(pgn_file);
\r
212 printf("filtering entries ...\n");
\r
215 printf("sorting entries ...\n");
\r
218 printf("saving entries ...\n");
\r
219 book_save(bin_file);
\r
221 printf("all done!\n");
\r
226 static void book_clear() {
\r
231 Book->mask = (Book->alloc * 2) - 1;
\r
233 Book->entry = (entry_t *) my_malloc(Book->alloc*sizeof(entry_t));
\r
236 Book->hash = (sint32 *) my_malloc((Book->alloc*2)*sizeof(sint32));
\r
237 for (index = 0; index < Book->alloc*2; index++) {
\r
238 Book->hash[index] = NIL;
\r
244 static void book_insert(const char file_name[]) {
\r
254 ASSERT(file_name!=NULL);
\r
261 pgn_open(pgn,file_name);
\r
263 while (pgn_next_game(pgn)) {
\r
265 board_start(board);
\r
270 } else if (my_string_equal(pgn->result,"1-0")) {
\r
272 } else if (my_string_equal(pgn->result,"0-1")) {
\r
276 while (pgn_next_move(pgn,string,256)) {
\r
278 if (ply < MaxPly) {
\r
280 move = move_from_san(string,board);
\r
282 if (move == MoveNone || !move_is_legal(move,board)) {
\r
283 my_fatal("book_insert(): illegal move \"%s\" at line %d, column %d,game %d\n",string,pgn->move_line,pgn->move_column,pgn->game_nb);
\r
286 pos = find_entry(board,move);
\r
288 Book->entry[pos].n++;
\r
289 Book->entry[pos].sum += result+1;
\r
291 if (Book->entry[pos].n >= COUNT_MAX) {
\r
292 halve_stats(board->key);
\r
295 move_do(board,move);
\r
301 if (pgn->game_nb % 10000 == 0) printf("%d games ...\n",pgn->game_nb);
\r
306 printf("%d game%s.\n",pgn->game_nb,(pgn->game_nb>2)?"s":"");
\r
307 printf("%d entries.\n",Book->size);
\r
314 static void book_filter() {
\r
322 for (src = 0; src < Book->size; src++) {
\r
323 if (keep_entry(src)) Book->entry[dst++] = Book->entry[src];
\r
326 ASSERT(dst>=0&&dst<=Book->size);
\r
329 printf("%d entries.\n",Book->size);
\r
334 static void book_sort() {
\r
336 // sort keys for binary search
\r
338 qsort(Book->entry,Book->size,sizeof(entry_t),&key_compare);
\r
343 static void book_save(const char file_name[]) {
\r
348 ASSERT(file_name!=NULL);
\r
350 file = fopen(file_name,"wb");
\r
351 if (file == NULL) my_fatal("book_save(): can't open file \"%s\" for writing: %s\n",file_name,strerror(errno));
\r
355 for (pos = 0; pos < Book->size; pos++) {
\r
357 ASSERT(keep_entry(pos));
\r
359 write_integer(file,8,Book->entry[pos].key);
\r
360 write_integer(file,2,Book->entry[pos].move);
\r
361 write_integer(file,2,entry_score(&Book->entry[pos]));
\r
362 write_integer(file,2,0);
\r
363 write_integer(file,2,0);
\r
371 static int find_entry(const board_t * board, int move) {
\r
377 ASSERT(board!=NULL);
\r
378 ASSERT(move==MoveNone || move_is_ok(move));
\r
380 ASSERT(move==MoveNone || move_is_legal(move,board));
\r
388 for (index = key & (uint64) Book->mask; (pos=Book->hash[index]) != NIL; index = (index+1) & Book->mask) {
\r
390 ASSERT(pos>=0&&pos<Book->size);
\r
392 if (Book->entry[pos].key == key && Book->entry[pos].move == move) {
\r
393 return pos; // found
\r
399 ASSERT(Book->size<=Book->alloc);
\r
401 if (Book->size == Book->alloc) {
\r
403 // allocate more memory
\r
407 for (index = key & (uint64) Book->mask; Book->hash[index] != NIL; index = (index+1) & Book->mask)
\r
411 // create a new entry
\r
413 ASSERT(Book->size<Book->alloc);
\r
414 pos = Book->size++;
\r
416 Book->entry[pos].key = key;
\r
417 Book->entry[pos].move = move;
\r
418 Book->entry[pos].n = 0;
\r
419 Book->entry[pos].sum = 0;
\r
420 Book->entry[pos].colour = board->turn;
\r
422 // insert into the hash table
\r
424 ASSERT(index>=0&&index<Book->alloc*2);
\r
425 ASSERT(Book->hash[index]==NIL);
\r
426 Book->hash[index] = pos;
\r
428 ASSERT(pos>=0&&pos<Book->size);
\r
433 // rebuild_hash_table
\r
435 static void rebuild_hash_table(){
\r
437 for (index = 0; index < Book->alloc*2; index++) {
\r
438 Book->hash[index] = NIL;
\r
440 for (pos = 0; pos < Book->size; pos++) {
\r
441 for (index = Book->entry[pos].key & (uint64) Book->mask; Book->hash[index] != NIL; index = (index+1) & Book->mask)
\r
443 ASSERT(index>=0&&index<Book->alloc*2);
\r
444 Book->hash[index] = pos;
\r
448 static void resize() {
\r
452 ASSERT(Book->size==Book->alloc);
\r
455 Book->mask = (Book->alloc * 2) - 1;
\r
458 size += Book->alloc * sizeof(entry_t);
\r
459 size += (Book->alloc*2) * sizeof(sint32);
\r
461 if (size >= 1048576) if(!Quiet){printf("allocating %gMB ...\n",double(size)/1048576.0);}
\r
465 Book->entry = (entry_t *) my_realloc(Book->entry,Book->alloc*sizeof(entry_t));
\r
466 Book->hash = (sint32 *) my_realloc(Book->hash,(Book->alloc*2)*sizeof(sint32));
\r
468 // rebuild hash table
\r
470 rebuild_hash_table();
\r
476 static void halve_stats(uint64 key) {
\r
483 for (index = key & (uint64) Book->mask; (pos=Book->hash[index]) != NIL; index = (index+1) & Book->mask) {
\r
485 ASSERT(pos>=0&&pos<Book->size);
\r
487 if (Book->entry[pos].key == key) {
\r
488 Book->entry[pos].n = (Book->entry[pos].n + 1) / 2;
\r
489 Book->entry[pos].sum = (Book->entry[pos].sum + 1) / 2;
\r
496 static bool keep_entry(int pos) {
\r
498 const entry_t * entry;
\r
502 ASSERT(pos>=0&&pos<Book->size);
\r
504 entry = &Book->entry[pos];
\r
506 // if (entry->n == 0) return false;
\r
507 if (entry->n < MinGame) return false;
\r
509 if (entry->sum == 0) return false;
\r
511 score = (double(entry->sum) / double(entry->n)) / 2.0;
\r
512 ASSERT(score>=0.0&&score<=1.0);
\r
514 if (score < MinScore) return false;
\r
516 colour = entry->colour;
\r
518 if ((RemoveWhite && colour_is_white(colour))
\r
519 || (RemoveBlack && colour_is_black(colour))) {
\r
523 if (entry_score(entry) == 0) return false; // REMOVE ME?
\r
530 static int entry_score(const entry_t * entry) {
\r
534 ASSERT(entry!=NULL);
\r
536 // score = entry->n; // popularity
\r
537 score = entry->sum; // "expectancy"
\r
539 if (Uniform) score = 1;
\r
548 static int key_compare(const void * p1, const void * p2) {
\r
550 const entry_t * entry_1, * entry_2;
\r
555 entry_1 = (const entry_t *) p1;
\r
556 entry_2 = (const entry_t *) p2;
\r
558 if (entry_1->key > entry_2->key) {
\r
560 } else if (entry_1->key < entry_2->key) {
\r
563 return entry_score(entry_2) - entry_score(entry_1); // highest score first
\r
569 static void write_integer(FILE * file, int size, uint64 n) {
\r
574 ASSERT(file!=NULL);
\r
575 ASSERT(size>0&&size<=8);
\r
576 ASSERT(size==8||n>>(size*8)==0);
\r
578 for (i = size-1; i >= 0; i--) {
\r
579 b = (n >> (i*8)) & 0xFF;
\r
580 ASSERT(b>=0&&b<256);
\r
587 static uint64 read_integer(FILE * file, int size) {
\r
591 ASSERT(file!=NULL);
\r
592 ASSERT(size>0&&size<=8);
\r
594 for (i = 0; i < size; i++) {
\r
598 my_fatal("read_integer(): fgetc(): EOF reached\n");
\r
600 my_fatal("read_integer(): fgetc(): %s\n",strerror(errno));
\r
603 ASSERT(b>=0&&b<256);
\r
611 static void read_entry_file(FILE *f, entry_t *entry){
\r
613 ASSERT(entry!=NULL);
\r
614 n = entry->key = read_integer(f,8);
\r
615 entry->move = read_integer(f,2);
\r
616 entry->count = read_integer(f,2);
\r
617 entry->n = read_integer(f,2);
\r
618 entry->sum = read_integer(f,2);
\r
619 ASSERT(n==entry->key); // test for mingw compiler bug with anon structs
\r
622 // write_entry_file
\r
624 static void write_entry_file(FILE * f, const entry_t * entry) {
\r
625 ASSERT(entry!=NULL);
\r
626 write_integer(f,8,entry->key);
\r
627 write_integer(f,2,entry->move);
\r
628 write_integer(f,2,entry->count);
\r
629 write_integer(f,2,entry->n);
\r
630 write_integer(f,2,entry->sum);
\r
633 static void print_list(const board_t *board, list_t *list){
\r
636 char move_string[256];
\r
637 for (i = 0; i < list_size(list); i++) {
\r
638 move = list_move(list,i);
\r
639 move_to_san(move,board,move_string,256);
\r
640 printf("%s",move_string);
\r
646 // loads a polyglot book
\r
648 static void book_load(const char filename[]){
\r
655 ASSERT(filename!=NULL);
\r
656 if(!(f=fopen(filename,"rb"))){
\r
657 my_fatal("book_load() : can't open file \"%s\" for reading: %s\n",filename,strerror(errno));
\r
659 fseek(f,0L,SEEK_END); // superportable way to get size of book!
\r
661 fseek(f,0,SEEK_SET);
\r
662 for(i=0L;i<size;i++){
\r
663 read_entry_file(f,entry);
\r
664 ASSERT(Book->size<=Book->alloc);
\r
665 if (Book->size == Book->alloc) {
\r
666 // allocate more memoryx
\r
669 // insert into the book
\r
670 pos = Book->size++;
\r
671 Book->entry[pos].key = entry->key;
\r
672 ASSERT(entry->move!=MoveNone);
\r
673 Book->entry[pos].move = entry->move;
\r
674 Book->entry[pos].count = entry->count;
\r
675 Book->entry[pos].n = entry->n;
\r
676 Book->entry[pos].sum = entry->sum;
\r
677 Book->entry[pos].colour = ColourNone;
\r
678 // find free hash table spot
\r
679 for (index = entry->key & (uint64) Book->mask;
\r
680 Book->hash[index] != NIL;
\r
681 index = (index+1) & Book->mask);
\r
682 // insert into the hash table
\r
683 ASSERT(index>=0&&index<Book->alloc*2);
\r
684 ASSERT(Book->hash[index]==NIL);
\r
685 Book->hash[index] = pos;
\r
686 ASSERT(pos>=0&&pos<Book->size);
\r
691 // gen_book_moves()
\r
692 // similar signature as gen_legal_moves
\r
693 static int gen_book_moves(list_t * list, const board_t * board){
\r
694 int first_pos, pos, index;
\r
699 for (index = board->key & (uint64) Book->mask; (first_pos=Book->hash[index]) != NIL; index = (index+1) & Book->mask) {
\r
700 ASSERT(first_pos>=0&&first_pos<Book->size);
\r
701 if (Book->entry[first_pos].key == board->key) {
\r
706 if(!found) return -1;
\r
707 if(Book->entry[first_pos].move==MoveNone) return -1;
\r
708 for (pos = first_pos; pos < Book->size; pos++) {
\r
709 *entry=Book->entry[pos];
\r
710 if (entry->key != board->key) break;
\r
711 if (entry->count > 0 &&
\r
712 entry->move != MoveNone &&
\r
713 move_is_legal(entry->move,board)) {
\r
714 list_add(list,entry->move,entry->count);
\r
720 // gen_opp_book_moves()
\r
721 // moves to which opponent has a reply in book
\r
722 // similar signature as gen_legal_moves
\r
723 static void gen_opp_book_moves(list_t * list, const board_t * board){
\r
725 list_t new_list[1], legal_moves[1];
\r
726 board_t new_board[1];
\r
729 gen_legal_moves(legal_moves,board);
\r
730 for (i = 0; i < list_size(legal_moves); i++) {
\r
731 move = list_move(legal_moves,i);
\r
733 memcpy(new_board, board, sizeof(board_t));
\r
734 move_do(new_board,move);
\r
735 gen_book_moves(new_list,new_board); // wasteful in time but tested!
\r
736 if(list_size(new_list)!=0){
\r
737 list_add(list,move);
\r
742 static void print_moves(info_t *info){
\r
744 char move_string[256];
\r
750 board_start(board);
\r
751 for(i=0;i<info->height;i++){
\r
753 fprintf(info->output,"%d. ",i/2+1);
\r
758 move_to_san(info->moves[i],board,move_string,256);
\r
759 fprintf(info->output,"%s", move_string);
\r
760 if(color==colour_opp(info->initial_color)){
\r
761 fprintf(info->output,"{%.0f%%} ",100*info->probs[i]);
\r
763 fprintf(info->output," ");
\r
765 move_do(board,info->moves[i]);
\r
769 static int search_book(board_t *board, info_t *info, search_t search){
\r
771 board_t new_board[1];
\r
781 for(i=0;i<256;i++){
\r
782 probs[i]=0.0; // kill compiler warnings
\r
784 for(i=0;i<info->height;i++){
\r
785 if(board->key==info->keys[i]){
\r
787 fprintf(info->output,"%d: ",info->line);
\r
789 fprintf(info->output,"{cycle: ply=%d}\n",i);
\r
792 return 1; // end of line because of cycle
\r
795 if(!info->book_trans_only || (info->book_trans_only && search==BOOK)){
\r
796 info->keys[info->height]=board->key;
\r
797 size=Book->size; // hack
\r
798 pos=find_entry(board,MoveNone);
\r
799 if(size==Book->size){
\r
801 fprintf(info->output,"%d: ",info->line);
\r
803 fprintf(info->output,"{trans: line=%d, ply=%d}\n",
\r
804 Book->entry[pos].line,
\r
805 Book->entry[pos].height);
\r
808 return 1; // end of line because of transposition
\r
810 Book->entry[pos].height=info->height;
\r
811 Book->entry[pos].line=info->line;
\r
816 offset=gen_book_moves(list,board);
\r
817 if(info->extended_search){
\r
818 gen_legal_moves(list,board);
\r
820 // ASSERT(offset!=-1);
\r
821 if(offset!=-1){ // only false in starting position for black book
\r
822 Book->entry[offset].colour=board->turn;
\r
824 if(!info->extended_search){
\r
825 for(i=0;i<list_size(list);i++){
\r
826 prob_sum+=uint16(list_value(list,i));
\r
828 for(i=0;i<list_size(list);i++){
\r
829 probs[i]=double(uint16(list_value(list,i)))/double(prob_sum);
\r
834 gen_opp_book_moves(list,board);
\r
836 for (i = 0; i < list_size(list); i++) {
\r
837 move = list_move(list,i);
\r
838 memcpy(new_board, board, sizeof(board_t));
\r
839 ASSERT(move_is_legal(move,new_board));
\r
840 move_do(new_board,move);
\r
841 ASSERT(search!=opp_search(search));
\r
842 info->moves[info->height++]=move;
\r
844 info->probs[info->height-1]=probs[i];
\r
846 ret=search_book(new_board, info, opp_search(search));
\r
847 if(ret==0 && search==BOOK){
\r
849 fprintf(info->output,"%d: ",info->line);
\r
851 fprintf(info->output,"\n");
\r
854 ret=1; // end of line book move counts for 1
\r
857 ASSERT(info->height>=0);
\r
863 void init_info(info_t *info){
\r
867 info->initial_color=White;
\r
868 info->book_trans_only=FALSE;
\r
872 // remove MoveNone entries from book and rebuild hash table
\r
874 int read_ptr,write_ptr;
\r
876 for(read_ptr=0;read_ptr<Book->size;read_ptr++){
\r
877 if(Book->entry[read_ptr].move!=MoveNone){
\r
878 Book->entry[write_ptr++]=Book->entry[read_ptr];
\r
881 Book->size=write_ptr;
\r
882 rebuild_hash_table();
\r
887 void book_dump(int argc, char * argv[]) {
\r
888 const char * bin_file=NULL;
\r
889 const char * txt_file=NULL;
\r
890 char string[StringSize];
\r
891 int color=ColourNone;
\r
896 my_string_set(&bin_file,"book.bin");
\r
897 for (i = 1; i < argc; i++) {
\r
899 } else if (my_string_equal(argv[i],"dump-book")) {
\r
901 } else if (my_string_equal(argv[i],"-bin")) {
\r
903 if (i==argc) my_fatal("book_dump(): missing argument\n");
\r
904 my_string_set(&bin_file,argv[i]);
\r
905 } else if (my_string_equal(argv[i],"-out")) {
\r
907 if (i==argc) my_fatal("book_dump(): missing argument\n");
\r
908 my_string_set(&txt_file,argv[i]);
\r
909 } else if (my_string_equal(argv[i],"-color") || my_string_equal(argv[i],"-colour")) {
\r
911 if (i == argc) my_fatal("book_dump(): missing argument\n");
\r
912 if(my_string_equal(argv[i],"white")){
\r
914 }else if (my_string_equal(argv[i],"black")){
\r
917 my_fatal("book_dump(): unknown color \"%s\"\n",argv[i]);
\r
920 my_fatal("book_dump(): unknown option \"%s\"\n",argv[i]);
\r
923 if(color==ColourNone){
\r
924 my_fatal("book_dump(): you must specify a color\n");
\r
926 if(txt_file==NULL){
\r
927 snprintf(string,StringSize,"book_%s.txt",color?"white":"black");
\r
928 my_string_set(&txt_file,string);
\r
932 if(!Quiet){printf("loading book ...\n");}
\r
933 book_load(bin_file);
\r
934 board_start(board);
\r
936 info->initial_color=color;
\r
937 if(!(f=fopen(txt_file,"w"))){
\r
938 my_fatal("book_dump(): can't open file \"%s\" for writing: %s",
\r
939 txt_file,strerror(errno));
\r
942 fprintf(info->output,"Dump of \"%s\" for %s.\n",
\r
943 bin_file,color==White?"white":"black");
\r
945 if(!Quiet){printf("generating lines for white...\n");}
\r
946 search_book(board,info, BOOK);
\r
948 if(!Quiet){printf("generating lines for black...\n");}
\r
949 search_book(board,info, ALL);
\r
955 void book_info(int argc,char* argv[]){
\r
956 const char *bin_file=NULL;
\r
961 int white_pos,black_pos,total_pos,white_pos_extended,
\r
962 black_pos_extended,white_pos_extended_diff,black_pos_extended_diff;
\r
964 bool extended_search=FALSE;
\r
967 my_string_set(&bin_file,"book.bin");
\r
969 for (i = 1; i < argc; i++) {
\r
971 } else if (my_string_equal(argv[i],"info-book")) {
\r
973 } else if (my_string_equal(argv[i],"-bin")) {
\r
975 if (i==argc) my_fatal("book_info(): missing argument\n");
\r
976 my_string_set(&bin_file,argv[i]);
\r
977 } else if (my_string_equal(argv[i],"-exact")) {
\r
978 extended_search=TRUE;
\r
980 my_fatal("book_info(): unknown option \"%s\"\n",argv[i]);
\r
984 if(!Quiet){printf("loading book ...\n");}
\r
985 book_load(bin_file);
\r
988 board_start(board);
\r
990 info->book_trans_only=FALSE;
\r
991 info->initial_color=White;
\r
992 info->extended_search=FALSE;
\r
993 search_book(board,info, BOOK);
\r
994 printf("Lines for white : %8d\n",info->line-1);
\r
999 info->initial_color=Black;
\r
1001 ASSERT(Book->size==s);
\r
1002 board_start(board);
\r
1003 search_book(board,info, ALL);
\r
1004 printf("Lines for black : %8d\n",info->line-1);
\r
1007 ASSERT(Book->size==s);
\r
1012 for(pos=0;pos<Book->size;pos++){
\r
1013 if(Book->entry[pos].key==last_key){
\r
1014 ASSERT(Book->entry[pos].colour==ColourNone);
\r
1017 last_key=Book->entry[pos].key;
\r
1019 if(Book->entry[pos].colour==White){
\r
1021 }else if(Book->entry[pos].colour==Black){
\r
1025 printf("Positions on lines for white : %8d\n",white_pos);
\r
1026 printf("Positions on lines for black : %8d\n",black_pos);
\r
1029 if(extended_search){
\r
1031 info->book_trans_only=TRUE;
\r
1032 info->initial_color=White;
\r
1033 info->extended_search=TRUE;
\r
1035 board_start(board);
\r
1036 search_book(board,info, BOOK);
\r
1039 info->book_trans_only=TRUE;
\r
1040 info->initial_color=Black;
\r
1041 info->extended_search=TRUE;
\r
1043 board_start(board);
\r
1044 search_book(board,info, ALL);
\r
1046 ASSERT(Book->size==s);
\r
1047 white_pos_extended=0;
\r
1048 black_pos_extended=0;
\r
1050 for(pos=0;pos<Book->size;pos++){
\r
1051 if(Book->entry[pos].key==last_key){
\r
1052 ASSERT(Book->entry[pos].colour==ColourNone);
\r
1055 last_key=Book->entry[pos].key;
\r
1056 if(Book->entry[pos].colour==White){
\r
1057 white_pos_extended++;
\r
1058 }else if(Book->entry[pos].colour==Black){
\r
1059 black_pos_extended++;
\r
1062 white_pos_extended_diff=white_pos_extended-white_pos;
\r
1063 black_pos_extended_diff=black_pos_extended-black_pos;
\r
1064 printf("Unreachable white positions(?) : %8d\n",
\r
1065 white_pos_extended_diff);
\r
1066 printf("Unreachable black positions(?) : %8d\n",
\r
1067 black_pos_extended_diff);
\r
1070 if(extended_search){
\r
1071 printf("Isolated positions : %8d\n",
\r
1072 total_pos-white_pos_extended-black_pos_extended);
\r
1074 printf("Isolated positions : %8d\n",
\r
1075 total_pos-white_pos-black_pos);
\r
1081 // end of book_make.cpp
\r