[BitBoard] Add bishop and pawn methods
This commit is contained in:
33
BitBoard.cpp
33
BitBoard.cpp
@@ -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;
|
||||
}
|
Reference in New Issue
Block a user