/// Position::piece_attacks_square() tests whether the piece on square f
/// attacks square t.
-bool Position::piece_attacks_square(Square f, Square t) const {
+bool Position::piece_attacks_square(Piece p, Square f, Square t) const {
assert(square_is_ok(f));
assert(square_is_ok(t));
- switch (piece_on(f))
+ switch (p)
{
case WP: return pawn_attacks_square(WHITE, f, t);
case BP: return pawn_attacks_square(BLACK, f, t);
assert(move_is_ok(m));
assert(square_is_ok(s));
- bool is_attack;
Square f = move_from(m), t = move_to(m);
assert(square_is_occupied(f));
- switch (piece_on(f))
- {
- case WP: is_attack = pawn_attacks_square(WHITE, t, s); break;
- case BP: is_attack = pawn_attacks_square(BLACK, t, s); break;
- case WN: case BN: is_attack = piece_attacks_square<KNIGHT>(t, s); break;
- case WB: case BB: is_attack = piece_attacks_square<BISHOP>(t, s); break;
- case WR: case BR: is_attack = piece_attacks_square<ROOK>(t, s); break;
- case WQ: case BQ: is_attack = piece_attacks_square<QUEEN>(t, s); break;
- case WK: case BK: is_attack = piece_attacks_square<KING>(t, s); break;
- default: break;
- }
-
- if (is_attack)
+ if (piece_attacks_square(piece_on(f), t, s))
return true;
// Move the piece and scan for X-ray attacks behind it
// Update board array
board[kfrom] = board[rfrom] = EMPTY;
- board[kto] = king_of_color(us);
- board[rto] = rook_of_color(us);
+ board[kto] = piece_of_color_and_type(us, KING);
+ board[rto] = piece_of_color_and_type(us, ROOK);
// Update king square
kingSquare[us] = kto;
// Update board
board[rto] = board[kto] = EMPTY;
- board[rfrom] = rook_of_color(us);
- board[kfrom] = king_of_color(us);
+ board[rfrom] = piece_of_color_and_type(us, ROOK);
+ board[kfrom] = piece_of_color_and_type(us, KING);
// Update king square
kingSquare[us] = kfrom;
set_bit(&(byColorBB[us]), from);
set_bit(&(byTypeBB[PAWN]), from);
set_bit(&(byTypeBB[0]), from); // HACK: byTypeBB[0] == occupied squares
- board[from] = pawn_of_color(us);
+ board[from] = piece_of_color_and_type(us, PAWN);
// Update material
npMaterial[us] -= piece_value_midgame(promotion);
set_bit(&(byColorBB[them]), capsq);
set_bit(&(byTypeBB[PAWN]), capsq);
set_bit(&(byTypeBB[0]), capsq);
- board[capsq] = pawn_of_color(them);
+ board[capsq] = piece_of_color_and_type(them, PAWN);
// Remove moving piece from destination square
clear_bit(&(byColorBB[us]), to);
set_bit(&(byColorBB[us]), from);
set_bit(&(byTypeBB[PAWN]), from);
set_bit(&(byTypeBB[0]), from);
- board[from] = pawn_of_color(us);
+ board[from] = piece_of_color_and_type(us, PAWN);
// Update piece list:
pieceList[us][PAWN][index[to]] = from;