2 Copyright (c) 1993 Richard V. Nash.
3 Copyright (C) Andrew Tridgell 2002
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.
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.
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.
26 #define CString( c ) ( ((c) == WHITE) ? "White" : "Black" )
27 #define CToggle( c ) ( ((c) == BLACK) ? WHITE : BLACK )
29 /* These will go into an array */
45 #define HONORABLEHORSE 14
47 #define DRAGONHORSE 16
59 #define MODERNELEPHANT 28
77 #define MAX_BOARD_STRING_LENGTH 1280 /* Abitrarily 80 * 16 */
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)
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)
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)
166 extern int pieceValues[PIECES];
170 /* Treated as [file][rank] */
171 typedef int board_t[BW][BH];
173 GENSTRUCT struct game_state_t {
176 int holding[2][PIECES];
178 char wkmoved, wqrmoved, wkrmoved;
179 char bkmoved, bqrmoved, bkrmoved;
181 int ep_possible[2][BW];
183 int lastIrreversable;
186 /* Game num not saved, must be restored when read */
189 char capablancaPieces;
206 #define ALG_CASTLE -3
208 /* bughouse: if a drop move, then fromFile is ALG_DROP and fromRank is piece */
210 GENSTRUCT struct move_t {
212 int fromFile, fromRank;
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
224 /* these are used when examining a game */
228 /* [HGM] these are used for computer games */
233 #define MoveToHalfMove( gs ) ((((gs)->moveNum - 1) * 2) + (((gs)->onMove == WHITE) ? 0 : 1))
235 extern const char *wpstring[];
236 extern const char *bpstring[];
238 extern int kludgeFlag; // [HGM] setup: forces move nr to zero in board printing
240 /* the FEN for the default initial position */
241 #define INITIAL_FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w"