mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 17:19:36 +00:00
Refactor bonus and penalty calculation (#917)
* Refactor bonus and penalty calculation Compute common terms in a helper function. No functional change. * Further refactoring Remove some parenthesis that are now useless. Define prevSq once, use repeatedly. No functional change. bench: 5884767 (bench of previous patch is wrong)
This commit is contained in:
parent
0d33466bcd
commit
a47bbca0ea
1 changed files with 9 additions and 27 deletions
|
@ -153,6 +153,9 @@ namespace {
|
|||
{1, 0, 0, 0, 0, 1, 1 ,1},
|
||||
};
|
||||
|
||||
Value bonus(Depth depth) { int d = depth / ONE_PLY ; return Value(d * d + 2 * d - 2); }
|
||||
Value penalty(Depth depth) { int d = depth / ONE_PLY ; return -Value(d * d + 4 * d + 1); }
|
||||
|
||||
const size_t HalfDensitySize = std::extent<decltype(HalfDensity)>::value;
|
||||
|
||||
EasyMoveManager EasyMove;
|
||||
|
@ -616,6 +619,7 @@ namespace {
|
|||
ss->counterMoves = nullptr;
|
||||
(ss+1)->skipEarlyPruning = false;
|
||||
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
|
||||
Square prevSq = to_sq((ss-1)->currentMove);
|
||||
|
||||
// Step 4. Transposition table lookup. We don't want the score of a partial
|
||||
// search to overwrite a previous full search TT value, so we use a different
|
||||
|
@ -638,21 +642,12 @@ namespace {
|
|||
// If ttMove is quiet, update killers, history, counter move on TT hit
|
||||
if (ttValue >= beta && ttMove)
|
||||
{
|
||||
int d = depth / ONE_PLY;
|
||||
|
||||
if (!pos.capture_or_promotion(ttMove))
|
||||
{
|
||||
Value bonus = Value(d * d + 2 * d - 2);
|
||||
update_stats(pos, ss, ttMove, nullptr, 0, bonus);
|
||||
}
|
||||
update_stats(pos, ss, ttMove, nullptr, 0, bonus(depth));
|
||||
|
||||
// Extra penalty for a quiet TT move in previous ply when it gets refuted
|
||||
if ((ss-1)->moveCount == 1 && !pos.captured_piece())
|
||||
{
|
||||
Value penalty = Value(d * d + 4 * d + 1);
|
||||
Square prevSq = to_sq((ss-1)->currentMove);
|
||||
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, -penalty);
|
||||
}
|
||||
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, penalty(depth));
|
||||
}
|
||||
return ttValue;
|
||||
}
|
||||
|
@ -1140,33 +1135,20 @@ moves_loop: // When in check search starts from here
|
|||
: inCheck ? mated_in(ss->ply) : DrawValue[pos.side_to_move()];
|
||||
else if (bestMove)
|
||||
{
|
||||
int d = depth / ONE_PLY;
|
||||
|
||||
// Quiet best move: update killers, history and countermoves
|
||||
if (!pos.capture_or_promotion(bestMove))
|
||||
{
|
||||
Value bonus = Value(d * d + 2 * d - 2);
|
||||
update_stats(pos, ss, bestMove, quietsSearched, quietCount, bonus);
|
||||
}
|
||||
update_stats(pos, ss, bestMove, quietsSearched, quietCount, bonus(depth));
|
||||
|
||||
// Extra penalty for a quiet TT move in previous ply when it gets refuted
|
||||
if ((ss-1)->moveCount == 1 && !pos.captured_piece())
|
||||
{
|
||||
Value penalty = Value(d * d + 4 * d + 1);
|
||||
Square prevSq = to_sq((ss-1)->currentMove);
|
||||
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, -penalty);
|
||||
}
|
||||
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, penalty(depth));
|
||||
}
|
||||
// Bonus for prior countermove that caused the fail low
|
||||
else if ( depth >= 3 * ONE_PLY
|
||||
&& !pos.captured_piece()
|
||||
&& is_ok((ss-1)->currentMove))
|
||||
{
|
||||
int d = depth / ONE_PLY;
|
||||
Value bonus = Value(d * d + 2 * d - 2);
|
||||
Square prevSq = to_sq((ss-1)->currentMove);
|
||||
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, bonus);
|
||||
}
|
||||
update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, bonus(depth));
|
||||
|
||||
tte->save(posKey, value_to_tt(bestValue, ss->ply),
|
||||
bestValue >= beta ? BOUND_LOWER :
|
||||
|
|
Loading…
Add table
Reference in a new issue