evaluate: fixed bug in passed candidate evaluation
[owl.git] / board.h
blob2e0977c788f969caa341c4dc774b19fbe7119459
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 #define WHITE_CASTLE_KINGSIDE (1 << 0)
17 #define WHITE_CASTLE_QUEENSIDE (1 << 1)
18 #define BLACK_CASTLE_KINGSIDE (1 << 2)
19 #define BLACK_CASTLE_QUEENSIDE (1 << 3)
21 struct board_t {
22 int cap_piece; /* if we are capturing piece now */
23 int castle_mask; /* a mask of allowed castle moves */
24 int ep; /* enpassant target */
25 int kings[2]; /* kings locations */
26 int wtm; /* side to move */
27 int fifty_rule; /* number of moves after last capture or pawn
28 move */
29 int move; /* last move */
30 uint64_t hash_key; /* zobrist key */
31 uint64_t hash_pawn_key;
34 struct game_history_t {
35 int count;
36 struct board_t board[1024];
39 /* see board.c for comments */
40 extern const char *char_board[64];
41 extern const char char_pieces[7];
43 extern int bitcount[65536];
44 extern int lzArray[65536];
45 extern uint64_t isolated_mask[8];
46 extern uint64_t passer_mask[2][64];
47 extern uint64_t pawn_moves[2][64];
48 extern uint64_t piece_moves[7][64];
49 extern uint64_t forward_ray[2][64];
50 extern uint64_t king_shield[2][64];
52 extern int distance[64][64];
53 extern const uint64_t file_bit[8];
55 extern int square64[64];
56 extern struct board_t brd;
57 extern struct game_history_t game_history;
58 extern uint64_t complete;
60 extern uint64_t piece_boards[2][7];
61 extern uint64_t side_boards[2];
63 extern int castled[2];
65 extern int material_complete[2];
66 extern int material_pawns[2];
67 extern int material_pieces[2];
69 extern int piece_value[7];
70 extern int piece_count[2][7];
72 /* functions */
73 void add_piece(int square, int piece, int side);
74 void calc_zobrist(uint64_t *hash_key, uint64_t *hash_pawn_key);
75 char *current_fen_position(char *buf);
76 void remove_piece(int square, int piece, int side);
77 int reps(void);
78 int SEE(int move);
79 int setup_board(char *fen);
80 void update_boards(void);
82 /* debuging functions */
83 int board_is_legal(struct board_t *b);
84 void print_bb(uint64_t b);
85 void print_board(void);
87 /* some defines for simplicity only */
88 #define PAWNS(side) (piece_boards[side][PAWN])
89 #define KNIGHTS(side) (piece_boards[side][KNIGHT])
90 #define BISHOPS(side) (piece_boards[side][BISHOP])
91 #define ROOKS(side) (piece_boards[side][ROOK])
92 #define QUEENS(side) (piece_boards[side][QUEEN])
93 #define KING(side) (piece_boards[side][KING])
95 #define wpc piece_count[WHITE][PAWN]
96 #define bpc piece_count[BLACK][PAWN]
97 #define wnc piece_count[WHITE][KNIGHT]
98 #define bnc piece_count[BLACK][KNIGHT]
99 #define wbc piece_count[WHITE][BISHOP]
100 #define bbc piece_count[BLACK][BISHOP]
101 #define wrc piece_count[WHITE][ROOK]
102 #define brc piece_count[BLACK][ROOK]
103 #define wqc piece_count[WHITE][QUEEN]
104 #define bqc piece_count[BLACK][QUEEN]
106 /* evaluation of the position for material */
107 #define MATERIAL_SCORE (material_complete[brd.wtm] - material_complete[1 ^ brd.wtm])