1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Simplify aspiration window calculation

It seems that we just need to look at previous score to
compute aspiration window size.

After 5350 games:
Mod vs Orig 800 - 803  - 3647 ELO +0 (+- 5.2)

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-12-07 17:51:02 +01:00
parent 4e59c5c274
commit 96213689e4

View file

@ -425,9 +425,8 @@ namespace {
Move id_loop(Position& pos, Move* ponderMove) { Move id_loop(Position& pos, Move* ponderMove) {
Stack ss[PLY_MAX_PLUS_2]; Stack ss[PLY_MAX_PLUS_2];
Value bestValues[PLY_MAX_PLUS_2];
int bestMoveChanges[PLY_MAX_PLUS_2]; int bestMoveChanges[PLY_MAX_PLUS_2];
int depth, aspirationDelta; int depth, delta;
Value bestValue, alpha, beta; Value bestValue, alpha, beta;
Move bestMove, skillBest, skillPonder; Move bestMove, skillBest, skillPonder;
bool bestMoveNeverChanged = true; bool bestMoveNeverChanged = true;
@ -437,7 +436,7 @@ namespace {
H.clear(); H.clear();
RootMoves.clear(); RootMoves.clear();
*ponderMove = bestMove = skillBest = skillPonder = MOVE_NONE; *ponderMove = bestMove = skillBest = skillPonder = MOVE_NONE;
depth = aspirationDelta = 0; depth = delta = 0;
bestValue = alpha = -VALUE_INFINITE, beta = VALUE_INFINITE; bestValue = alpha = -VALUE_INFINITE, beta = VALUE_INFINITE;
ss->currentMove = MOVE_NULL; // Hack to skip update gains ss->currentMove = MOVE_NULL; // Hack to skip update gains
@ -467,17 +466,17 @@ namespace {
// MultiPV loop. We perform a full root search for each PV line // MultiPV loop. We perform a full root search for each PV line
for (MultiPVIdx = 0; MultiPVIdx < std::min(MultiPV, RootMoves.size()); MultiPVIdx++) for (MultiPVIdx = 0; MultiPVIdx < std::min(MultiPV, RootMoves.size()); MultiPVIdx++)
{ {
// Calculate dynamic aspiration window based on previous iterations // Calculate dynamic aspiration window based on previous iteration
if (depth >= 5 && abs(RootMoves[MultiPVIdx].prevScore) < VALUE_KNOWN_WIN) if (depth >= 5 && abs(RootMoves[MultiPVIdx].score) < VALUE_KNOWN_WIN)
{ {
int prevDelta1 = bestValues[depth - 1] - bestValues[depth - 2]; delta = abs(RootMoves[MultiPVIdx].score - RootMoves[MultiPVIdx].prevScore);
int prevDelta2 = bestValues[depth - 2] - bestValues[depth - 3]; delta = std::min(std::max(delta, 16), 24);
delta = (delta + 7) / 8 * 8; // Round to match grainSize
aspirationDelta = std::min(std::max(abs(prevDelta1) + abs(prevDelta2) / 2, 16), 24); alpha = RootMoves[MultiPVIdx].score - delta;
aspirationDelta = (aspirationDelta + 7) / 8 * 8; // Round to match grainSize beta = RootMoves[MultiPVIdx].score + delta;
alpha = std::max(RootMoves[MultiPVIdx].prevScore - aspirationDelta, -VALUE_INFINITE); assert(alpha > -VALUE_INFINITE && beta < VALUE_INFINITE);
beta = std::min(RootMoves[MultiPVIdx].prevScore + aspirationDelta, VALUE_INFINITE);
} }
else else
{ {
@ -545,16 +544,16 @@ namespace {
// research, otherwise exit the fail high/low loop. // research, otherwise exit the fail high/low loop.
if (bestValue >= beta) if (bestValue >= beta)
{ {
beta = std::min(beta + aspirationDelta, VALUE_INFINITE); beta = std::min(beta + delta, VALUE_INFINITE);
aspirationDelta += aspirationDelta / 2; delta += delta / 2;
} }
else if (bestValue <= alpha) else if (bestValue <= alpha)
{ {
Signals.failedLowAtRoot = true; Signals.failedLowAtRoot = true;
Signals.stopOnPonderhit = false; Signals.stopOnPonderhit = false;
alpha = std::max(alpha - aspirationDelta, -VALUE_INFINITE); alpha = std::max(alpha - delta, -VALUE_INFINITE);
aspirationDelta += aspirationDelta / 2; delta += delta / 2;
} }
else else
break; break;
@ -564,7 +563,6 @@ namespace {
bestMove = RootMoves[0].pv[0]; bestMove = RootMoves[0].pv[0];
*ponderMove = RootMoves[0].pv[1]; *ponderMove = RootMoves[0].pv[1];
bestValues[depth] = bestValue;
bestMoveChanges[depth] = BestMoveChanges; bestMoveChanges[depth] = BestMoveChanges;
// Skills: Do we need to pick now the best and the ponder moves ? // Skills: Do we need to pick now the best and the ponder moves ?