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);
121 /* try a knight capture (using xside's knight moves) */
123 ptyp = ptype[side ^ 1][knight];
126 u = first_direction(ptyp, &d, square);
128 pdir = (*nextdir[ptyp])[square];
134 if (color[u] == side && board[u] == knight)
138 u = next_direction(ptyp, &d, square);
147 /* try a (promoted) bishop capture */
149 ptyp = ptype[black][bishop];
152 u = first_direction(ptyp, &d, square);
154 ppos = (*nextpos[ptyp])[square];
155 pdir = (*nextdir[ptyp])[square];
161 if (color[u] == neutral)
163 u = next_position(ptyp, &d, square, u);
169 if (color[u] == side && (unpromoted[board[u]] == bishop))
173 u = next_direction(ptyp, &d, square);
181 /* try a (promoted) rook capture */
183 ptyp = ptype[black][rook];
186 u = first_direction(ptyp, &d, square);
188 ppos = (*nextpos[ptyp])[square];
189 pdir = (*nextdir[ptyp])[square];
195 if (color[u] == neutral)
198 u = next_position(ptyp, &d, square, u);
207 if (color[u] == side && (unpromoted[board[u]] == rook))
211 u = next_direction(ptyp, &d, square);
219 /* try a lance capture (using xside's lance moves) */
221 ptyp = ptype[side ^ 1][lance];
224 u = first_direction(ptyp, &d, square);
226 ppos = (*nextpos[ptyp])[square];
232 if (color[u] == neutral)
235 u = next_position(ptyp, &d, square, u);
244 if ((color[u] == side) && (board[u] == lance))