4 * ----------------------------------------------------------------------
5 * Copyright (c) 1993, 1994, 1995 Matthias Mutz
6 * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
7 * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation
9 * GNU SHOGI is based on GNU CHESS
11 * Copyright (c) 1988, 1989, 1990 John Stanback
12 * Copyright (c) 1992 Free Software Foundation
14 * This file is part of GNU SHOGI.
16 * GNU Shogi is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 3 of the License,
19 * or (at your option) any later version.
21 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
22 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 * You should have received a copy of the GNU General Public License along
27 * with GNU Shogi; see the file COPYING. If not, see
28 * <http://www.gnu.org/licenses/>.
29 * ----------------------------------------------------------------------
36 #define CHECK_DISTANCE
39 * See if any piece with color 'side' attacks sq.
40 * *blockable == attack could be blocked by drop
44 SqAttacked(short square
, short side
, short *blockable
)
49 unsigned char *ppos
, *pdir
;
54 if (MatchSignature(threats_signature
[side
]))
56 *blockable
= true; /* don't know */
57 return Anyattack(side
, square
);
61 * First check neighbouring squares,
64 * then (last) check Rooks,
69 /* try a capture from direct neighboured squares */
71 ptyp
= ptype
[black
][king
];
74 u
= first_direction(ptyp
, &d
, square
);
76 pdir
= (*nextdir
[ptyp
])[square
];
82 if (color
[u
] == side
) /* can piece reach square in one step ? */
85 if (piece_distance(side
, board
[u
], u
, square
) == 1)
91 short ptypv
= ptype
[side
][board
[u
]];
94 v
= first_direction(ptypv
, &dv
, u
);
97 qdir
= (*nextdir
[ptypv
])[u
];
105 v
= next_direction(ptypv
, &dv
, u
);
115 u
= next_direction(ptyp
, &d
, square
);
123 /* try a knight capture (using xside's knight moves) */
125 ptyp
= ptype
[side
^ 1][knight
];
128 u
= first_direction(ptyp
, &d
, square
);
130 pdir
= (*nextdir
[ptyp
])[square
];
136 if (color
[u
] == side
&& board
[u
] == knight
)
140 u
= next_direction(ptyp
, &d
, square
);
146 #endif /* MINISHOGI */
150 /* try a (promoted) bishop capture */
152 ptyp
= ptype
[black
][bishop
];
155 u
= first_direction(ptyp
, &d
, square
);
157 ppos
= (*nextpos
[ptyp
])[square
];
158 pdir
= (*nextdir
[ptyp
])[square
];
164 if (color
[u
] == neutral
)
166 u
= next_position(ptyp
, &d
, square
, u
);
172 if (color
[u
] == side
&& (unpromoted
[board
[u
]] == bishop
))
176 u
= next_direction(ptyp
, &d
, square
);
184 /* try a (promoted) rook capture */
186 ptyp
= ptype
[black
][rook
];
189 u
= first_direction(ptyp
, &d
, square
);
191 ppos
= (*nextpos
[ptyp
])[square
];
192 pdir
= (*nextdir
[ptyp
])[square
];
198 if (color
[u
] == neutral
)
201 u
= next_position(ptyp
, &d
, square
, u
);
210 if (color
[u
] == side
&& (unpromoted
[board
[u
]] == rook
))
214 u
= next_direction(ptyp
, &d
, square
);
223 /* try a lance capture (using xside's lance moves) */
225 ptyp
= ptype
[side
^ 1][lance
];
228 u
= first_direction(ptyp
, &d
, square
);
230 ppos
= (*nextpos
[ptyp
])[square
];
236 if (color
[u
] == neutral
)
239 u
= next_position(ptyp
, &d
, square
, u
);
248 if ((color
[u
] == side
) && (board
[u
] == lance
))
255 #endif /* MINISHOGI */