Subversion Repositories Games.Chess Giants

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
99 pmbaty 1
/*
2
This Software is distributed with the following X11 License,
3
sometimes also known as MIT license.
4
 
5
Copyright (c) 2010 Miguel A. Ballicora
6
 
7
 Permission is hereby granted, free of charge, to any person
8
 obtaining a copy of this software and associated documentation
9
 files (the "Software"), to deal in the Software without
10
 restriction, including without limitation the rights to use,
11
 copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 copies of the Software, and to permit persons to whom the
13
 Software is furnished to do so, subject to the following
14
 conditions:
15
 
16
 The above copyright notice and this permission notice shall be
17
 included in all copies or substantial portions of the Software.
18
 
19
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26
 OTHER DEALINGS IN THE SOFTWARE.
27
*/
28
 
29
#if !defined(H_GTBPROBE)
30
#define H_GTBPROBE
31
#ifdef __cplusplus
32
extern "C" {
33
#endif
34
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
35
 
36
#include <stdlib.h>
37
 
38
#define tb_MAXPATHLEN 1024
39
 
40
/*----------------------------------*\
41
|            CONSTANTS
42
\*----------------------------------*/
43
 
44
enum TB_mask_values { tb_RESMASK = 3, tb_INFOMASK = 7, tb_PLYSHIFT = 3 };
45
 
46
enum TB_return_values {  
47
   tb_DRAW = 0,
48
   tb_WMATE = 1,
49
   tb_BMATE = 2,
50
   tb_FORBID = 3,
51
   tb_UNKNOWN = 7
52
};
53
 
54
enum TB_pieces    {
55
   tb_NOPIECE, tb_PAWN, tb_KNIGHT, tb_BISHOP, tb_ROOK, tb_QUEEN, tb_KING
56
};
57
 
58
enum TB_sides {
59
   tb_WHITE_TO_MOVE, tb_BLACK_TO_MOVE
60
};
61
 
62
enum TB_squares {
63
   tb_A1, tb_B1, tb_C1, tb_D1, tb_E1, tb_F1, tb_G1, tb_H1,
64
   tb_A2, tb_B2, tb_C2, tb_D2, tb_E2, tb_F2, tb_G2, tb_H2,
65
   tb_A3, tb_B3, tb_C3, tb_D3, tb_E3, tb_F3, tb_G3, tb_H3,
66
   tb_A4, tb_B4, tb_C4, tb_D4, tb_E4, tb_F4, tb_G4, tb_H4,
67
   tb_A5, tb_B5, tb_C5, tb_D5, tb_E5, tb_F5, tb_G5, tb_H5,
68
   tb_A6, tb_B6, tb_C6, tb_D6, tb_E6, tb_F6, tb_G6, tb_H6,
69
   tb_A7, tb_B7, tb_C7, tb_D7, tb_E7, tb_F7, tb_G7, tb_H7,
70
   tb_A8, tb_B8, tb_C8, tb_D8, tb_E8, tb_F8, tb_G8, tb_H8,
71
   tb_NOSQUARE
72
};
73
 
74
enum TB_castling {
75
   tb_NOCASTLE = 0,
76
   tb_WOO  = 8,
77
   tb_WOOO = 4,    
78
   tb_BOO  = 2,
79
   tb_BOOO = 1
80
};
81
 
82
enum TB_compression_scheme {
83
        tb_UNCOMPRESSED, tb_CP1, tb_CP2, tb_CP3, tb_CP4
84
};
85
 
86
/*----------------------------------*\
87
|               FUNCTIONS
88
\*----------------------------------*/
89
 
90
extern char *           tb_init   (int verbosity, int compression_scheme, const char **paths);
91
 
92
extern char *           tb_restart(int verbosity, int compression_scheme, const char **paths);
93
 
94
extern void                     tb_done (void);
95
 
96
extern int /*bool*/     tb_probe_hard
97
                                                        (unsigned stm,
98
                                                         unsigned epsq,
99
                                                         unsigned castles,
100
                                                         const unsigned *inp_wSQ,
101
                                                         const unsigned *inp_bSQ,
102
                                                         const unsigned char *inp_wPC,
103
                                                         const unsigned char *inp_bPC,
104
                                                         /*@out@*/ unsigned *tbinfo,
105
                                                         /*@out@*/ unsigned *plies);
106
 
107
extern int /*bool*/     tb_probe_soft
108
                                                        (unsigned stm,
109
                                                         unsigned epsq,
110
                                                         unsigned castles,
111
                                                         const unsigned *inp_wSQ,
112
                                                         const unsigned *inp_bSQ,
113
                                                         const unsigned char *inp_wPC,
114
                                                         const unsigned char *inp_bPC,
115
                                                         /*@out@*/ unsigned *tbinfo,
116
                                                         /*@out@*/ unsigned *plies);
117
 
118
extern int /*bool*/     tb_probe_WDL_hard
119
                                                        (unsigned stm,
120
                                                         unsigned epsq,
121
                                                         unsigned castles,
122
                                                         const unsigned *inp_wSQ,
123
                                                         const unsigned *inp_bSQ,
124
                                                         const unsigned char *inp_wPC,
125
                                                         const unsigned char *inp_bPC,
126
                                                         /*@out@*/ unsigned *tbinfo);
127
 
128
extern int /*bool*/     tb_probe_WDL_soft
129
                                                        (unsigned stm,
130
                                                         unsigned epsq,
131
                                                         unsigned castles,
132
                                                         const unsigned *inp_wSQ,
133
                                                         const unsigned *inp_bSQ,
134
                                                         const unsigned char *inp_wPC,
135
                                                         const unsigned char *inp_bPC,
136
                                                         /*@out@*/ unsigned *tbinfo);
137
 
138
extern int /*bool*/     tb_is_initialized (void);
139
 
140
/*      
141
|       tb_availability() returns 0 if no TBs available
142
|       Otherwise, the following bits are turned 'on' if...
143
|       ----------------------------------
144
|       bit: meaning
145
|       ----------------------------------
146
|       0: at least one 3-pc TB is present
147
|       1: 3-pc TBs are complete
148
|       2: at least one 4-pc TB is present
149
|       3: 4-pc TBs are complete
150
|       4: at least one 5-pc TB is present
151
|       5: 5-pc TBs are complete
152
|       6: at least one 6-pc TB is present
153
|       7: 6-pc TBs are complete
154
|       Example: if 63 is returned, it means all 3-4-5-pc TBs are present
155
|       Bits 6 and 7 will be always off, of course, until 6-piece TBs
156
|       are supported.
157
*/
158
 
159
extern unsigned int     tb_availability(void);
160
 
161
/*      
162
|       tb_indexmemory ()returns
163
|       how much memory has been allocated for indexes
164
*/
165
 
166
extern size_t           tb_indexmemory (void);
167
 
168
/*----------------------------------*\
169
|               cache
170
\*----------------------------------*/
171
 
172
extern int /*bool*/     tbcache_init    (size_t cache_mem, int wdl_fraction);
173
extern int /*bool*/     tbcache_restart (size_t cache_mem, int wdl_fraction);
174
extern void                     tbcache_done (void);
175
extern int /*bool*/     tbcache_is_on (void);
176
extern void                     tbcache_flush (void);
177
 
178
/*----------------------------------*\
179
|               STATS
180
\*----------------------------------*/
181
 
182
/*
183
|       For maximum portability, some stats are provided
184
|       in two 32 bits integers rather than a single 64 bit number.
185
|       For intance, prob_hard_hits[0] contains the less significant 32 bits
186
|       (0 to 31), and prob_hard_hits[1] the most significant ones (32 to 63).
187
|       The 64-bit number can be recreated like this:
188
|       uint64_t x;
189
|       x = (uint64_t)probe_hard_hits[0]|((uint64_t)probe_hard_hits[1]<<32);
190
|       The user has the responsibility to combine the numbers and use the
191
|       proper 64 bit integers.
192
*/
193
 
194
struct TB_STATS {
195
        long unsigned int wdl_easy_hits  [2]; /* hits that were found in own wdl cache */
196
        long unsigned int wdl_hard_prob  [2]; /* hard probes to the wdl cache: if fail, they will go to HD */
197
        long unsigned int wdl_soft_prob  [2]; /* soft probes to the wdl cache: if fail, they won't go to HD */ 
198
        size_t                    wdl_cachesize     ; /* size allocated for wdl cache */
199
        double                    wdl_occupancy     ; /* % of slots filled in wdl cache */
200
 
201
        long unsigned int dtm_easy_hits  [2]; /* hits that were found in own dtm cache */
202
        long unsigned int dtm_hard_prob  [2]; /* hard probes to the dtm cache: if fail, they will go to HD */
203
        long unsigned int dtm_soft_prob  [2]; /* soft probes to the dtm cache: if fail, they won't go to HD */ 
204
        size_t                    dtm_cachesize     ; /* size allocated for dtm cache */
205
        double                    dtm_occupancy     ; /* % of slots filled in dtm cache */
206
 
207
        long unsigned int  total_hits    [2]; /* succesful probes */
208
        long unsigned int memory_hits    [2]; /* succesful probes to memory */
209
        long unsigned int  drive_hits    [2]; /* succesful probes to the Hard drive */
210
        long unsigned int  drive_miss    [2]; /* failing   probes to the Hard drive */
211
        long unsigned int  bytes_read    [2]; /* bytes read from Hard drive */
212
        long unsigned int files_opened      ; /* number of files newly opened */
213
        double                    memory_efficiency ; /* % hits from memory over total hits */
214
};
215
 
216
extern void                     tbstats_reset (void);
217
extern void             tbstats_get (struct TB_STATS *stats);
218
 
219
 
220
/*----------------------------------*\
221
|               PATH MANAGEMENT
222
\*----------------------------------*/
223
 
224
extern const char **            tbpaths_init    (void);
225
extern const char **            tbpaths_add             (const char **ps, const char *newpath);
226
extern const char **            tbpaths_done    (const char **ps);
227
 
228
extern const char *                     tbpaths_getmain (void);
229
 
230
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
231
#ifdef __cplusplus
232
}
233
#endif
234
#endif