Time limits are updated when the engine stops pondering
This commit is contained in:
parent
d9e183caf3
commit
836e9e6a34
|
@ -121,6 +121,7 @@ type
|
||||||
transpositionTable: ptr TTable
|
transpositionTable: ptr TTable
|
||||||
history: ptr HistoryTable
|
history: ptr HistoryTable
|
||||||
killers: ptr KillersTable
|
killers: ptr KillersTable
|
||||||
|
maxSearchTime: int64
|
||||||
# We keep one extra entry so we don't need any special casing
|
# We keep one extra entry so we don't need any special casing
|
||||||
# inside the search function when constructing pv lines
|
# inside the search function when constructing pv lines
|
||||||
pvMoves: array[MAX_DEPTH + 1, array[MAX_DEPTH + 1, Move]]
|
pvMoves: array[MAX_DEPTH + 1, array[MAX_DEPTH + 1, Move]]
|
||||||
|
@ -248,11 +249,17 @@ proc reorderMoves(self: SearchManager, moves: var MoveList, ply: int) =
|
||||||
|
|
||||||
proc timedOut(self: SearchManager): bool = getMonoTime() >= self.hardLimit
|
proc timedOut(self: SearchManager): bool = getMonoTime() >= self.hardLimit
|
||||||
proc isPondering*(self: var SearchManager): bool = self.pondering.load()
|
proc isPondering*(self: var SearchManager): bool = self.pondering.load()
|
||||||
proc stopPondering*(self: var SearchManager) = self.pondering.store(false)
|
|
||||||
proc cancelled(self: var SearchManager): bool = self.stop.load()
|
proc cancelled(self: var SearchManager): bool = self.stop.load()
|
||||||
proc elapsedTime(self: SearchManager): int64 = (getMonoTime() - self.searchStart).inMilliseconds()
|
proc elapsedTime(self: SearchManager): int64 = (getMonoTime() - self.searchStart).inMilliseconds()
|
||||||
|
|
||||||
|
|
||||||
|
proc stopPondering*(self: var SearchManager) =
|
||||||
|
self.pondering.store(false)
|
||||||
|
let t = getMonoTime()
|
||||||
|
self.hardLimit = t + initDuration(milliseconds=self.maxSearchTime)
|
||||||
|
self.softLimit = t + initDuration(milliseconds=self.maxSearchTime div 3)
|
||||||
|
|
||||||
|
|
||||||
proc log(self: SearchManager, depth: int) =
|
proc log(self: SearchManager, depth: int) =
|
||||||
let
|
let
|
||||||
elapsedMsec = self.elapsedTime().uint64
|
elapsedMsec = self.elapsedTime().uint64
|
||||||
|
@ -641,16 +648,15 @@ proc findBestLine*(self: var SearchManager, timeRemaining, increment: int64, max
|
||||||
## variation instead of the best move
|
## variation instead of the best move
|
||||||
|
|
||||||
# Apparently negative remaining time is a thing. Welp
|
# Apparently negative remaining time is a thing. Welp
|
||||||
let
|
self.maxSearchTime = if not timePerMove: max(1, (timeRemaining div 10) + ((increment div 3) * 2)) else: timeRemaining
|
||||||
maxSearchTime = if not timePerMove: max(1, (timeRemaining div 10) + ((increment div 3) * 2)) else: timeRemaining
|
let softLimit = if not timePerMove: self.maxSearchTime div 3 else: self.maxSearchTime
|
||||||
softLimit = if not timePerMove: maxSearchTime div 3 else: maxSearchTime
|
|
||||||
result = @[]
|
result = @[]
|
||||||
var pv: array[256, Move]
|
var pv: array[256, Move]
|
||||||
self.maxNodes = maxNodes
|
self.maxNodes = maxNodes
|
||||||
self.pondering.store(ponder)
|
self.pondering.store(ponder)
|
||||||
self.searchMoves = searchMoves
|
self.searchMoves = searchMoves
|
||||||
self.searchStart = getMonoTime()
|
self.searchStart = getMonoTime()
|
||||||
self.hardLimit = self.searchStart + initDuration(milliseconds=maxSearchTime)
|
self.hardLimit = self.searchStart + initDuration(milliseconds=self.maxSearchTime)
|
||||||
self.softLimit = self.searchStart + initDuration(milliseconds=softLimit)
|
self.softLimit = self.searchStart + initDuration(milliseconds=softLimit)
|
||||||
var maxDepth = maxDepth
|
var maxDepth = maxDepth
|
||||||
if maxDepth == -1:
|
if maxDepth == -1:
|
||||||
|
|
|
@ -353,6 +353,7 @@ proc startUCISession* =
|
||||||
echo "id name Nimfish 0.1"
|
echo "id name Nimfish 0.1"
|
||||||
echo "id author Nocturn9x & Contributors (see LICENSE)"
|
echo "id author Nocturn9x & Contributors (see LICENSE)"
|
||||||
echo "option name Hash type spin default 64 min 1 max 33554432"
|
echo "option name Hash type spin default 64 min 1 max 33554432"
|
||||||
|
echo "option name Threads type spin default 1 min 1 max 1"
|
||||||
echo "uciok"
|
echo "uciok"
|
||||||
var
|
var
|
||||||
cmd: UCICommand
|
cmd: UCICommand
|
||||||
|
|
Loading…
Reference in New Issue