Alter Makefile to force 32-bit compile
[capablanca.git] / lasker-2.2.3 / src / board.h
1 /*
2    Copyright (c) 1993 Richard V. Nash.
3    Copyright (C) Andrew Tridgell 2002
4    
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20
21 #ifndef _BOARD_H
22 #define _BOARD_H
23
24 #define WHITE 0x00
25 #define BLACK 0x80
26 #define CString( c ) (  ((c) == WHITE) ? "White" : "Black" )
27 #define CToggle( c ) (  ((c) == BLACK) ? WHITE : BLACK )
28
29 /* These will go into an array */
30
31 #define NOPIECE 0
32 #define PAWN 1
33 #define KNIGHT 2
34 #define BISHOP 3
35 #define ROOK 4
36 #define CARDINAL 5
37 #define MARSHALL 6
38 #define MAN 7
39 #define QUEEN 8
40 #define ELEPHANT 9
41 #define ALFIL 10
42 #define FERZ 11
43 #define WAZIR 12
44 #define HORSE 13
45 #define HONORABLEHORSE 14
46 #define DRAGONKING 15
47 #define DRAGONHORSE 16
48 #define LANCE 17
49 #define CANNON 18
50 #define SILVER 19
51 #define GOLD 20
52 #define NIGHTRIDER 21
53 #define MANDARIN 22
54 #define FERZ2 23
55 #define ALFIL2 24
56 #define PRIESTESS 25
57 #define MINISTER 26
58 #define MAN2 27
59 #define MODERNELEPHANT 28
60 #define WOODY 29
61 #define SQUIRREL 30
62 #define MASTODON 31
63 #define CENTAUR 32
64 #define PRINCESS 33
65 #define EMPRESS 34
66 #define AMAZON 35
67 #define KING 36
68 #define HAWK 37
69 #define SELEPHANT 38
70 #define WARLORD 39
71 #define GENERAL 40
72 #define LIEUTENANT 41
73 #define CAPTAIN 42
74 #define HOPLITE 43
75 #define PIECES 44
76
77 #define MAX_BOARD_STRING_LENGTH 1280    /* Abitrarily 80 * 16 */
78 #define MAX_STYLES 13
79
80 #define W_PAWN (PAWN | WHITE)
81 #define W_KNIGHT (KNIGHT | WHITE)
82 #define W_BISHOP (BISHOP | WHITE)
83 #define W_ROOK (ROOK | WHITE)
84 #define W_CARDINAL (CARDINAL | WHITE)
85 #define W_MARSHALL (MARSHALL | WHITE)
86 #define W_MAN (MAN | WHITE)
87 #define W_QUEEN (QUEEN | WHITE)
88 #define W_ELEPHANT (ELEPHANT | WHITE)
89 #define W_ALFIL (ALFIL | WHITE)
90 #define W_FERZ (FERZ | WHITE)
91 #define W_WAZIR (WAZIR | WHITE)
92 #define W_ALFIL2 (ALFIL2 | WHITE)
93 #define W_FERZ2 (FERZ2 | WHITE)
94 #define W_AMAZON (AMAZON | WHITE)
95 #define W_CENTAUR (CENTAUR | WHITE)
96 #define W_HORSE (HORSE | WHITE)
97 #define W_HONORABLEHORSE (HONORABLEHORSE | WHITE)
98 #define W_DRAGONKING (DRAGONKING | WHITE)
99 #define W_DRAGONHORSE (DRAGONHORSE | WHITE)
100 #define W_LANCE (LANCE | WHITE)
101 #define W_CANNON (CANNON | WHITE)
102 #define W_SILVER (SILVER | WHITE)
103 #define W_GOLD (GOLD | WHITE)
104 #define W_KING (KING | WHITE)
105 #define W_MANDARIN (MANDARIN | WHITE)
106 #define W_EMPRESS (EMPRESS | WHITE)
107 #define W_PRINCESS (PRINCESS | WHITE)
108 #define W_WOODY (WOODY | WHITE)
109 #define W_MINISTER (MINISTER | WHITE)
110 #define W_PRIESTESS (PRIESTESS | WHITE)
111 #define W_MASTODON (MASTODON | WHITE)
112 #define W_MAN2 (MAN2 | WHITE)
113 #define W_NIGHTRIDER (NIGHTRIDER | WHITE)
114 #define W_HAWK (HAWK | WHITE)
115 #define W_SELEPHANT (SELEPHANT | WHITE)
116
117 #define B_PAWN (PAWN | BLACK)
118 #define B_KNIGHT (KNIGHT | BLACK)
119 #define B_BISHOP (BISHOP | BLACK)
120 #define B_ROOK (ROOK | BLACK)
121 #define B_CARDINAL (CARDINAL | BLACK)
122 #define B_MARSHALL (MARSHALL | BLACK)
123 #define B_MAN (MAN | BLACK)
124 #define B_QUEEN (QUEEN | BLACK)
125 #define B_ELEPHANT (ELEPHANT | BLACK)
126 #define B_ALFIL (ALFIL | BLACK)
127 #define B_FERZ (FERZ | BLACK)
128 #define B_WAZIR (WAZIR | BLACK)
129 #define B_ALFIL2 (ALFIL2 | BLACK)
130 #define B_FERZ2 (FERZ2 | BLACK)
131 #define B_AMAZON (AMAZON | BLACK)
132 #define B_CENTAUR (CENTAUR | BLACK)
133 #define B_HORSE (HORSE | BLACK)
134 #define B_HONORABLEHORSE (HONORABLEHORSE | BLACK)
135 #define B_DRAGONKING (DRAGONKING | BLACK)
136 #define B_DRAGONHORSE (DRAGONHORSE | BLACK)
137 #define B_LANCE (LANCE | BLACK)
138 #define B_CANNON (CANNON | BLACK)
139 #define B_SILVER (SILVER | BLACK)
140 #define B_GOLD (GOLD | BLACK)
141 #define B_KING (KING | BLACK)
142 #define B_MANDARIN (MANDARIN | BLACK)
143 #define B_EMPRESS (EMPRESS | BLACK)
144 #define B_PRINCESS (PRINCESS | BLACK)
145 #define B_WOODY (WOODY | BLACK)
146 #define B_MINISTER (MINISTER | BLACK)
147 #define B_PRIESTESS (PRIESTESS | BLACK)
148 #define B_MASTODON (MASTODON | BLACK)
149 #define B_MAN2 (MAN2 | BLACK)
150 #define B_NIGHTRIDER (NIGHTRIDER | BLACK)
151 #define B_HAWK (HAWK | BLACK)
152 #define B_SELEPHANT (SELEPHANT | BLACK)
153 #define B_WARLORD (WARLORD | BLACK)
154 #define B_GENERAL (GENERAL | BLACK)
155 #define B_LIEUTENANT (LIEUTENANT | BLACK)
156 #define B_CAPTAIN (CAPTAIN | BLACK)
157 #define B_HOPLITE (HOPLITE | BLACK)
158
159 #define isblack(p) ((p) & BLACK)
160 #define iswhite(p) (!isblack(p))
161 #define iscolor(p,color) (((p) & BLACK) == (color))
162 #define piecetype(p) ((p) & 0x7f)
163 #define colorval(p) ((p) & 0x80)
164 #define square_color(r,f) ((((r)+(f)) & 0x01) ? BLACK : WHITE)
165
166 extern int pieceValues[PIECES];
167
168 #define BW 12
169 #define BH 10
170 /* Treated as [file][rank] */
171 typedef int board_t[BW][BH];
172
173 GENSTRUCT struct game_state_t {
174         int board[BW][BH];
175         /* for bughouse */
176         int holding[2][PIECES];
177         /* For castling */
178         char wkmoved, wqrmoved, wkrmoved;
179         char bkmoved, bqrmoved, bkrmoved;
180         /* for ep */
181         int ep_possible[2][BW];
182         /* For draws */
183         int lastIrreversable;
184         int onMove;
185         int moveNum;
186         /* Game num not saved, must be restored when read */
187         int gameNum;
188         char royalKnight;
189         char capablancaPieces;
190         char pawnDblStep;
191         char ranks;
192         char files;
193         char holdings;
194         char drops;
195         char castlingStyle;
196         char palace;
197         char setup;
198         char bareKingLoses;
199         char stalemate;
200         char promoType;
201         char promoZone;
202         char variant[20];
203 };
204
205 #define ALG_DROP -2
206 #define ALG_CASTLE -3
207
208 /* bughouse: if a drop move, then fromFile is ALG_DROP and fromRank is piece */
209
210 GENSTRUCT struct move_t {
211         int color;
212         int fromFile, fromRank;
213         int toFile, toRank;
214         int pieceCaptured;
215         int piecePromotionTo;
216         int enPassant; /* 0 = no, 1=higher -1= lower */
217         int doublePawn; /* Only used for board display */
218         char moveString[8]; _NULLTERM
219         char algString[8]; _NULLTERM
220         unsigned char FENpos[74]; _NULLTERM
221         unsigned atTime;
222         unsigned tookTime;
223
224         /* these are used when examining a game */
225         int wTime;
226         int bTime;
227
228         /* [HGM] these are used for computer games */
229         float score;
230         int depth;
231 };
232
233 #define MoveToHalfMove( gs ) ((((gs)->moveNum - 1) * 2) + (((gs)->onMove == WHITE) ? 0 : 1))
234
235 extern const char *wpstring[];
236 extern const char *bpstring[];
237
238 extern int kludgeFlag; // [HGM] setup: forces move nr to zero in board printing
239
240 /* the FEN for the default initial position */
241 #define INITIAL_FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w"
242
243 #endif