Merge pull request #160 from rektdie/no-fp-direct-check

prevent fp when move gives direct check | bench 1847720
This commit was merged in pull request #160.
This commit is contained in:
rektdie authored and GitHub committed 2026-03-20 19:45:46 +01:00
commit e33b88277b
3 files changed
+46 -1

No files matched your search

+40
View File
@@ -42,6 +42,8 @@ void Board::Reset() {
pawnKey = 0ULL; pawnKey = 0ULL;
nonPawnKey = 0ULL; nonPawnKey = 0ULL;
majorKey = 0ULL; majorKey = 0ULL;
checkZones = std::array<Bitboard, 4>();
} }
void Board::SetByFen(std::string_view fen) { void Board::SetByFen(std::string_view fen) {
@@ -97,6 +99,7 @@ void Board::SetByFen(std::string_view fen) {
hashKey = UTILS::GetHashKey(*this); hashKey = UTILS::GetHashKey(*this);
checkers = CalcCheckers(); checkers = CalcCheckers();
pinned = {CalcPinned(White), CalcPinned(Black)}; pinned = {CalcPinned(White), CalcPinned(Black)};
CalcCheckers();
MOVEGEN::GenThreatMaps(*this); MOVEGEN::GenThreatMaps(*this);
MOVEGEN::GenerateMoves<All>(*this, true); MOVEGEN::GenerateMoves<All>(*this, true);
@@ -504,6 +507,7 @@ void Board::MakeMove(Move move) {
MOVEGEN::GenThreatMaps(*this); MOVEGEN::GenThreatMaps(*this);
pinned = {CalcPinned(White), CalcPinned(Black)}; pinned = {CalcPinned(White), CalcPinned(Black)};
checkers = CalcCheckers(); checkers = CalcCheckers();
CalcCheckZones();
/* /*
sideToMove = !sideToMove; sideToMove = !sideToMove;
@@ -927,3 +931,39 @@ bool Board::IsPseudoLegal(Move &move) {
return false; 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());
}
+5
View File
@@ -49,6 +49,8 @@ public:
U64 nonPawnKey = 0ULL; U64 nonPawnKey = 0ULL;
U64 majorKey = 0ULL; U64 majorKey = 0ULL;
std::array<Bitboard, 4> checkZones;
void Reset(); void Reset();
void SetByFen(std::string_view fen); void SetByFen(std::string_view fen);
std::string GetFen(); std::string GetFen();
@@ -82,6 +84,9 @@ public:
Bitboard CalcCheckers(); Bitboard CalcCheckers();
Bitboard CalcPinned(bool color); Bitboard CalcPinned(bool color);
void CalcCheckZones();
bool GivesDirectCheck(Move &move);
bool IsLegal(Move &move); bool IsLegal(Move &move);
bool IsPseudoLegal(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; int margin = fpMargin * (lmrDepth + improving) + historyScore / 32;
if (!isPV && ply && currMove.IsQuiet() if (!isPV && ply && currMove.IsQuiet()
&& lmrDepth <= 5 && staticEval + margin < alpha && notMated) { && lmrDepth <= 5 && staticEval + margin < alpha && notMated && !board.GivesDirectCheck(currMove)) {
continue; continue;
} }