prevent fp when move gives direct check | bench 1847720 #160

Merged
rektdie merged 1 commits from no-fp-direct-check into main 2026-03-20 19:45:47 +01:00
3 changed files with 47 additions and 2 deletions

No files matched your search

+40
View File
@@ -42,6 +42,8 @@ void Board::Reset() {
pawnKey = 0ULL;
nonPawnKey = 0ULL;
majorKey = 0ULL;
checkZones = std::array<Bitboard, 4>();
}
void Board::SetByFen(std::string_view fen) {
@@ -97,6 +99,7 @@ void Board::SetByFen(std::string_view fen) {
hashKey = UTILS::GetHashKey(*this);
checkers = CalcCheckers();
pinned = {CalcPinned(White), CalcPinned(Black)};
CalcCheckers();
MOVEGEN::GenThreatMaps(*this);
MOVEGEN::GenerateMoves<All>(*this, true);
@@ -504,6 +507,7 @@ void Board::MakeMove(Move move) {
MOVEGEN::GenThreatMaps(*this);
pinned = {CalcPinned(White), CalcPinned(Black)};
checkers = CalcCheckers();
CalcCheckZones();
/*
sideToMove = !sideToMove;
@@ -926,4 +930,40 @@ bool Board::IsPseudoLegal(Move &move) {
default:
return false;
}
}
void Board::CalcCheckZones() {
int oppKingSquare = (colors[!sideToMove] & pieces[King]).getLS1BIndex();
checkZones[0] = MOVEGEN::pawnAttacks[!sideToMove][oppKingSquare];
checkZones[1] = MOVEGEN::knightAttacks[oppKingSquare];
checkZones[2] = MOVEGEN::getBishopAttack(oppKingSquare, occupied);
checkZones[3] = MOVEGEN::getRookAttack(oppKingSquare, occupied);
}
bool Board::GivesDirectCheck(Move &move) {
int attackerType = nullPieceType;
if (move.IsPromo()) {
if (move.IsCapture()) {
attackerType = move.GetFlags() - 9;
} else {
attackerType = move.GetFlags() - 5;
}
} else {
attackerType = GetPieceType(move.MoveFrom());
}
if (attackerType == King)
return false;
Bitboard checkZone = 0ULL;
if (attackerType == Queen) {
checkZone = checkZones[Bishop] | checkZones[Rook];
} else {
checkZone = checkZones[attackerType];
}
return checkZone.IsSet(move.MoveTo());
}
+6 -1
View File
@@ -49,6 +49,8 @@ public:
U64 nonPawnKey = 0ULL;
U64 majorKey = 0ULL;
std::array<Bitboard, 4> checkZones;
void Reset();
void SetByFen(std::string_view fen);
std::string GetFen();
@@ -82,6 +84,9 @@ public:
Bitboard CalcCheckers();
Bitboard CalcPinned(bool color);
void CalcCheckZones();
bool GivesDirectCheck(Move &move);
bool IsLegal(Move &move);
bool IsPseudoLegal(Move &move);
};
};
+1 -1
View File
@@ -561,7 +561,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
int margin = fpMargin * (lmrDepth + improving) + historyScore / 32;
if (!isPV && ply && currMove.IsQuiet()
&& lmrDepth <= 5 && staticEval + margin < alpha && notMated) {
&& lmrDepth <= 5 && staticEval + margin < alpha && notMated && !board.GivesDirectCheck(currMove)) {
continue;
}