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

Promotion piece must be empty if is not a promotion

Add a new check in  move_is_legal()

Avoid useless casting in move.h while there.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-05-22 08:35:14 +01:00
parent 3ef4fdeaa0
commit 90e83fa879
2 changed files with 11 additions and 7 deletions

View file

@ -130,7 +130,7 @@ inline T pick_best(T* curMove, T* lastMove)
inline Square move_from(Move m) {
return Square((int(m) >> 6) & 0x3F);
return Square((m >> 6) & 0x3F);
}
inline Square move_to(Move m) {
@ -162,23 +162,23 @@ inline bool move_is_long_castle(Move m) {
}
inline PieceType move_promotion_piece(Move m) {
return move_is_promotion(m) ? PieceType(((int(m) >> 12) & 3) + 2) : PIECE_TYPE_NONE;
return PieceType(((m >> 12) & 3) + 2);
}
inline Move make_move(Square from, Square to) {
return Move(int(to) | (int(from) << 6));
return Move(to | (from << 6));
}
inline Move make_promotion_move(Square from, Square to, PieceType promotion) {
return Move(int(to) | (int(from) << 6) | ((int(promotion) - 2) << 12) | (1 << 14));
return Move(to | (from << 6) | ((promotion - 2) << 12) | (1 << 14));
}
inline Move make_ep_move(Square from, Square to) {
return Move(int(to) | (int(from) << 6) | (2 << 14));
return Move(to | (from << 6) | (2 << 14));
}
inline Move make_castle_move(Square from, Square to) {
return Move(int(to) | (int(from) << 6) | (3 << 14));
return Move(to | (from << 6) | (3 << 14));
}
inline bool move_is_ok(Move m) {

View file

@ -676,9 +676,13 @@ bool Position::move_is_legal(const Move m, Bitboard pinned) const {
if (move_is_special(m))
return move_is_legal(m);
// Is not a promotion, so promotion piece must be empty
if (move_promotion_piece(m) - 2 != PIECE_TYPE_NONE)
return false;
// If the from square is not occupied by a piece belonging to the side to
// move, the move is obviously not legal.
if (color_of_piece(pc) != us)
if (pc == PIECE_NONE || color_of_piece(pc) != us)
return false;
// The destination square cannot be occupied by a friendly piece