Codex-generated pull request #139
No files matched your search
+7
-5
@@ -638,24 +638,26 @@ Bitboard Board::AttacksTo(int square, Bitboard occupancy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Board::IsSquareAttackedBy(bool attackerSide, int square, Bitboard occupancy) {
|
bool Board::IsSquareAttackedBy(bool attackerSide, int square, Bitboard occupancy) {
|
||||||
const Bitboard pawns = pieces[Pawn] & colors[attackerSide];
|
const Bitboard attackers = colors[attackerSide] & occupancy;
|
||||||
|
|
||||||
|
const Bitboard pawns = pieces[Pawn] & attackers;
|
||||||
if (MOVEGEN::pawnAttacks[!attackerSide][square] & pawns) {
|
if (MOVEGEN::pawnAttacks[!attackerSide][square] & pawns) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MOVEGEN::knightAttacks[square] & pieces[Knight] & colors[attackerSide]) {
|
if (MOVEGEN::knightAttacks[square] & pieces[Knight] & attackers) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MOVEGEN::kingAttacks[square] & pieces[King] & colors[attackerSide]) {
|
if (MOVEGEN::kingAttacks[square] & pieces[King] & attackers) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MOVEGEN::getBishopAttack(square, occupancy) & (pieces[Bishop] | pieces[Queen]) & colors[attackerSide]) {
|
if (MOVEGEN::getBishopAttack(square, occupancy) & (pieces[Bishop] | pieces[Queen]) & attackers) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MOVEGEN::getRookAttack(square, occupancy) & (pieces[Rook] | pieces[Queen]) & colors[attackerSide]) {
|
if (MOVEGEN::getRookAttack(square, occupancy) & (pieces[Rook] | pieces[Queen]) & attackers) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-8
@@ -10,11 +10,9 @@ static U64 HelperPerft(Board board, int depth) {
|
|||||||
U64 nodes = 0;
|
U64 nodes = 0;
|
||||||
|
|
||||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||||
Move move = board.moveList[i];
|
|
||||||
if (!board.IsLegal(move)) continue;
|
|
||||||
|
|
||||||
Board copy = board;
|
Board copy = board;
|
||||||
copy.MakeMove(move);
|
bool isLegal = copy.MakeMove(board.moveList[i]);
|
||||||
|
if (!isLegal) continue;
|
||||||
nodes += HelperPerft(copy, depth - 1);
|
nodes += HelperPerft(copy, depth - 1);
|
||||||
}
|
}
|
||||||
return nodes;
|
return nodes;
|
||||||
@@ -27,11 +25,9 @@ void Perft(Board &board, int depth) {
|
|||||||
|
|
||||||
Stopwatch sw;
|
Stopwatch sw;
|
||||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||||
Move move = board.moveList[i];
|
|
||||||
if (!board.IsLegal(move)) continue;
|
|
||||||
|
|
||||||
Board copy = board;
|
Board copy = board;
|
||||||
copy.MakeMove(move);
|
bool isLegal = copy.MakeMove(board.moveList[i]);
|
||||||
|
if (!isLegal) continue;
|
||||||
U64 nodeCount = HelperPerft(copy, depth - 1);
|
U64 nodeCount = HelperPerft(copy, depth - 1);
|
||||||
totalNodes += nodeCount;
|
totalNodes += nodeCount;
|
||||||
board.moveList[i].PrintMove();
|
board.moveList[i].PrintMove();
|
||||||
|
|||||||
Reference in new issue
Block a user