4 * ----------------------------------------------------------------------
5 * Copyright (c) 1993, 1994, 1995 Matthias Mutz
6 * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
8 * GNU SHOGI is based on GNU CHESS
10 * Copyright (c) 1988, 1989, 1990 John Stanback
11 * Copyright (c) 1992 Free Software Foundation
13 * This file is part of GNU SHOGI.
15 * GNU Shogi is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 3 of the License,
18 * or (at your option) any later version.
20 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
21 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * You should have received a copy of the GNU General Public License along
26 * with GNU Shogi; see the file COPYING. If not, see
27 * <http://www.gnu.org/licenses/>.
28 * ----------------------------------------------------------------------
35 #define CHECK_DISTANCE
38 * See if any piece with color 'side' attacks sq.
39 * *blockable == attack could be blocked by drop
43 SqAttacked(short square, short side, short *blockable)
48 unsigned char *ppos, *pdir;
53 if (MatchSignature(threats_signature[side]))
55 *blockable = true; /* don't know */
56 return Anyattack(side, square);
60 * First check neighbouring squares,
63 * then (last) check Rooks,
68 /* try a capture from direct neighboured squares */
70 ptyp = ptype[black][king];
73 u = first_direction(ptyp, &d, square);
75 pdir = (*nextdir[ptyp])[square];
81 if (color[u] == side) /* can piece reach square in one step ? */
84 if (piece_distance(side, board[u], u, square) == 1)
90 short ptypv = ptype[side][board[u]];
93 v = first_direction(ptypv, &dv, u);
96 qdir = (*nextdir[ptypv])[u];
104 v = next_direction(ptypv, &dv, u);
114 u = next_direction(ptyp, &d, square);
122 /* try a knight capture (using xside's knight moves) */
124 ptyp = ptype[side ^ 1][knight];
127 u = first_direction(ptyp, &d, square);
129 pdir = (*nextdir[ptyp])[square];
135 if (color[u] == side && board[u] == knight)
139 u = next_direction(ptyp, &d, square);
145 #endif /* MINISHOGI */
149 /* try a (promoted) bishop capture */
151 ptyp = ptype[black][bishop];
154 u = first_direction(ptyp, &d, square);
156 ppos = (*nextpos[ptyp])[square];
157 pdir = (*nextdir[ptyp])[square];
163 if (color[u] == neutral)
165 u = next_position(ptyp, &d, square, u);
171 if (color[u] == side && (unpromoted[board[u]] == bishop))
175 u = next_direction(ptyp, &d, square);
183 /* try a (promoted) rook capture */
185 ptyp = ptype[black][rook];
188 u = first_direction(ptyp, &d, square);
190 ppos = (*nextpos[ptyp])[square];
191 pdir = (*nextdir[ptyp])[square];
197 if (color[u] == neutral)
200 u = next_position(ptyp, &d, square, u);
209 if (color[u] == side && (unpromoted[board[u]] == rook))
213 u = next_direction(ptyp, &d, square);
222 /* try a lance capture (using xside's lance moves) */
224 ptyp = ptype[side ^ 1][lance];
227 u = first_direction(ptyp, &d, square);
229 ppos = (*nextpos[ptyp])[square];
235 if (color[u] == neutral)
238 u = next_position(ptyp, &d, square, u);
247 if ((color[u] == side) && (board[u] == lance))
254 #endif /* MINISHOGI */