Removed killer, just use history. small cleanup.
[rattatechess.git] / board_defs.h
blob904b403a257e715e69d9de92c1b6e1a21ab985a9
1 /***************************************************************************
2 board_defs.h - Board related definitions
3 -------------------
4 begin : Sun Nov 28 2007
5 copyright : (C) 2007 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #ifndef __BOARD_DEFS_H__
19 #define __BOARD_DEFS_H__
22 #define INF 30000
25 /*******************************************************************************
26 the chessboard is a 16x8 arrays, and is accessed with 1-byte indices
27 whose binary form look like: 0yyy0xxx
28 where xxx and yyy are 3bits (0 ... 7) that store the x and y coords.
29 The 4th and 8th bits are 0 if the index is valid, so an invalid (out
30 of board) index can be detected testing with 10001000 (0x88)
32 Chess pieces. Keep these numbers because in a few place it is useful to be
33 able to assume that QUEEN=ROOK|BISHOP, ie if you want to test if a piece
34 moves diagonally you have just to test (piece&(~ROOK) == BISHOP)
35 *******************************************************************************/
36 #define ROOK 1
37 #define BISHOP 2
38 #define QUEEN 3
39 #define KNIGHT 4
40 #define PAWN 5
41 #define KING 6
43 #define STONE ((uint8_t)0xff)
44 #define ENDL 0,0,0,0,0,0,0,0
45 #define SENDL STONE,STONE,STONE,STONE,STONE,STONE,STONE,STONE
47 #define INVALID ((uint8_t)0xff)
49 // color bits
50 #define WHITE ((uint8_t)0x80)
51 #define BLACK ((uint8_t)0x40)
53 // flags to mark pinning information
54 #define NFREE ((uint8_t)0x20)
55 #define CLFREE ((~NFREE)+(~(NFREE<<8))+(~(NFREE<<16))+(~(NFREE<<24)))
56 #define DIAG ((uint8_t)0x80)
57 #define COLM ((uint8_t)0x40)
59 // define directions
60 #define UP ((uint8_t)0x10)
61 #define DOWN ((uint8_t)0xf0)
62 #define RIGHT ((uint8_t)0x01)
63 #define LEFT ((uint8_t)0xff)
65 #define RIGHT_OF(a) ((uint8_t)(RIGHT+a))
66 #define LEFT_OF(a) ((uint8_t)(LEFT+a))
67 #define UP_OF(a) ((uint8_t)(UP+a))
68 #define DOWN_OF(a) ((uint8_t)(DOWN+a))
69 #define RIGHTUP_OF(a) ((uint8_t)(RIGHT+UP+a))
70 #define LEFTUP_OF(a) ((uint8_t)(LEFT+UP+a))
71 #define RIGHTDOWN_OF(a) ((uint8_t)(RIGHT+DOWN+a))
72 #define LEFTDOWN_OF(a) ((uint8_t)(LEFT+DOWN+a))
74 // macros to work with 1-byte coordinates
75 #define POS_XY(x,y) ((uint8_t)((y)<<4)+(x))
76 #define OTHER_COLOR(a) (((uint8_t)0xc0) - (a))
77 #define IS_OF_COLOR(a,c) ((a) & (c))
78 #define COLOR_OF(a) (((uint8_t)0xc0) & (a))
79 #define PIECE_OF(a) (((uint8_t)0x0f) & (a))
80 #define ROW_OF(a) (a & ((uint8_t)0xf0))
81 #define COL_OF(a) (a & ((uint8_t)0x0f))
82 #define Y(a) ((uint8_t)(((a) & ((uint8_t)0xf0))>>4))
83 #define X(a) ((a) & ((uint8_t)0x0f))
84 #define CAN_MOVE(a) (! ((a) & NFREE))
85 #define IS_VOID(a) (!(a))
86 #define IS_PIECE(a,b) (((a) & ((uint8_t)0x0f)) ==(b))
87 #define OUT_OF_BOARD(a) ((a) & ((uint8_t)0x88))
88 #define IS_WHITE(a) ((uint8_t)((a)>>7))
89 #define PIECE_TO_12(p) ({uint8_t _p = (p); uint8_t _r = PIECE_OF(_p)-1 + 6*IS_WHITE(_p);ASSERT(_r<12);_r;})
90 #define SQUARE_TO_64(s) ({uint8_t _s = (s); ASSERT(!OUT_OF_BOARD(_s)); X(_s) + (Y(_s)<<3);})
91 #define SQUARE_FROM_64(s) ({uint8_t _s = (s); (0x07&_s) + ((0x38&_s)<<1);})
92 #define DISTANCE(a, b) ({int _x = X(a)-X(b); int _y = Y(a)-Y(b); MAX(ABS(_x), ABS(_y));})
93 #define DISTANCE_2(a, b) ({int _x = X(a)-X(b); int _y = Y(a)-Y(b); _x*_x + _y*_y;})
95 // flag of the move (flags) field to store
96 // if the move is en-passant, castle, a pawn 2-push or a promotion
97 #define ENPASSANT 1
98 #define CASTLEKINGSIDE 2
99 #define CASTLEQUEENSIDE 3
100 #define PAWNOF2 4
101 #define PROMOTE0 4
102 #define PROMOTE_FIRST 5
103 #define PROMOTEROOK (ROOK+4)
104 #define PROMOTEBISHOP (BISHOP+4)
105 #define PROMOTEQUEEN (QUEEN+4)
106 #define PROMOTEKNIGHT (KNIGHT+4)
107 #define PROMOTE_LAST 8
109 //flags of the castle-passing mask
110 #define NOT_PASSING ((uint8_t)0x08)
111 #define WCANCASTLEKS ((uint8_t)0x10)
112 #define WCANCASTLEQS ((uint8_t)0x20)
113 #define BCANCASTLEKS ((uint8_t)0x40)
114 #define BCANCASTLEQS ((uint8_t)0x80)
116 /* 0 -> 11 pieces representation */
117 #define BR_12 0
118 #define BB_12 1
119 #define BQ_12 2
120 #define BN_12 3
121 #define BP_12 4
122 #define BK_12 5
123 #define WR_12 6
124 #define WB_12 7
125 #define WQ_12 8
126 #define WN_12 9
127 #define WP_12 10
128 #define WK_12 11
130 // pieces shorcuts
131 #define __ 0
132 #define WN WHITE|KNIGHT
133 #define WB WHITE|BISHOP
134 #define WR WHITE|ROOK
135 #define WP WHITE|PAWN
136 #define WQ WHITE|QUEEN
137 #define WK WHITE|KING
138 #define BN BLACK|KNIGHT
139 #define BB BLACK|BISHOP
140 #define BR BLACK|ROOK
141 #define BP BLACK|PAWN
142 #define BQ BLACK|QUEEN
143 #define BK BLACK|KING
145 /* define chess squares values */
146 #define A1 POS_XY(0,0)
147 #define A2 POS_XY(0,1)
148 #define A3 POS_XY(0,2)
149 #define A4 POS_XY(0,3)
150 #define A5 POS_XY(0,4)
151 #define A6 POS_XY(0,5)
152 #define A7 POS_XY(0,6)
153 #define A8 POS_XY(0,7)
154 #define B1 POS_XY(1,0)
155 #define B2 POS_XY(1,1)
156 #define B3 POS_XY(1,2)
157 #define B4 POS_XY(1,3)
158 #define B5 POS_XY(1,4)
159 #define B6 POS_XY(1,5)
160 #define B7 POS_XY(1,6)
161 #define B8 POS_XY(1,7)
162 #define C1 POS_XY(2,0)
163 #define C2 POS_XY(2,1)
164 #define C3 POS_XY(2,2)
165 #define C4 POS_XY(2,3)
166 #define C5 POS_XY(2,4)
167 #define C6 POS_XY(2,5)
168 #define C7 POS_XY(2,6)
169 #define C8 POS_XY(2,7)
170 #define D1 POS_XY(3,0)
171 #define D2 POS_XY(3,1)
172 #define D3 POS_XY(3,2)
173 #define D4 POS_XY(3,3)
174 #define D5 POS_XY(3,4)
175 #define D6 POS_XY(3,5)
176 #define D7 POS_XY(3,6)
177 #define D8 POS_XY(3,7)
178 #define E1 POS_XY(4,0)
179 #define E2 POS_XY(4,1)
180 #define E3 POS_XY(4,2)
181 #define E4 POS_XY(4,3)
182 #define E5 POS_XY(4,4)
183 #define E6 POS_XY(4,5)
184 #define E7 POS_XY(4,6)
185 #define E8 POS_XY(4,7)
186 #define F1 POS_XY(5,0)
187 #define F2 POS_XY(5,1)
188 #define F3 POS_XY(5,2)
189 #define F4 POS_XY(5,3)
190 #define F5 POS_XY(5,4)
191 #define F6 POS_XY(5,5)
192 #define F7 POS_XY(5,6)
193 #define F8 POS_XY(5,7)
194 #define G1 POS_XY(6,0)
195 #define G2 POS_XY(6,1)
196 #define G3 POS_XY(6,2)
197 #define G4 POS_XY(6,3)
198 #define G5 POS_XY(6,4)
199 #define G6 POS_XY(6,5)
200 #define G7 POS_XY(6,6)
201 #define G8 POS_XY(6,7)
202 #define H1 POS_XY(7,0)
203 #define H2 POS_XY(7,1)
204 #define H3 POS_XY(7,2)
205 #define H4 POS_XY(7,3)
206 #define H5 POS_XY(7,4)
207 #define H6 POS_XY(7,5)
208 #define H7 POS_XY(7,6)
209 #define H8 POS_XY(7,7)
211 #endif //__BOARD_DEFS_H__