fn isSquareAttacked(self: @This(), square: Square, color: Colors) bool {
switch (color) {
.white => {
// attacked by white pawns
const pa = self.attacks.pawn_attacks[@enumToInt(Colors.black)][square.int()];
if (pa & @bitCast(BoardType, self.bitboards[PE.P.int()]) != 0) return true;
},
.black => {
const pa = self.attacks.pawn_attacks[@enumToInt(Colors.white)][square.int()];
if (pa & @bitCast(BoardType, self.bitboards[PE.p.int()]) != 0) return true;
},
}
// attacked by knight
const na = self.attacks.knight_attacks[square.int()];
const nbb = switch (color) {
.white => self.bitboards[PE.N.int()],
.black => self.bitboards[PE.n.int()],
};
if (na & @bitCast(BoardType, nbb) != 0) return true;
// attacked by king
const ka = self.attacks.king_attacks[square.int()];
const kbb = switch (color) {
.white => self.bitboards[PE.K.int()],
.black => self.bitboards[PE.k.int()],
};
if (ka & @bitCast(BoardType, kbb) != 0) return true;
// attacked by bishop
const ba = self.attacks.getBishopAttacks(square, self.occupBoth());
const bbb = switch (color) {
.white => self.bitboards[PE.B.int()],
.black => self.bitboards[PE.b.int()],
};
if (ba & @bitCast(BoardType, bbb) != 0) return true;
// attacked by rook
const ra = self.attacks.getRookAttacks(square, self.occupBoth());
const rbb = switch (color) {
.white => self.bitboards[PE.R.int()],
.black => self.bitboards[PE.r.int()],
};
if (ra & @bitCast(BoardType, rbb) != 0) return true;
// attacked by queen
const qa = self.attacks.getQueenAttacks(square, self.occupBoth());
const qbb = switch (color) {
.white => self.bitboards[PE.Q.int()],
.black => self.bitboards[PE.q.int()],
};
if (qa & @bitCast(BoardType, qbb) != 0) return true;
return false;
}
fn sideAttacks(self: @This(), color: Colors) BoardType {
var ret: BoardType = 0;
for (std.enums.values(Square)) |square| {
if (isSquareAttacked(self, square, color)) ret |= @as(BoardType, 1) << square.int();
}
return ret;
}