[BitBoard] Add bishop and pawn methods

This commit is contained in:
2022-12-22 15:58:11 +01:00
parent e620e6f5cb
commit e1d216f06b
2 changed files with 55 additions and 7 deletions

View File

@@ -25,9 +25,6 @@ std::ostream &operator<<(std::ostream &os, const BitBoard &board) {
return os;
}
BitBoard BitBoard::getRank(int r) {
return (genShift(1ULL, (r + 1) * 8) - 1) & genShift(~1ULL, r * 8 - 1);
}
BitBoard BitBoard::genShift(BitBoard x, const int s) {
return (s < 0) ? (x >> -s) : (s > 63) ? x : (x << s);
}
@@ -58,5 +55,35 @@ BitBoard BitBoard::kingAttacks(const BitBoard bb) {
result ^= bb;
return result;
}
BitBoard BitBoard::bishopAttacks(BitBoard bishops, BitBoard empty) {
BitBoard result = 0;
BitBoard diag1 = bishops;
BitBoard diag2 = bishops;
empty ^= bishops;
for (int i = 0; i < 7; i++) {
result |= (diag1 | diag2);
diag1 = (diag1.northWest() | diag1.southEast()) & empty;
diag2 = (diag2.northEast() | diag2.southWest()) & empty;
}
return (result | diag1.northWest() | diag1.southEast() | diag2.northEast() | diag2.southWest()) & ~bishops;
}
BitBoard BitBoard::pawnNorthAttacks(BitBoard pawns, BitBoard targets) {
return (pawns.northEast() | pawns.northWest()) & targets;
}
BitBoard BitBoard::pawnNorthMoves(BitBoard pawns, BitBoard empty) {
pawns = pawns.north() & empty;
return (pawns | (pawns.north() & Rank4)) & empty;
}
BitBoard BitBoard::pawnSouthAttacks(BitBoard pawns, BitBoard targets) {
return (pawns.southEast() | pawns.southWest()) & targets;
}
BitBoard BitBoard::pawnSouthMoves(BitBoard pawns, BitBoard empty) {
pawns = pawns.south() & empty;
return (pawns | (pawns.south() & Rank5)) & empty;
}