Fix mamer crash on listmanagers command
[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
69 #define MAX_BOARD_STRING_LENGTH 1280    /* Abitrarily 80 * 16 */
70 #define MAX_STYLES 13
71
72 #define W_PAWN (PAWN | WHITE)
73 #define W_KNIGHT (KNIGHT | WHITE)
74 #define W_BISHOP (BISHOP | WHITE)
75 #define W_ROOK (ROOK | WHITE)
76 #define W_CARDINAL (CARDINAL | WHITE)
77 #define W_MARSHALL (MARSHALL | WHITE)
78 #define W_MAN (MAN | WHITE)
79 #define W_QUEEN (QUEEN | WHITE)
80 #define W_ELEPHANT (ELEPHANT | WHITE)
81 #define W_ALFIL (ALFIL | WHITE)
82 #define W_FERZ (FERZ | WHITE)
83 #define W_WAZIR (WAZIR | WHITE)
84 #define W_ALFIL2 (ALFIL2 | WHITE)
85 #define W_FERZ2 (FERZ2 | WHITE)
86 #define W_AMAZON (AMAZON | WHITE)
87 #define W_CENTAUR (CENTAUR | WHITE)
88 #define W_HORSE (HORSE | WHITE)
89 #define W_HONORABLEHORSE (HONORABLEHORSE | WHITE)
90 #define W_DRAGONKING (DRAGONKING | WHITE)
91 #define W_DRAGONHORSE (DRAGONHORSE | WHITE)
92 #define W_LANCE (LANCE | WHITE)
93 #define W_CANNON (CANNON | WHITE)
94 #define W_SILVER (SILVER | WHITE)
95 #define W_GOLD (GOLD | WHITE)
96 #define W_KING (KING | WHITE)
97 #define W_MANDARIN (MANDARIN | WHITE)
98 #define W_EMPRESS (EMPRESS | WHITE)
99 #define W_PRINCESS (PRINCESS | WHITE)
100 #define W_WOODY (WOODY | WHITE)
101 #define W_MINISTER (MINISTER | WHITE)
102 #define W_PRIESTESS (PRIESTESS | WHITE)
103 #define W_MASTODON (MASTODON | WHITE)
104 #define W_MAN2 (MAN2 | WHITE)
105 #define W_NIGHTRIDER (NIGHTRIDER | WHITE)
106
107 #define B_PAWN (PAWN | BLACK)
108 #define B_KNIGHT (KNIGHT | BLACK)
109 #define B_BISHOP (BISHOP | BLACK)
110 #define B_ROOK (ROOK | BLACK)
111 #define B_CARDINAL (CARDINAL | BLACK)
112 #define B_MARSHALL (MARSHALL | BLACK)
113 #define B_MAN (MAN | BLACK)
114 #define B_QUEEN (QUEEN | BLACK)
115 #define B_ELEPHANT (ELEPHANT | BLACK)
116 #define B_ALFIL (ALFIL | BLACK)
117 #define B_FERZ (FERZ | BLACK)
118 #define B_WAZIR (WAZIR | BLACK)
119 #define B_ALFIL2 (ALFIL2 | BLACK)
120 #define B_FERZ2 (FERZ2 | BLACK)
121 #define B_AMAZON (AMAZON | BLACK)
122 #define B_CENTAUR (CENTAUR | BLACK)
123 #define B_HORSE (HORSE | BLACK)
124 #define B_HONORABLEHORSE (HONORABLEHORSE | BLACK)
125 #define B_DRAGONKING (DRAGONKING | BLACK)
126 #define B_DRAGONHORSE (DRAGONHORSE | BLACK)
127 #define B_LANCE (LANCE | BLACK)
128 #define B_CANNON (CANNON | BLACK)
129 #define B_SILVER (SILVER | BLACK)
130 #define B_GOLD (GOLD | BLACK)
131 #define B_KING (KING | BLACK)
132 #define B_MANDARIN (MANDARIN | BLACK)
133 #define B_EMPRESS (EMPRESS | BLACK)
134 #define B_PRINCESS (PRINCESS | BLACK)
135 #define B_WOODY (WOODY | BLACK)
136 #define B_MINISTER (MINISTER | BLACK)
137 #define B_PRIESTESS (PRIESTESS | BLACK)
138 #define B_MASTODON (MASTODON | BLACK)
139 #define B_MAN2 (MAN2 | BLACK)
140 #define B_NIGHTRIDER (NIGHTRIDER | BLACK)
141
142 #define isblack(p) ((p) & BLACK)
143 #define iswhite(p) (!isblack(p))
144 #define iscolor(p,color) (((p) & BLACK) == (color))
145 #define piecetype(p) ((p) & 0x7f)
146 #define colorval(p) ((p) & 0x80)
147 #define square_color(r,f) ((((r)+(f)) & 0x01) ? BLACK : WHITE)
148
149 extern int pieceValues[KING+1];
150
151 #define BW 12
152 #define BH 10
153 /* Treated as [file][rank] */
154 typedef int board_t[BW][BH];
155
156 GENSTRUCT struct game_state_t {
157         int board[BW][BH];
158         /* for bughouse */
159         int holding[2][KING];
160         /* For castling */
161         char wkmoved, wqrmoved, wkrmoved;
162         char bkmoved, bqrmoved, bkrmoved;
163         /* for ep */
164         int ep_possible[2][BW];
165         /* For draws */
166         int lastIrreversable;
167         int onMove;
168         int moveNum;
169         /* Game num not saved, must be restored when read */
170         int gameNum;
171         char royalKnight;
172         char capablancaPieces;
173         char pawnDblStep;
174         char ranks;
175         char files;
176         char holdings;
177         char drops;
178         char castlingStyle;
179         char palace;
180         char setup;
181         char bareKingLoses;
182         char stalemate;
183         char promoType;
184         char promoZone;
185         char variant[20];
186 };
187
188 #define ALG_DROP -2
189 #define ALG_CASTLE -3
190
191 /* bughouse: if a drop move, then fromFile is ALG_DROP and fromRank is piece */
192
193 GENSTRUCT struct move_t {
194         int color;
195         int fromFile, fromRank;
196         int toFile, toRank;
197         int pieceCaptured;
198         int piecePromotionTo;
199         int enPassant; /* 0 = no, 1=higher -1= lower */
200         int doublePawn; /* Only used for board display */
201         char moveString[8]; _NULLTERM
202         char algString[8]; _NULLTERM
203         unsigned char FENpos[74]; _NULLTERM
204         unsigned atTime;
205         unsigned tookTime;
206
207         /* these are used when examining a game */
208         int wTime;
209         int bTime;
210
211         /* [HGM] these are used for computer games */
212         float score;
213         int depth;
214 };
215
216 #define MoveToHalfMove( gs ) ((((gs)->moveNum - 1) * 2) + (((gs)->onMove == WHITE) ? 0 : 1))
217
218 extern const char *wpstring[];
219 extern const char *bpstring[];
220
221 extern int kludgeFlag; // [HGM] setup: forces move nr to zero in board printing
222
223 /* the FEN for the default initial position */
224 #define INITIAL_FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w"
225
226 #endif