Skip to content

Commit d454cd4

Browse files
Matt14916mcostalba
authored andcommitted
Fix divide by zero bug in late game
If the game got late enough that move_importance(currentPly) * slowMover / 100 rounds to 0, then we ended up dividing 0 by 0 when only looking 1 move ahead. This apparently caused the search to almost immediately abort and Stockfish would blunder in long games. So convert thisMoveImportance to a double. No functional change.
1 parent 48f38f3 commit d454cd4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/timeman.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ namespace {
147147
const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
148148
const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
149149

150-
int thisMoveImportance = move_importance(currentPly) * slowMover / 100;
150+
double thisMoveImportance = double(move_importance(currentPly) * slowMover) / 100;
151151
int otherMovesImportance = 0;
152152

153153
for (int i = 1; i < movesToGo; ++i)
154154
otherMovesImportance += move_importance(currentPly + 2 * i);
155155

156-
double ratio1 = (TMaxRatio * thisMoveImportance) / double(TMaxRatio * thisMoveImportance + otherMovesImportance);
157-
double ratio2 = (thisMoveImportance + TStealRatio * otherMovesImportance) / double(thisMoveImportance + otherMovesImportance);
156+
double ratio1 = (TMaxRatio * thisMoveImportance) / (TMaxRatio * thisMoveImportance + otherMovesImportance);
157+
double ratio2 = (thisMoveImportance + TStealRatio * otherMovesImportance) / (thisMoveImportance + otherMovesImportance);
158158

159159
return int(floor(myTime * std::min(ratio1, ratio2)));
160160
}

0 commit comments

Comments
 (0)