search: move reductions
[owl.git] / common.h
blob5334009e075fd52bcd9f2c6129784031d992730d
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 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
30 enum COLOR {NOBODY = -1, WHITE = 0, BLACK = 1};
31 enum PIECES {NONE, PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING};
32 enum SQUARES64 {
33 A1, B1, C1, D1, E1, F1, G1, H1,
34 A2, B2, C2, D2, E2, F2, G2, H2,
35 A3, B3, C3, D3, E3, F3, G3, H3,
36 A4, B4, C4, D4, E4, F4, G4, H4,
37 A5, B5, C5, D5, E5, F5, G5, H5,
38 A6, B6, C6, D6, E6, F6, G6, H6,
39 A7, B7, C7, D7, E7, F7, G7, H7,
40 A8, B8, C8, D8, E8, F8, G8, H8 };
42 #define TRUE 1
43 #define FALSE 0
45 #define MAX_STRING 2048
47 #define MAX_PLY 64
49 #define OPENING 0
50 #define ENDGAME 1
52 #define MAX(a, b) ((a) > (b) ? (a) : (b))
53 #define MIN(a, b) ((a) < (b) ? (a) : (b))
55 #define _FILE(x) ((x) & 7)
56 #define _RANK(x) ((x) >> 3)
58 #define ZERO_MEM(x) (memset (&(x), 0, sizeof (x)))
60 #define MATE_VALUE 30000
61 #define SCORE_IS_MATE(x) ((x) > MATE_VALUE - 512 || (x) < -MATE_VALUE + 512)
63 /* simple bit operations */
64 #define BIT(x) (1ULL << (x))
65 #define SET(bb, i) ((bb) |= BIT(i))
66 #define CLEAR(bb, i) ((bb) &= ~BIT(i))
68 #define _RANK1 0x00000000000000FFULL
69 #define _RANK2 0x000000000000FF00ULL
70 #define _RANK7 0x00FF000000000000ULL
71 #define _RANK8 0xFF00000000000000ULL
73 #define WHITESQUARES 0x55AA55AA55AA55AAULL
74 #define BLACKSQUARES 0xAA55AA55AA55AA55ULL
76 #define GAME_PHASE MAX((256 - (material_pieces[WHITE] + \
77 material_pieces[BLACK]) / e.phase_factor), 0)
79 /* global data */
80 extern char program_name[MAX_STRING];
82 /* zobrist hash */
83 extern uint64_t hash_wck;
84 extern uint64_t hash_wcq;
85 extern uint64_t hash_bck;
86 extern uint64_t hash_bcq;
87 extern uint64_t hash_code[2][7][64];
88 extern uint64_t hash_ep[8];
89 extern uint64_t hash_side;
91 extern uint64_t *p_hash_piece;
92 extern uint64_t *p_hash_castle;
93 extern uint64_t *p_hash_ep;
94 extern uint64_t *p_hash_side;
96 /* Bitwise operations */
97 extern int bitcount[65536];
99 int bit_scan(uint64_t b);
100 int bit_scan_clear(uint64_t *b);
101 int bit_scan_rev(uint64_t b);
102 static inline int popcount(uint64_t b)
104 return (bitcount[(b) >> 48] + bitcount[((b) >> 32) & 0xffff] + \
105 bitcount[((b) >> 16) & 0xffff] + bitcount[(b) & 0xffff]);