-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefines.h
163 lines (131 loc) · 4.8 KB
/
defines.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef __DEFINES_H__
#define __DEFINES_H__
#include <stddef.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
/* Config file name, without the directory. The file is assumed to reside in the colibri/ installation directory. */
#define CONFIG_FILE "colibri.conf"
/* Sides */
#define WHITE 0
#define BLACK 1
/* Piece types */
#define PAWN 1
#define KNIGHT 2
#define BISHOP 3
#define ROOK 4
#define QUEEN 5
#define KING 6
/* Order of bitboards in a board */
/* The intervals BB_WALL - BB_WK and BB_BALL - BB_BK need to stay contiguous because makeMove depends on it. */
#define BB_WALL 0
#define BB_WP 1
#define BB_WN 2
#define BB_WB 3
#define BB_WR 4
#define BB_WQ 5
#define BB_WK 6
#define BB_BALL 7
#define BB_BP 8
#define BB_BN 9
#define BB_BB 10
#define BB_BR 11
#define BB_BQ 12
#define BB_BK 13
#define BB_EMPTY 14
#define BB_EP 15
#define BB_COUNT 16
/*
* Possible transformations. The first two apply to all boards; the other six
* only apply to boards without pawns.
*/
#define TR_NONE 0 /* c1 -> c1 */
#define TR_FLIP_EW 1 /* c1 -> f1 */
#define TR_ROT_CCW 2 /* c1 -> h3 */
#define TR_ROT_180 3 /* c1 -> f8 */
#define TR_ROT_CW 4 /* c1 -> a6 */
#define TR_FLIP_NS 5 /* c1 -> c8 */
#define TR_FLIP_DIAG 6 /* c1 -> a3 */
#define TR_FLIP_ANTIDIAG 7 /* c1 -> h6 */
/* Masks for some ranks and files of interest */
#define FILE_A 0x0101010101010101ull
#define FILE_B 0x0202020202020202ull
#define FILE_H 0x8080808080808080ull
#define RANK_1 0x00000000000000ffull
#define RANK_3 0x0000000000ff0000ull
#define RANK_4 0x00000000ff000000ull
#define RANK_5 0x000000ff00000000ull
#define RANK_6 0x0000ff0000000000ull
#define RANK_8 0xff00000000000000ull
/* For assorted purposes */
#define INFTY 1000000000
#define INFTY64 1000000000000000000ull
/* NULL-like value for statically allocated lists */
#define NIL 1000000000
/* If a bitboard is mutiplied by FILE_MAGIC, all the bits on the 'a' file will end up on the 8-th rank. */
#define FILE_MAGIC 0x8040201008040201ull
/* If a diagonal is mutiplied by DIAG_MAGIC, all the bits on the diagonal will end up on the 8-th rank. */
#define DIAG_MAGIC 0x0101010101010101ull
/* The board at the start of a new game */
#define NEW_BOARD "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w - - 0 1"
/* Clears the rightmost set bit of x and returns its index in square */
#define GET_BIT_AND_CLEAR(x, square) \
square = ctz(x); \
x &= x - 1;
/* Maximum number of legal moves in a position */
#define MAX_MOVES 200
/* Maximum number of pieces in the endgame tables */
#define EGTB_MEN 5
#define EGTB_UNKNOWN 1000000000
/* Directions of move generation. BACKWARD is used for retrograde analysis during EGTB generation */
#define FORWARD true
#define BACKWARD false
/* Cache EGTB files in 32 KB chunks */
#define EGTB_CHUNK_SIZE 32768
/* The square between 0 and 63 corresponding to a rank and file between 0 and 7 */
#define SQUARE(rank, file) (((rank) << 3) + (file))
/* The 64-bit mask corresponding to a rank and file between 0 and 7 */
#define BIT(rank, file) (1ull << (((rank) << 3) + (file)))
/* Return a square given its algebraic coordinates, e.g. "a1" -> 0, "h8" -> 63 */
#define SQUARE_BY_NAME(s) ((((s).at(1) - '1') << 3) + ((s).at(0) - 'a'))
/* Return a 1-character string naming the file (column) of the given square */
#define FILE_NAME(sq) (string(1, 'a' + (sq & 7)))
/* Return a 1-character string naming the rank (row) of the given square */
#define RANK_NAME(sq) (string(1, '1' + (sq >> 3)))
/* Return a 2-character string naming the given square */
#define SQUARE_NAME(sq) (FILE_NAME(sq) + RANK_NAME(sq))
#define MIN(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
/* Commands given from the command line */
#define CMD_ANALYZE 1
#define CMD_SERVER 2
typedef unsigned long long u64;
typedef unsigned short u16;
typedef unsigned char byte;
typedef struct {
u64 bb[BB_COUNT]; /* One bitboard for every BB_* property above */
bool side; /* Side to move */
} Board;
/* There is some redundancy in our Move structure. The aim is not to save space, since we don't store moves during our algorithms.
* The aim is to print moves easily. */
typedef struct {
byte piece; /* Type of piece being moved */
byte from; /* Square of origin */
byte to; /* Destination square */
byte promotion; /* Promotion, if any */
} Move;
/* For EGTB, use PieceSet's in the order in which they are placed on the board */
typedef struct {
bool side;
byte piece;
byte count;
} PieceSet;
/* Piece names for move notation */
const char PIECE_INITIALS[8] = " PNBRQK";
const int PIECE_BY_NAME[26] = { 0, BISHOP, 0, 0, 0, 0, 0, 0, 0, 0, KING, 0, 0, KNIGHT, 0, PAWN, QUEEN, ROOK, 0, 0, 0, 0, 0, 0, 0, 0 };
inline int sgn(long long x) {
return (x > 0) - (x < 0);
}
#endif