1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

Fix missing pawn color check in move_is_legal()

In case we have a correct white pawn move but pawn
is black (or the contrary) we fail to detect the
move as illegal.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2009-05-05 13:10:29 +02:00
parent 5c703b7526
commit 46bb6c6dc3

View file

@ -496,6 +496,11 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
// Proceed according to the type of the moving piece. // Proceed according to the type of the moving piece.
if (type_of_piece(pc) == PAWN) if (type_of_piece(pc) == PAWN)
{ {
// Move direction must be compatible with pawn color
int direction = to - from;
if ((us == WHITE) != (direction > 0))
return false;
// If the destination square is on the 8/1th rank, the move must // If the destination square is on the 8/1th rank, the move must
// be a promotion. // be a promotion.
if ( ( (square_rank(to) == RANK_8 && us == WHITE) if ( ( (square_rank(to) == RANK_8 && us == WHITE)
@ -505,7 +510,7 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
// Proceed according to the square delta between the source and // Proceed according to the square delta between the source and
// destionation squares. // destionation squares.
switch (to - from) switch (direction)
{ {
case DELTA_NW: case DELTA_NW:
case DELTA_NE: case DELTA_NE: