Time fix #36
No files matched your search
+10
-6
@@ -117,7 +117,7 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int
|
||||
}
|
||||
|
||||
static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
|
||||
if (!benchStarted) {
|
||||
if (!benchStarted && nodes % 1024 == 0) {
|
||||
if (sw.GetElapsedMS() >= timeToSearch) {
|
||||
StopSearch();
|
||||
return 0;
|
||||
@@ -166,7 +166,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
|
||||
|
||||
template <bool isPV>
|
||||
SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
|
||||
if (!benchStarted) {
|
||||
if (!benchStarted && nodes % 1024 == 0) {
|
||||
if (sw.GetElapsedMS() >= timeToSearch) {
|
||||
StopSearch();
|
||||
return 0;
|
||||
@@ -269,12 +269,13 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
|
||||
score = -PVS<isPV>(copy, depth - 1, -beta, -alpha, ply + 1).score;
|
||||
}
|
||||
|
||||
if (searchStopped) return 0;
|
||||
|
||||
moveSeen++;
|
||||
positionIndex--;
|
||||
|
||||
// Fail high (beta cutoff)
|
||||
if (score >= beta) {
|
||||
if (searchStopped) return 0;
|
||||
if (!currMove.IsCapture()) {
|
||||
killerMoves[1][ply] = killerMoves[0][ply];
|
||||
killerMoves[0][ply] = currMove;
|
||||
@@ -312,8 +313,6 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
|
||||
|
||||
// Iterative deepening
|
||||
static SearchResults ID(Board &board, SearchParams params) {
|
||||
sw.Restart();
|
||||
|
||||
int fullTime = board.sideToMove ? params.btime : params.wtime;
|
||||
int inc = board.sideToMove ? params.binc : params.winc;
|
||||
|
||||
@@ -327,11 +326,15 @@ static SearchResults ID(Board &board, SearchParams params) {
|
||||
|
||||
int ply = 0;
|
||||
|
||||
int elapsed = 0;
|
||||
sw.Restart();
|
||||
|
||||
for (int depth = 1; depth <= 99; depth++) {
|
||||
timeToSearch = (fullTime / 20) + (inc / 2);
|
||||
timeToSearch = std::max((fullTime / 20) + (inc / 2), 4);
|
||||
int softTime = timeToSearch * 0.65;
|
||||
|
||||
SearchResults currentResults = PVS<true>(board, depth, alpha, beta, ply);
|
||||
elapsed = sw.GetElapsedMS();
|
||||
|
||||
// If we fell outside the window, try again with full width
|
||||
if ((currentResults.score <= alpha)
|
||||
@@ -360,6 +363,7 @@ static SearchResults ID(Board &board, SearchParams params) {
|
||||
|
||||
std::cout << "info ";
|
||||
std::cout << "depth " << depth;
|
||||
std::cout << " time " << elapsed;
|
||||
std::cout << " score cp " << safeResults.score;
|
||||
std::cout << " nodes " << nodes << " nps " << int(nodes/sw.GetElapsedSec());
|
||||
std::cout << " hashfull " << TT.GetUsedPercentage();
|
||||
|
||||
+17
-6
@@ -40,18 +40,29 @@ static void ParsePosition(Board &board, std::string_view command) {
|
||||
}
|
||||
|
||||
static int ReadParam(std::string param, std::string &command) {
|
||||
size_t pos = -1;
|
||||
pos = command.find(param);
|
||||
|
||||
size_t pos = command.find(param);
|
||||
if (pos != std::string::npos) {
|
||||
std::string result = "";
|
||||
pos += param.length() + 1;
|
||||
bool isNegative = false;
|
||||
std::string result = "";
|
||||
|
||||
while(pos < command.length() && std::isdigit(command[pos])){
|
||||
// Check for negative sign
|
||||
if (pos < command.length() && command[pos] == '-') {
|
||||
isNegative = true;
|
||||
pos++;
|
||||
}
|
||||
|
||||
// Extract digits
|
||||
while (pos < command.length() && std::isdigit(command[pos])) {
|
||||
result += command[pos];
|
||||
pos++;
|
||||
}
|
||||
return stoi(result);
|
||||
|
||||
// Ensure result is not empty before calling stoi
|
||||
if (!result.empty()) {
|
||||
int value = std::stoi(result);
|
||||
return isNegative ? -value : value;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user