improve AI timeouts configuration
This commit is contained in:
parent
789a08b9c3
commit
84875d9b4b
|
@ -69,8 +69,10 @@ final class Env(
|
|||
private lazy val stockfishConfig = new stockfish.Config(
|
||||
hashSize = config getInt "stockfish.hash_size",
|
||||
nbThreads = config getInt "stockfish.threads",
|
||||
playMaxMoveTime = config getInt "stockfish.play.movetime",
|
||||
analyseMoveTime = config getInt "stockfish.analyse.movetime",
|
||||
playMaxMoveTime = config duration "stockfish.play.movetime",
|
||||
analyseMoveTime = config duration "stockfish.analyse.movetime",
|
||||
playTimeout = config duration "stockfish.play.timeout",
|
||||
analyseTimeout = config duration "stockfish.play.timeout",
|
||||
debug = config getBoolean "stockfish.debug")
|
||||
|
||||
private lazy val client = (EngineName, IsClient) match {
|
||||
|
|
|
@ -2,17 +2,20 @@ package lila.ai
|
|||
package stockfish
|
||||
|
||||
import model._
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
|
||||
private[ai] final class Config(
|
||||
hashSize: Int,
|
||||
nbThreads: Int,
|
||||
playMaxMoveTime: Int,
|
||||
analyseMoveTime: Int,
|
||||
playMaxMoveTime: FiniteDuration,
|
||||
analyseMoveTime: FiniteDuration,
|
||||
val playTimeout: FiniteDuration,
|
||||
val analyseTimeout: FiniteDuration,
|
||||
val debug: Boolean) {
|
||||
|
||||
import Config._
|
||||
|
||||
def moveTime(level: Int) = (levelBox(level) * playMaxMoveTime) / levels.end
|
||||
def moveTime(level: Int) = (levelBox(level) * playMaxMoveTime.toMillis) / levels.end
|
||||
|
||||
def ownBook(level: Int) = levelBox(level) > 4
|
||||
|
||||
|
@ -57,7 +60,7 @@ private[ai] final class Config(
|
|||
)),
|
||||
anal ⇒ List(
|
||||
position(anal.fen, anal.pastMoves),
|
||||
"go movetime %d".format(analyseMoveTime)))
|
||||
"go movetime %d".format(analyseMoveTime.toMillis)))
|
||||
|
||||
private def position(fen: Option[String], moves: String) =
|
||||
"position %s moves %s".format(fen.fold("startpos")("fen " + _), moves)
|
||||
|
|
|
@ -18,7 +18,7 @@ import lila.analyse.Analysis
|
|||
final class Server(execPath: String, config: Config) {
|
||||
|
||||
def play(pgn: String, initialFen: Option[String], level: Int): Fu[String] = {
|
||||
implicit val timeout = makeTimeout(playAtMost)
|
||||
implicit val timeout = makeTimeout(config.playTimeout)
|
||||
UciDump(pgn, initialFen) map { moves ⇒
|
||||
model.play.Task.Builder(moves, initialFen map chess960Fen, level)
|
||||
} fold (
|
||||
|
@ -34,7 +34,7 @@ final class Server(execPath: String, config: Config) {
|
|||
err ⇒ fufail(err),
|
||||
moves ⇒ {
|
||||
val analyse = model.analyse.Task.Builder(moves, initialFen map chess960Fen)
|
||||
implicit val timeout = makeTimeout(analyseAtMost)
|
||||
implicit val timeout = makeTimeout(config.analyseTimeout)
|
||||
(actor ? analyse).mapTo[String ⇒ Analysis] ~ { _ onFailure reboot }
|
||||
}
|
||||
)
|
||||
|
@ -53,9 +53,6 @@ final class Server(execPath: String, config: Config) {
|
|||
case e: AskTimeoutException ⇒ actor ! model.RebootException
|
||||
}
|
||||
|
||||
private val playAtMost = 10 seconds
|
||||
private val analyseAtMost = 20 minutes
|
||||
|
||||
private lazy val process = Process(execPath, "StockFish") _
|
||||
private lazy val actor = system.actorOf(Props(
|
||||
new ActorFSM(process, config)))
|
||||
|
|
Loading…
Reference in a new issue