Replace constant '-1' to NOBODY for side to move
[owl.git] / board.h
blobfc35bbb3eff21716ef596ff7cdb2b7cc722f805b
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 r_pieces[2];
62 extern uint64_t side_boards[2];
64 extern int castled[2];
66 extern int material_complete[2];
67 extern int material_pawns[2];
68 extern int material_pieces[2];
70 extern int piece_value[7];
71 extern int piece_count[2][7];
73 /* functions */
74 void add_piece(int square, int piece, int side);
75 void calc_zobrist(uint64_t *hash_key, uint64_t *hash_pawn_key);
76 char *current_fen_position(char *buf);
77 void remove_piece(int square, int piece, int side);
78 int reps(void);
79 int SEE(int move);
80 int setup_board(char *fen);
81 void update_boards(void);
83 /* debuging functions */
84 int board_is_legal(struct board_t *b);
85 void print_bb(uint64_t b);
86 void print_board(void);
88 /* some defines for simplicity only */
89 #define PAWNS(side) (piece_boards[side][PAWN])
90 #define KNIGHTS(side) (piece_boards[side][KNIGHT])
91 #define BISHOPS(side) (piece_boards[side][BISHOP])
92 #define ROOKS(side) (piece_boards[side][ROOK])
93 #define QUEENS(side) (piece_boards[side][QUEEN])
94 #define KING(side) (piece_boards[side][KING])
96 #define wpc piece_count[WHITE][PAWN]
97 #define bpc piece_count[BLACK][PAWN]
98 #define wnc piece_count[WHITE][KNIGHT]
99 #define bnc piece_count[BLACK][KNIGHT]
100 #define wbc piece_count[WHITE][BISHOP]
101 #define bbc piece_count[BLACK][BISHOP]
102 #define wrc piece_count[WHITE][ROOK]
103 #define brc piece_count[BLACK][ROOK]
104 #define wqc piece_count[WHITE][QUEEN]
105 #define bqc piece_count[BLACK][QUEEN]
107 /* evaluation of the position for material */
108 #define MATERIAL_SCORE (material_complete[brd.wtm] - material_complete[1 ^ brd.wtm])