00001 /*********************************************************************************** 00002 * Filename $RCSfile: alg1_book.h,v $ 00003 * Current CVS $Revision: 1.10 $ 00004 * Checked-in by $Author: yves $ 00005 * 00006 * $Log: alg1_book.h,v $ 00007 * Multiple updates to version 0.2.8 00008 * 00009 * Revision 1.8 2004/12/24 01:25:33 yves 00010 * Opening book in binary mode implemented. 00011 * Version 0.2.6 00012 * 00013 * speedup in book reading 00014 * opening book implemented 00015 * 00016 * Revision 1.4 2004/12/16 00:18:24 yves 00017 * Standard CVS command tags added 00018 * FEN notation inverted, now uppercase is white and lowercase is black 00019 * 00020 * 00021 ***********************************************************************************/ 00022 00023 #if !defined(__ALG1_BOOK_H__) 00024 #define __ALG1_BOOK_H__ 00025 00026 #include "belofte.h" 00027 00028 /** CHBK 00029 * following string is represented as HEX, if the book is created on a little-endian machine, 00030 * it will be invalid on a big-endian machine because the byte ordering will be different 00031 */ 00032 00033 #define BOOKID 0x4348424B 00034 00035 /** each time we alter the book size, we change the version 00036 */ 00037 #define BOOKVERSION 2 00038 00039 /** 00040 * the branch size is 30 bytes times the branching factor (20) 00041 * ( the book size is the 136 plus the branch size ) times the book size 00042 * a value of book-size of 700000 will occupy appoximately 512 MB 00043 */ 00044 #define BOOK_DEPTH 30 00045 #define SIZE_BRANCH 20 00046 #define SIZE_BOOK 200000 00047 00048 // a lot is to be gained in size by storing the move as 2 bytes (from and to) 00049 // and limiting the counters to 24 bits (16 million positions) 00050 // and limiting the number of branches to e.g. 10-12 00051 // then the size of a position can be brought down to one third at least 00052 00053 // -------------------------------------------------------------------- 00054 00055 struct st_book_move { // single book move entry 00056 char szMove[MAX_MOVE_LENGTH]; // the move 00057 int nOccurence; // number of times this is played 00058 int nWhiteWin; // number of times white won 00059 int nBlackWin; // number of times black won 00060 int nDraw; // number of times the score was draw 00061 int nMovesAfter; // the number of moves that were played after this move 00062 // this is total, all games together, to indicate the purity of the score 00063 }; 00064 00065 struct st_book_pos { // Opening book entry 00066 char szFen[MAX_FEN_LENGTH]; // the identifier 00067 int nOccurence; // number of times this is in the opening book 00068 int iMoves; // number of moves stored 00069 struct st_book_move m_move[SIZE_BRANCH]; // each move 00070 }; 00071 00072 struct st_book { 00073 long szBookID; // some magic number to identify BIG or LITTLE ENDIAN when loading binary book 00074 long iBookVersion; // support different versions 00075 long iBookSize; // control digit for the number of book positions 00076 char szBookDate[14]; // date of last modification in the book YYYYMMDDHHMMSS 00077 long liBookUsedPositions; // number of used positions in the book 00078 long iLeaves; // total number of leaves 00079 struct st_book_pos pos[SIZE_BOOK]; // array of positions 00080 }; 00081 00082 // -------------------------------------------------------------------- 00083 00084 #define BOOKRESULT_UNKNOWN -1 00085 #define BOOKRESULT_DRAW 0 00086 #define BOOKRESULT_WHITEWON 1 00087 #define BOOKRESULT_BLACKWON 2 00088 00089 // -------------------------------------------------------------------- 00090 00091 void book_load(const char *szBinFileName); 00092 void book_save(const char *szBinFileName); 00093 void book_create(const char *szInputFileName, const char *szBinFileName); 00094 00095 int book_move(const char *szFen,char *szMove); 00096 void book_listmoves(const char *szFen, const t_boolean bShowFen); 00097 00098 // -------------------------------------------------------------------- 00099 00100 #endif 00101