X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmovegen.cpp;h=9a6b902bb3efc8b66d2b08a52f63bbad7419a0d5;hb=6176357ac18dcc2f0dd12c17d5ac654c86a32009;hp=b3a25806aaa5593ae064ca5d816735e4806dc628;hpb=7c267587fc7f454182b4d527607bcf8fdbd8c41c;p=stockfish diff --git a/src/movegen.cpp b/src/movegen.cpp index b3a25806..9a6b902b 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -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. 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 // be a promotion. 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 // destionation squares. - switch (to - from) + switch (direction) { case DELTA_NW: case DELTA_NE: