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 union{ // unfortunately minggw32 seems to have a bug with anon unions.
\r
68 bool book_trans_only;
\r
69 bool extended_search;
\r
81 static double MinScore;
\r
82 static bool RemoveWhite, RemoveBlack;
\r
83 static bool Uniform;
\r
84 static bool Quiet=false;
\r
86 static book_t Book[1];
\r
90 static void book_clear ();
\r
91 static void book_insert (const char file_name[]);
\r
92 static void book_filter ();
\r
93 static void book_sort ();
\r
94 static void book_save (const char file_name[]);
\r
96 static int find_entry (const board_t * board, int move);
\r
97 static void resize ();
\r
98 static void halve_stats (uint64 key);
\r
100 static bool keep_entry (int pos);
\r
102 static int entry_score (const entry_t * entry);
\r
104 static int key_compare (const void * p1, const void * p2);
\r
106 static void write_integer (FILE * file, int size, uint64 n);
\r
107 static uint64 read_integer(FILE * file, int size);
\r
109 static void read_entry_file(FILE *f, entry_t *entry);
\r
110 static void write_entry_file(FILE * f, const entry_t * entry);
\r
116 void book_make(int argc, char * argv[]) {
\r
119 const char * pgn_file;
\r
120 const char * bin_file;
\r
123 my_string_set(&pgn_file,"book.pgn");
\r
126 my_string_set(&bin_file,"book.bin");
\r
131 RemoveWhite = false;
\r
132 RemoveBlack = false;
\r
135 for (i = 1; i < argc; i++) {
\r
139 } else if (my_string_equal(argv[i],"make-book")) {
\r
143 } else if (my_string_equal(argv[i],"-pgn")) {
\r
146 if (argv[i] == NULL) my_fatal("book_make(): missing argument\n");
\r
148 my_string_set(&pgn_file,argv[i]);
\r
150 } else if (my_string_equal(argv[i],"-bin")) {
\r
153 if (argv[i] == NULL) my_fatal("book_make(): missing argument\n");
\r
155 my_string_set(&bin_file,argv[i]);
\r
157 } else if (my_string_equal(argv[i],"-max-ply")) {
\r
160 if (argv[i] == NULL) my_fatal("book_make(): missing argument\n");
\r
162 MaxPly = atoi(argv[i]);
\r
165 } else if (my_string_equal(argv[i],"-min-game")) {
\r
168 if (argv[i] == NULL) my_fatal("book_make(): missing argument\n");
\r
170 MinGame = atoi(argv[i]);
\r
173 } else if (my_string_equal(argv[i],"-min-score")) {
\r
176 if (argv[i] == NULL) my_fatal("book_make(): missing argument\n");
\r
178 MinScore = atof(argv[i]) / 100.0;
\r
179 ASSERT(MinScore>=0.0&&MinScore<=1.0);
\r
181 } else if (my_string_equal(argv[i],"-only-white")) {
\r
183 RemoveWhite = false;
\r
184 RemoveBlack = true;
\r
186 } else if (my_string_equal(argv[i],"-only-black")) {
\r
188 RemoveWhite = true;
\r
189 RemoveBlack = false;
\r
191 } else if (my_string_equal(argv[i],"-uniform")) {
\r
197 my_fatal("book_make(): unknown option \"%s\"\n",argv[i]);
\r
203 printf("inserting games ...\n");
\r
204 book_insert(pgn_file);
\r
206 printf("filtering entries ...\n");
\r
209 printf("sorting entries ...\n");
\r
212 printf("saving entries ...\n");
\r
213 book_save(bin_file);
\r
215 printf("all done!\n");
\r
220 static void book_clear() {
\r
225 Book->mask = (Book->alloc * 2) - 1;
\r
227 Book->entry = (entry_t *) my_malloc(Book->alloc*sizeof(entry_t));
\r
230 Book->hash = (sint32 *) my_malloc((Book->alloc*2)*sizeof(sint32));
\r
231 for (index = 0; index < Book->alloc*2; index++) {
\r
232 Book->hash[index] = NIL;
\r
238 static void book_insert(const char file_name[]) {
\r
248 ASSERT(file_name!=NULL);
\r
255 pgn_open(pgn,file_name);
\r
257 while (pgn_next_game(pgn)) {
\r
259 board_start(board);
\r
264 } else if (my_string_equal(pgn->result,"1-0")) {
\r
266 } else if (my_string_equal(pgn->result,"0-1")) {
\r
270 while (pgn_next_move(pgn,string,256)) {
\r
272 if (ply < MaxPly) {
\r
274 move = move_from_san(string,board);
\r
276 if (move == MoveNone || !move_is_legal(move,board)) {
\r
277 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
280 pos = find_entry(board,move);
\r
282 Book->entry[pos].n++;
\r
283 Book->entry[pos].sum += result+1;
\r
285 if (Book->entry[pos].n >= COUNT_MAX) {
\r
286 halve_stats(board->key);
\r
289 move_do(board,move);
\r
295 if (pgn->game_nb % 10000 == 0) printf("%d games ...\n",pgn->game_nb);
\r
300 printf("%d game%s.\n",pgn->game_nb,(pgn->game_nb>2)?"s":"");
\r
301 printf("%d entries.\n",Book->size);
\r
308 static void book_filter() {
\r
316 for (src = 0; src < Book->size; src++) {
\r
317 if (keep_entry(src)) Book->entry[dst++] = Book->entry[src];
\r
320 ASSERT(dst>=0&&dst<=Book->size);
\r
323 printf("%d entries.\n",Book->size);
\r
328 static void book_sort() {
\r
330 // sort keys for binary search
\r
332 qsort(Book->entry,Book->size,sizeof(entry_t),&key_compare);
\r
337 static void book_save(const char file_name[]) {
\r
342 ASSERT(file_name!=NULL);
\r
344 file = fopen(file_name,"wb");
\r
345 if (file == NULL) my_fatal("book_save(): can't open file \"%s\" for writing: %s\n",file_name,strerror(errno));
\r
349 for (pos = 0; pos < Book->size; pos++) {
\r
351 ASSERT(keep_entry(pos));
\r
353 write_integer(file,8,Book->entry[pos].key);
\r
354 write_integer(file,2,Book->entry[pos].move);
\r
355 write_integer(file,2,entry_score(&Book->entry[pos]));
\r
356 write_integer(file,2,0);
\r
357 write_integer(file,2,0);
\r
365 static int find_entry(const board_t * board, int move) {
\r
371 ASSERT(board!=NULL);
\r
372 ASSERT(move==MoveNone || move_is_ok(move));
\r
374 ASSERT(move==MoveNone || move_is_legal(move,board));
\r
382 for (index = key & (uint64) Book->mask; (pos=Book->hash[index]) != NIL; index = (index+1) & Book->mask) {
\r
384 ASSERT(pos>=0&&pos<Book->size);
\r
386 if (Book->entry[pos].key == key && Book->entry[pos].move == move) {
\r
387 return pos; // found
\r
393 ASSERT(Book->size<=Book->alloc);
\r
395 if (Book->size == Book->alloc) {
\r
397 // allocate more memory
\r
401 for (index = key & (uint64) Book->mask; Book->hash[index] != NIL; index = (index+1) & Book->mask)
\r
405 // create a new entry
\r
407 ASSERT(Book->size<Book->alloc);
\r
408 pos = Book->size++;
\r
410 Book->entry[pos].key = key;
\r
411 Book->entry[pos].move = move;
\r
412 Book->entry[pos].n = 0;
\r
413 Book->entry[pos].sum = 0;
\r
414 Book->entry[pos].colour = board->turn;
\r
416 // insert into the hash table
\r
418 ASSERT(index>=0&&index<Book->alloc*2);
\r
419 ASSERT(Book->hash[index]==NIL);
\r
420 Book->hash[index] = pos;
\r
422 ASSERT(pos>=0&&pos<Book->size);
\r
427 // rebuild_hash_table
\r
429 static void rebuild_hash_table(){
\r
431 for (index = 0; index < Book->alloc*2; index++) {
\r
432 Book->hash[index] = NIL;
\r
434 for (pos = 0; pos < Book->size; pos++) {
\r
435 for (index = Book->entry[pos].key & (uint64) Book->mask; Book->hash[index] != NIL; index = (index+1) & Book->mask)
\r
437 ASSERT(index>=0&&index<Book->alloc*2);
\r
438 Book->hash[index] = pos;
\r
442 static void resize() {
\r
446 ASSERT(Book->size==Book->alloc);
\r
449 Book->mask = (Book->alloc * 2) - 1;
\r
452 size += Book->alloc * sizeof(entry_t);
\r
453 size += (Book->alloc*2) * sizeof(sint32);
\r
455 if (size >= 1048576) if(!Quiet){printf("allocating %gMB ...\n",double(size)/1048576.0);}
\r
459 Book->entry = (entry_t *) my_realloc(Book->entry,Book->alloc*sizeof(entry_t));
\r
460 Book->hash = (sint32 *) my_realloc(Book->hash,(Book->alloc*2)*sizeof(sint32));
\r
462 // rebuild hash table
\r
464 rebuild_hash_table();
\r
470 static void halve_stats(uint64 key) {
\r
477 for (index = key & (uint64) Book->mask; (pos=Book->hash[index]) != NIL; index = (index+1) & Book->mask) {
\r
479 ASSERT(pos>=0&&pos<Book->size);
\r
481 if (Book->entry[pos].key == key) {
\r
482 Book->entry[pos].n = (Book->entry[pos].n + 1) / 2;
\r
483 Book->entry[pos].sum = (Book->entry[pos].sum + 1) / 2;
\r
490 static bool keep_entry(int pos) {
\r
492 const entry_t * entry;
\r
496 ASSERT(pos>=0&&pos<Book->size);
\r
498 entry = &Book->entry[pos];
\r
500 // if (entry->n == 0) return false;
\r
501 if (entry->n < MinGame) return false;
\r
503 if (entry->sum == 0) return false;
\r
505 score = (double(entry->sum) / double(entry->n)) / 2.0;
\r
506 ASSERT(score>=0.0&&score<=1.0);
\r
508 if (score < MinScore) return false;
\r
510 colour = entry->colour;
\r
512 if ((RemoveWhite && colour_is_white(colour))
\r
513 || (RemoveBlack && colour_is_black(colour))) {
\r
517 if (entry_score(entry) == 0) return false; // REMOVE ME?
\r
524 static int entry_score(const entry_t * entry) {
\r
528 ASSERT(entry!=NULL);
\r
530 // score = entry->n; // popularity
\r
531 score = entry->sum; // "expectancy"
\r
533 if (Uniform) score = 1;
\r
542 static int key_compare(const void * p1, const void * p2) {
\r
544 const entry_t * entry_1, * entry_2;
\r
549 entry_1 = (const entry_t *) p1;
\r
550 entry_2 = (const entry_t *) p2;
\r
552 if (entry_1->key > entry_2->key) {
\r
554 } else if (entry_1->key < entry_2->key) {
\r
557 return entry_score(entry_2) - entry_score(entry_1); // highest score first
\r
563 static void write_integer(FILE * file, int size, uint64 n) {
\r
568 ASSERT(file!=NULL);
\r
569 ASSERT(size>0&&size<=8);
\r
570 ASSERT(size==8||n>>(size*8)==0);
\r
572 for (i = size-1; i >= 0; i--) {
\r
573 b = (n >> (i*8)) & 0xFF;
\r
574 ASSERT(b>=0&&b<256);
\r
581 static uint64 read_integer(FILE * file, int size) {
\r
585 ASSERT(file!=NULL);
\r
586 ASSERT(size>0&&size<=8);
\r
588 for (i = 0; i < size; i++) {
\r
592 my_fatal("read_integer(): fgetc(): EOF reached\n");
\r
594 my_fatal("read_integer(): fgetc(): %s\n",strerror(errno));
\r
597 ASSERT(b>=0&&b<256);
\r
605 static void read_entry_file(FILE *f, entry_t *entry){
\r
607 ASSERT(entry!=NULL);
\r
608 n = entry->key = read_integer(f,8);
\r
609 entry->move = read_integer(f,2);
\r
610 entry->count = read_integer(f,2);
\r
611 entry->n = read_integer(f,2);
\r
612 entry->sum = read_integer(f,2);
\r
613 ASSERT(n==entry->key); // test for mingw compiler bug with anon structs
\r
616 // write_entry_file
\r
618 static void write_entry_file(FILE * f, const entry_t * entry) {
\r
619 ASSERT(entry!=NULL);
\r
620 write_integer(f,8,entry->key);
\r
621 write_integer(f,2,entry->move);
\r
622 write_integer(f,2,entry->count);
\r
623 write_integer(f,2,entry->n);
\r
624 write_integer(f,2,entry->sum);
\r
627 static void print_list(const board_t *board, list_t *list){
\r
630 char move_string[256];
\r
631 for (i = 0; i < list_size(list); i++) {
\r
632 move = list_move(list,i);
\r
633 move_to_san(move,board,move_string,256);
\r
634 printf("%s",move_string);
\r
640 // loads a polyglot book
\r
642 static void book_load(const char filename[]){
\r
649 ASSERT(filename!=NULL);
\r
650 if(!(f=fopen(filename,"rb"))){
\r
651 my_fatal("book_load() : can't open file \"%s\" for reading: %s\n",filename,strerror(errno));
\r
653 fseek(f,0L,SEEK_END); // superportable way to get size of book!
\r
655 fseek(f,0,SEEK_SET);
\r
656 for(i=0L;i<size;i++){
\r
657 read_entry_file(f,entry);
\r
658 ASSERT(Book->size<=Book->alloc);
\r
659 if (Book->size == Book->alloc) {
\r
660 // allocate more memoryx
\r
663 // insert into the book
\r
664 pos = Book->size++;
\r
665 Book->entry[pos].key = entry->key;
\r
666 ASSERT(entry->move!=MoveNone);
\r
667 Book->entry[pos].move = entry->move;
\r
668 Book->entry[pos].count = entry->count;
\r
669 Book->entry[pos].n = entry->n;
\r
670 Book->entry[pos].sum = entry->sum;
\r
671 Book->entry[pos].colour = ColourNone;
\r
672 // find free hash table spot
\r
673 for (index = entry->key & (uint64) Book->mask;
\r
674 Book->hash[index] != NIL;
\r
675 index = (index+1) & Book->mask);
\r
676 // insert into the hash table
\r
677 ASSERT(index>=0&&index<Book->alloc*2);
\r
678 ASSERT(Book->hash[index]==NIL);
\r
679 Book->hash[index] = pos;
\r
680 ASSERT(pos>=0&&pos<Book->size);
\r
685 // gen_book_moves()
\r
686 // similar signature as gen_legal_moves
\r
687 static int gen_book_moves(list_t * list, const board_t * board){
\r
688 int first_pos, pos, index;
\r
693 for (index = board->key & (uint64) Book->mask; (first_pos=Book->hash[index]) != NIL; index = (index+1) & Book->mask) {
\r
694 ASSERT(first_pos>=0&&first_pos<Book->size);
\r
695 if (Book->entry[first_pos].key == board->key) {
\r
700 if(!found) return -1;
\r
701 if(Book->entry[first_pos].move==MoveNone) return -1;
\r
702 for (pos = first_pos; pos < Book->size; pos++) {
\r
703 *entry=Book->entry[pos];
\r
704 if (entry->key != board->key) break;
\r
705 if (entry->count > 0 &&
\r
706 entry->move != MoveNone &&
\r
707 move_is_legal(entry->move,board)) {
\r
708 list_add(list,entry->move,entry->count);
\r
714 // gen_opp_book_moves()
\r
715 // moves to which opponent has a reply in book
\r
716 // similar signature as gen_legal_moves
\r
717 static void gen_opp_book_moves(list_t * list, const board_t * board){
\r
719 list_t new_list[1], legal_moves[1];
\r
720 board_t new_board[1];
\r
723 gen_legal_moves(legal_moves,board);
\r
724 for (i = 0; i < list_size(legal_moves); i++) {
\r
725 move = list_move(legal_moves,i);
\r
727 memcpy(new_board, board, sizeof(board_t));
\r
728 move_do(new_board,move);
\r
729 gen_book_moves(new_list,new_board); // wasteful in time but tested!
\r
730 if(list_size(new_list)!=0){
\r
731 list_add(list,move);
\r
736 static void print_moves(info_t *info){
\r
738 char move_string[256];
\r
744 board_start(board);
\r
745 for(i=0;i<info->height;i++){
\r
747 fprintf(info->output,"%d. ",i/2+1);
\r
752 move_to_san(info->moves[i],board,move_string,256);
\r
753 fprintf(info->output,"%s", move_string);
\r
754 if(color==colour_opp(info->initial_color)){
\r
755 fprintf(info->output,"{%.0f%%} ",100*info->probs[i]);
\r
757 fprintf(info->output," ");
\r
759 move_do(board,info->moves[i]);
\r
763 static int search_book(board_t *board, info_t *info, search_t search){
\r
765 board_t new_board[1];
\r
775 for(i=0;i<256;i++){
\r
776 probs[i]=0.0; // kill compiler warnings
\r
778 for(i=0;i<info->height;i++){
\r
779 if(board->key==info->keys[i]){
\r
781 fprintf(info->output,"%d: ",info->line);
\r
783 fprintf(info->output,"{cycle: ply=%d}\n",i);
\r
786 return 1; // end of line because of cycle
\r
789 if(!info->book_trans_only || (info->book_trans_only && search==BOOK)){
\r
790 info->keys[info->height]=board->key;
\r
791 size=Book->size; // hack
\r
792 pos=find_entry(board,MoveNone);
\r
793 if(size==Book->size){
\r
795 fprintf(info->output,"%d: ",info->line);
\r
797 fprintf(info->output,"{trans: line=%d, ply=%d}\n",
\r
798 Book->entry[pos].line,
\r
799 Book->entry[pos].height);
\r
802 return 1; // end of line because of transposition
\r
804 Book->entry[pos].height=info->height;
\r
805 Book->entry[pos].line=info->line;
\r
810 offset=gen_book_moves(list,board);
\r
811 if(info->extended_search){
\r
812 gen_legal_moves(list,board);
\r
814 // ASSERT(offset!=-1);
\r
815 if(offset!=-1){ // only false in starting position for black book
\r
816 Book->entry[offset].colour=board->turn;
\r
818 if(!info->extended_search){
\r
819 for(i=0;i<list_size(list);i++){
\r
820 prob_sum+=uint16(list_value(list,i));
\r
822 for(i=0;i<list_size(list);i++){
\r
823 probs[i]=double(uint16(list_value(list,i)))/double(prob_sum);
\r
828 gen_opp_book_moves(list,board);
\r
830 for (i = 0; i < list_size(list); i++) {
\r
831 move = list_move(list,i);
\r
832 memcpy(new_board, board, sizeof(board_t));
\r
833 ASSERT(move_is_legal(move,new_board));
\r
834 move_do(new_board,move);
\r
835 ASSERT(search!=opp_search(search));
\r
836 info->moves[info->height++]=move;
\r
838 info->probs[info->height-1]=probs[i];
\r
840 ret=search_book(new_board, info, opp_search(search));
\r
841 if(ret==0 && search==BOOK){
\r
843 fprintf(info->output,"%d: ",info->line);
\r
845 fprintf(info->output,"\n");
\r
848 ret=1; // end of line book move counts for 1
\r
851 ASSERT(info->height>=0);
\r
857 void init_info(info_t *info){
\r
861 info->initial_color=White;
\r
862 info->book_trans_only=FALSE;
\r
866 // remove MoveNone entries from book and rebuild hash table
\r
868 int read_ptr,write_ptr;
\r
870 for(read_ptr=0;read_ptr<Book->size;read_ptr++){
\r
871 if(Book->entry[read_ptr].move!=MoveNone){
\r
872 Book->entry[write_ptr++]=Book->entry[read_ptr];
\r
875 Book->size=write_ptr;
\r
876 rebuild_hash_table();
\r
881 void book_dump(int argc, char * argv[]) {
\r
882 const char * bin_file=NULL;
\r
883 const char * txt_file=NULL;
\r
884 char string[StringSize];
\r
885 int color=ColourNone;
\r
890 my_string_set(&bin_file,"book.bin");
\r
891 for (i = 1; i < argc; i++) {
\r
893 } else if (my_string_equal(argv[i],"dump-book")) {
\r
895 } else if (my_string_equal(argv[i],"-bin")) {
\r
897 if (i==argc) my_fatal("book_dump(): missing argument\n");
\r
898 my_string_set(&bin_file,argv[i]);
\r
899 } else if (my_string_equal(argv[i],"-out")) {
\r
901 if (i==argc) my_fatal("book_dump(): missing argument\n");
\r
902 my_string_set(&txt_file,argv[i]);
\r
903 } else if (my_string_equal(argv[i],"-color") || my_string_equal(argv[i],"-colour")) {
\r
905 if (i == argc) my_fatal("book_dump(): missing argument\n");
\r
906 if(my_string_equal(argv[i],"white")){
\r
908 }else if (my_string_equal(argv[i],"black")){
\r
911 my_fatal("book_dump(): unknown color \"%s\"\n",argv[i]);
\r
914 my_fatal("book_dump(): unknown option \"%s\"\n",argv[i]);
\r
917 if(color==ColourNone){
\r
918 my_fatal("book_dump(): you must specify a color\n");
\r
920 if(txt_file==NULL){
\r
921 snprintf(string,StringSize,"book_%s.txt",color?"white":"black");
\r
922 my_string_set(&txt_file,string);
\r
926 if(!Quiet){printf("loading book ...\n");}
\r
927 book_load(bin_file);
\r
928 board_start(board);
\r
930 info->initial_color=color;
\r
931 if(!(f=fopen(txt_file,"w"))){
\r
932 my_fatal("book_dump(): can't open file \"%s\" for writing: %s",
\r
933 txt_file,strerror(errno));
\r
936 fprintf(info->output,"Dump of \"%s\" for %s.\n",
\r
937 bin_file,color==White?"white":"black");
\r
939 if(!Quiet){printf("generating lines for white...\n");}
\r
940 search_book(board,info, BOOK);
\r
942 if(!Quiet){printf("generating lines for black...\n");}
\r
943 search_book(board,info, ALL);
\r
949 void book_info(int argc,char* argv[]){
\r
950 const char *bin_file=NULL;
\r
955 int white_pos,black_pos,total_pos,white_pos_extended,
\r
956 black_pos_extended,white_pos_extended_diff,black_pos_extended_diff;
\r
958 bool extended_search=FALSE;
\r
961 my_string_set(&bin_file,"book.bin");
\r
963 for (i = 1; i < argc; i++) {
\r
965 } else if (my_string_equal(argv[i],"info-book")) {
\r
967 } else if (my_string_equal(argv[i],"-bin")) {
\r
969 if (i==argc) my_fatal("book_info(): missing argument\n");
\r
970 my_string_set(&bin_file,argv[i]);
\r
971 } else if (my_string_equal(argv[i],"-exact")) {
\r
972 extended_search=TRUE;
\r
974 my_fatal("book_info(): unknown option \"%s\"\n",argv[i]);
\r
978 if(!Quiet){printf("loading book ...\n");}
\r
979 book_load(bin_file);
\r
982 board_start(board);
\r
984 info->book_trans_only=FALSE;
\r
985 info->initial_color=White;
\r
986 info->extended_search=FALSE;
\r
987 search_book(board,info, BOOK);
\r
988 printf("Lines for white : %8d\n",info->line-1);
\r
993 info->initial_color=Black;
\r
995 ASSERT(Book->size==s);
\r
996 board_start(board);
\r
997 search_book(board,info, ALL);
\r
998 printf("Lines for black : %8d\n",info->line-1);
\r
1001 ASSERT(Book->size==s);
\r
1006 for(pos=0;pos<Book->size;pos++){
\r
1007 if(Book->entry[pos].key==last_key){
\r
1008 ASSERT(Book->entry[pos].colour==ColourNone);
\r
1011 last_key=Book->entry[pos].key;
\r
1013 if(Book->entry[pos].colour==White){
\r
1015 }else if(Book->entry[pos].colour==Black){
\r
1019 printf("Positions on lines for white : %8d\n",white_pos);
\r
1020 printf("Positions on lines for black : %8d\n",black_pos);
\r
1023 if(extended_search){
\r
1025 info->book_trans_only=TRUE;
\r
1026 info->initial_color=White;
\r
1027 info->extended_search=TRUE;
\r
1029 board_start(board);
\r
1030 search_book(board,info, BOOK);
\r
1033 info->book_trans_only=TRUE;
\r
1034 info->initial_color=Black;
\r
1035 info->extended_search=TRUE;
\r
1037 board_start(board);
\r
1038 search_book(board,info, ALL);
\r
1040 ASSERT(Book->size==s);
\r
1041 white_pos_extended=0;
\r
1042 black_pos_extended=0;
\r
1044 for(pos=0;pos<Book->size;pos++){
\r
1045 if(Book->entry[pos].key==last_key){
\r
1046 ASSERT(Book->entry[pos].colour==ColourNone);
\r
1049 last_key=Book->entry[pos].key;
\r
1050 if(Book->entry[pos].colour==White){
\r
1051 white_pos_extended++;
\r
1052 }else if(Book->entry[pos].colour==Black){
\r
1053 black_pos_extended++;
\r
1056 white_pos_extended_diff=white_pos_extended-white_pos;
\r
1057 black_pos_extended_diff=black_pos_extended-black_pos;
\r
1058 printf("Unreachable white positions(?) : %8d\n",
\r
1059 white_pos_extended_diff);
\r
1060 printf("Unreachable black positions(?) : %8d\n",
\r
1061 black_pos_extended_diff);
\r
1064 if(extended_search){
\r
1065 printf("Isolated positions : %8d\n",
\r
1066 total_pos-white_pos_extended-black_pos_extended);
\r
1068 printf("Isolated positions : %8d\n",
\r
1069 total_pos-white_pos-black_pos);
\r
1075 // end of book_make.cpp
\r