Modified king attacks
[owl.git] / common.h
blob69561b15a5c7d6ab00ac60847f12852f382f563a
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 #include <assert.h>
17 #include <errno.h>
18 #include <inttypes.h>
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sys/time.h>
24 #include <unistd.h>
26 enum COLOR {NOBODY = -1, WHITE = 0, BLACK = 1};
27 enum PIECES {NONE, PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING};
28 enum SQUARES64 {
29 A1, B1, C1, D1, E1, F1, G1, H1,
30 A2, B2, C2, D2, E2, F2, G2, H2,
31 A3, B3, C3, D3, E3, F3, G3, H3,
32 A4, B4, C4, D4, E4, F4, G4, H4,
33 A5, B5, C5, D5, E5, F5, G5, H5,
34 A6, B6, C6, D6, E6, F6, G6, H6,
35 A7, B7, C7, D7, E7, F7, G7, H7,
36 A8, B8, C8, D8, E8, F8, G8, H8 };
38 #define TRUE 1
39 #define FALSE 0
41 #define MAX_STRING 2048
43 #define MAX_PLY 64
45 #define OPENING 0
46 #define ENDGAME 1
48 #define MAX(a, b) ((a) > (b) ? (a) : (b))
49 #define MIN(a, b) ((a) < (b) ? (a) : (b))
51 #define _FILE(x) ((x) & 7)
52 #define _RANK(x) ((x) >> 3)
54 #define ZERO_MEM(x) (memset (&(x), 0, sizeof (x)))
56 #define MATE_VALUE 30000
57 #define SCORE_IS_MATE(x) ((x) > MATE_VALUE - 512 || (x) < -MATE_VALUE + 512)
59 /* simple bit operations */
60 #define BIT(x) (1ULL << (x))
61 #define SET(bb, i) ((bb) |= BIT(i))
62 #define CLEAR(bb, i) ((bb) &= ~BIT(i))
64 #define _RANK1 0x00000000000000FFULL
65 #define _RANK2 0x000000000000FF00ULL
66 #define _RANK7 0x00FF000000000000ULL
67 #define _RANK8 0xFF00000000000000ULL
69 #define WHITESQUARES 0x55AA55AA55AA55AAULL
70 #define BLACKSQUARES 0xAA55AA55AA55AA55ULL
72 #define GAME_PHASE MAX((256 - (material_pieces[WHITE] + \
73 material_pieces[BLACK]) / e.phase_factor), 0)
75 /* global data */
76 extern char program_name[MAX_STRING];
78 /* zobrist hash */
79 extern uint64_t hash_wck;
80 extern uint64_t hash_wcq;
81 extern uint64_t hash_bck;
82 extern uint64_t hash_bcq;
83 extern uint64_t hash_code[2][7][64];
84 extern uint64_t hash_ep[8];
85 extern uint64_t hash_side;
87 extern uint64_t *p_hash_piece;
88 extern uint64_t *p_hash_castle;
89 extern uint64_t *p_hash_ep;
90 extern uint64_t *p_hash_side;
92 /* Bitwise operations */
93 extern int bitcount[65536];
95 int bit_scan(uint64_t b);
96 int bit_scan_clear(uint64_t *b);
97 int bit_scan_rev(uint64_t b);
98 static inline int popcount(uint64_t b)
100 return (bitcount[(b) >> 48] + bitcount[((b) >> 32) & 0xffff] + \
101 bitcount[((b) >> 16) & 0xffff] + bitcount[(b) & 0xffff]);