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
69 #define MAX_BOARD_STRING_LENGTH 1280 /* Abitrarily 80 * 16 */
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)
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)
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)
149 extern int pieceValues[KING+1];
153 /* Treated as [file][rank] */
154 typedef int board_t[BW][BH];
156 GENSTRUCT struct game_state_t {
159 int holding[2][KING];
161 char wkmoved, wqrmoved, wkrmoved;
162 char bkmoved, bqrmoved, bkrmoved;
164 int ep_possible[2][BW];
166 int lastIrreversable;
169 /* Game num not saved, must be restored when read */
172 char capablancaPieces;
188 #define ALG_CASTLE -3
190 /* bughouse: if a drop move, then fromFile is ALG_DROP and fromRank is piece */
192 GENSTRUCT struct move_t {
194 int fromFile, fromRank;
197 int piecePromotionTo;
198 int enPassant; /* 0 = no, 1=higher -1= lower */
199 int doublePawn; /* Only used for board display */
200 char moveString[8]; _NULLTERM
201 char algString[8]; _NULLTERM
202 unsigned char FENpos[74]; _NULLTERM
206 /* these are used when examining a game */
210 /* [HGM] these are used for computer games */
215 #define MoveToHalfMove( gs ) ((((gs)->moveNum - 1) * 2) + (((gs)->onMove == WHITE) ? 0 : 1))
217 extern const char *wpstring[];
218 extern const char *bpstring[];
220 extern int kludgeFlag; // [HGM] setup: forces move nr to zero in board printing
222 /* the FEN for the default initial position */
223 #define INITIAL_FEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w"