added SEE to QS | bench 3986957
This commit is contained in:
1 parent
5e18083113
commit
a529a949f0
4 files changed
+109
-4
No files matched your search
+3
-3
@@ -523,7 +523,7 @@ void Board::ResetAccPair() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitboard Board::AttacksTo(int square) {
|
Bitboard Board::AttacksTo(int square, Bitboard occupancy) {
|
||||||
Bitboard attacks;
|
Bitboard attacks;
|
||||||
|
|
||||||
// Pawn attacks
|
// Pawn attacks
|
||||||
@@ -540,8 +540,8 @@ Bitboard Board::AttacksTo(int square) {
|
|||||||
// King
|
// King
|
||||||
attacks |= (MOVEGEN::kingAttacks[square] & pieces[King]);
|
attacks |= (MOVEGEN::kingAttacks[square] & pieces[King]);
|
||||||
|
|
||||||
Bitboard bishopAttacks = MOVEGEN::getBishopAttack(square, occupied);
|
Bitboard bishopAttacks = MOVEGEN::getBishopAttack(square, occupancy);
|
||||||
Bitboard rookAttacks = MOVEGEN::getRookAttack(square, occupied);
|
Bitboard rookAttacks = MOVEGEN::getRookAttack(square, occupancy);
|
||||||
|
|
||||||
// Rook or queen
|
// Rook or queen
|
||||||
attacks |= (rookAttacks & (pieces[Rook] | pieces[Queen]));
|
attacks |= (rookAttacks & (pieces[Rook] | pieces[Queen]));
|
||||||
|
|||||||
+1
-1
@@ -67,5 +67,5 @@ public:
|
|||||||
|
|
||||||
bool InPossibleZug();
|
bool InPossibleZug();
|
||||||
|
|
||||||
Bitboard AttacksTo(int square);
|
Bitboard AttacksTo(int square, Bitboard occupancy);
|
||||||
};
|
};
|
||||||
@@ -125,6 +125,79 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int
|
|||||||
return reduction;
|
return reduction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int SEE(Board& board, Move& move, int threshold) {
|
||||||
|
int from = move.MoveFrom();
|
||||||
|
int to = move.MoveTo();
|
||||||
|
int flags = move.GetFlags();
|
||||||
|
|
||||||
|
int nextVictim = -1;
|
||||||
|
|
||||||
|
// Next victim is moved piece or promo piece
|
||||||
|
if (move.IsPromo()) {
|
||||||
|
if (move.IsCapture()) {
|
||||||
|
nextVictim = move.GetFlags() - 9;
|
||||||
|
} else {
|
||||||
|
nextVictim = move.GetFlags() - 5;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nextVictim = board.GetPieceType(from);
|
||||||
|
}
|
||||||
|
|
||||||
|
int balance = MoveEstimatedValue(board, move) - threshold;
|
||||||
|
|
||||||
|
if (balance < 0) return 0;
|
||||||
|
|
||||||
|
balance -= SEEPieceValues[nextVictim];
|
||||||
|
|
||||||
|
if (balance >= 0) return 1;
|
||||||
|
|
||||||
|
Bitboard bishops = board.pieces[Bishop] | board.pieces[Queen];
|
||||||
|
Bitboard rooks = board.pieces[Rook] | board.pieces[Queen];
|
||||||
|
|
||||||
|
Bitboard occupied = board.occupied;
|
||||||
|
occupied = (occupied ^ Bitboard((1ULL << from))) | Bitboard((1ULL << to));
|
||||||
|
|
||||||
|
if (flags == epCapture)
|
||||||
|
occupied ^= Bitboard(1ULL << board.enPassantTarget);
|
||||||
|
|
||||||
|
Bitboard attackers = board.AttacksTo(to, occupied) & occupied;
|
||||||
|
|
||||||
|
bool color = !board.sideToMove;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
Bitboard myAttackers = attackers & board.colors[color];
|
||||||
|
if (!myAttackers) break;
|
||||||
|
|
||||||
|
for (nextVictim = Pawn; nextVictim <= Queen; nextVictim++) {
|
||||||
|
if (myAttackers & board.pieces[nextVictim])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
occupied ^= Bitboard(1ULL << Bitboard(myAttackers & board.pieces[nextVictim]).getLS1BIndex());
|
||||||
|
|
||||||
|
if (nextVictim == Pawn || nextVictim == Bishop || nextVictim == Queen)
|
||||||
|
attackers |= MOVEGEN::getBishopAttack(to, occupied) & bishops;
|
||||||
|
|
||||||
|
if (nextVictim == Rook || nextVictim == Queen)
|
||||||
|
attackers |= MOVEGEN::getRookAttack(to, occupied) & rooks;
|
||||||
|
|
||||||
|
attackers &= occupied;
|
||||||
|
|
||||||
|
color = !color;
|
||||||
|
|
||||||
|
balance = -balance - 1 - SEEPieceValues[nextVictim];
|
||||||
|
|
||||||
|
if (balance >= 0) {
|
||||||
|
if (nextVictim == King && (attackers & board.colors[color]))
|
||||||
|
color = !color;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return board.sideToMove != color;
|
||||||
|
}
|
||||||
|
|
||||||
template <searchMode mode>
|
template <searchMode mode>
|
||||||
static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, SearchContext& ctx) {
|
static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, SearchContext& ctx) {
|
||||||
if constexpr (mode != nodesMode) {
|
if constexpr (mode != nodesMode) {
|
||||||
@@ -178,6 +251,10 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
|
|||||||
Board copy = board;
|
Board copy = board;
|
||||||
int isLegal = copy.MakeMove(board.moveList[i]);
|
int isLegal = copy.MakeMove(board.moveList[i]);
|
||||||
if (!isLegal) continue;
|
if (!isLegal) continue;
|
||||||
|
|
||||||
|
if (!SEE(board, board.moveList[i], 0))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (copy.positionIndex >= ctx.positionHistory.size()) {
|
if (copy.positionIndex >= ctx.positionHistory.size()) {
|
||||||
ctx.positionHistory.resize(copy.positionIndex + 100);
|
ctx.positionHistory.resize(copy.positionIndex + 100);
|
||||||
}
|
}
|
||||||
@@ -522,6 +599,27 @@ SearchResults SearchPosition(Board &board, SearchParams params, SearchContext& c
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MoveEstimatedValue(Board& board, Move& move) {
|
||||||
|
int value = SEEPieceValues[board.GetPieceType(move.MoveTo())];
|
||||||
|
|
||||||
|
if (move.IsPromo()) {
|
||||||
|
int promoPiece = -1;
|
||||||
|
if (move.IsCapture()) {
|
||||||
|
promoPiece = move.GetFlags() - 9;
|
||||||
|
} else {
|
||||||
|
promoPiece = move.GetFlags() - 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
value += SEEPieceValues[promoPiece] - SEEPieceValues[Pawn];
|
||||||
|
} else if (move.GetFlags() == epCapture) {
|
||||||
|
value = SEEPieceValues[Pawn];
|
||||||
|
} else if (move.GetFlags() == queenCastle || move.GetFlags() == kingCastle) {
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
template SearchResults PVS<true, searchMode::bench>(Board&, int, int, int, int, SearchContext& ctx);
|
template SearchResults PVS<true, searchMode::bench>(Board&, int, int, int, int, SearchContext& ctx);
|
||||||
template SearchResults PVS<false, searchMode::bench>(Board&, int, int, int, int, SearchContext& ctx);
|
template SearchResults PVS<false, searchMode::bench>(Board&, int, int, int, int, SearchContext& ctx);
|
||||||
template SearchResults PVS<true, searchMode::normal>(Board&, int, int, int, int, SearchContext& ctx);
|
template SearchResults PVS<true, searchMode::normal>(Board&, int, int, int, int, SearchContext& ctx);
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ constexpr int inf = 100000;
|
|||||||
|
|
||||||
inline int lmrTable[MAX_DEPTH+1][MAX_MOVES];
|
inline int lmrTable[MAX_DEPTH+1][MAX_MOVES];
|
||||||
|
|
||||||
|
static const int SEEPieceValues[] = {
|
||||||
|
103, 422, 437, 694,
|
||||||
|
1313, 0, 0, 0,
|
||||||
|
};
|
||||||
|
|
||||||
void InitLMRTable();
|
void InitLMRTable();
|
||||||
|
|
||||||
class History {
|
class History {
|
||||||
@@ -142,4 +147,6 @@ constexpr int moveScoreTable[6][6] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void ListScores(Board &board, SearchContext& ctx);
|
void ListScores(Board &board, SearchContext& ctx);
|
||||||
|
|
||||||
|
int MoveEstimatedValue(Board& board, Move& move);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user