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