Cute Chess 0.1
tbcore.h
1/*
2 Copyright (c) 2011-2015 Ronald de Man
3*/
4
5#ifndef TBCORE_H
6#define TBCORE_H
7
8#ifndef _WIN32
9#include <pthread.h>
10#define SEP_CHAR ':'
11#define FD int
12#define FD_ERR -1
13#else
14#include <windows.h>
15#define SEP_CHAR ';'
16#define FD HANDLE
17#define FD_ERR INVALID_HANDLE_VALUE
18#endif
19
20#ifdef TB_HAVE_THREADS
21#ifndef _WIN32
22#define LOCK_T pthread_mutex_t
23#define LOCK_INIT(x) pthread_mutex_init(&(x), NULL)
24#define LOCK(x) pthread_mutex_lock(&(x))
25#define UNLOCK(x) pthread_mutex_unlock(&(x))
26#else
27#define LOCK_T HANDLE
28#define LOCK_INIT(x) do { x = CreateMutex(NULL, FALSE, NULL); } while (0)
29#define LOCK(x) WaitForSingleObject(x, INFINITE)
30#define UNLOCK(x) ReleaseMutex(x)
31#endif
32#else /* !TB_HAVE_THREADS */
33#define LOCK_T int
34#define LOCK_INIT(x) /* NOP */
35#define LOCK(x) /* NOP */
36#define UNLOCK(x) /* NOP */
37#endif
38
39#define WDLSUFFIX ".rtbw"
40#define DTZSUFFIX ".rtbz"
41#define WDLDIR "RTBWDIR"
42#define DTZDIR "RTBZDIR"
43#define TBPIECES 6
44
45#define WDL_MAGIC 0x5d23e871
46#define DTZ_MAGIC 0xa50c66d7
47
48#define TBHASHBITS 10
49
50typedef unsigned long long uint64;
51typedef unsigned int uint32;
52typedef unsigned char ubyte;
53typedef unsigned short ushort;
54
55struct TBHashEntry;
56
57#ifdef DECOMP64
58typedef uint64 base_t;
59#else
60typedef uint32 base_t;
61#endif
62
63struct PairsData {
64 char *indextable;
65 ushort *sizetable;
66 ubyte *data;
67 ushort *offset;
68 ubyte *symlen;
69 ubyte *sympat;
70 int blocksize;
71 int idxbits;
72 int min_len;
73 base_t base[1]; // C++ complains about base[]...
74};
75
76struct TBEntry {
77 char *data;
78 uint64 key;
79 uint64 mapping;
80 ubyte ready;
81 ubyte num;
82 ubyte symmetric;
83 ubyte has_pawns;
84}
85#ifdef __GNUC__
86__attribute__((__may_alias__));
87#else
88;
89#endif
90
92 char *data;
93 uint64 key;
94 uint64 mapping;
95 ubyte ready;
96 ubyte num;
97 ubyte symmetric;
98 ubyte has_pawns;
99 ubyte enc_type;
100 struct PairsData *precomp[2];
101 int factor[2][TBPIECES];
102 ubyte pieces[2][TBPIECES];
103 ubyte norm[2][TBPIECES];
104};
105
107 char *data;
108 uint64 key;
109 uint64 mapping;
110 ubyte ready;
111 ubyte num;
112 ubyte symmetric;
113 ubyte has_pawns;
114 ubyte pawns[2];
115 struct {
116 struct PairsData *precomp[2];
117 int factor[2][TBPIECES];
118 ubyte pieces[2][TBPIECES];
119 ubyte norm[2][TBPIECES];
120 } file[4];
121};
122
124 char *data;
125 uint64 key;
126 uint64 mapping;
127 ubyte ready;
128 ubyte num;
129 ubyte symmetric;
130 ubyte has_pawns;
131 ubyte enc_type;
132 struct PairsData *precomp;
133 int factor[TBPIECES];
134 ubyte pieces[TBPIECES];
135 ubyte norm[TBPIECES];
136 ubyte flags; // accurate, mapped, side
137 ushort map_idx[4];
138 ubyte *map;
139};
140
142 char *data;
143 uint64 key;
144 uint64 mapping;
145 ubyte ready;
146 ubyte num;
147 ubyte symmetric;
148 ubyte has_pawns;
149 ubyte pawns[2];
150 struct {
151 struct PairsData *precomp;
152 int factor[TBPIECES];
153 ubyte pieces[TBPIECES];
154 ubyte norm[TBPIECES];
155 } file[4];
156 ubyte flags[4];
157 ushort map_idx[4][4];
158 ubyte *map;
159};
160
162 uint64 key;
163 struct TBEntry *ptr;
164};
165
167 uint64 key1;
168 uint64 key2;
169 struct TBEntry *entry;
170};
171
172#endif
173
Definition tbcore.h:141
Definition tbcore.h:123
Definition tbcore.h:166
Definition tbcore.h:63
Definition tbcore.h:106
Definition tbcore.h:91
Definition tbcore.h:76
Definition tbcore.h:161