lazy AI backend resolution

This commit is contained in:
Thibault Duplessis 2013-05-29 12:39:04 +02:00
parent 8e534c7c9a
commit 9b0364fd68
5 changed files with 12 additions and 12 deletions

View file

@ -22,7 +22,7 @@ final class Env(
}
import settings._
lazy val ai: Ai = (EngineName, IsClient) match {
val ai: () Ai = () (EngineName, IsClient) match {
case ("stockfish", true) stockfishClient or stockfishAi
case ("stockfish", false) stockfishAi
case _ stupidAi
@ -39,7 +39,7 @@ final class Env(
def receive = {
case lila.hub.actorApi.ai.Ping sender ! clientPing
case lila.hub.actorApi.ai.Analyse(id, pgn, fen)
ai.analyse(pgn, fen) map { _(id) } pipeTo sender
ai().analyse(pgn, fen) map { _(id) } pipeTo sender
}
}), name = ActorName)

View file

@ -15,7 +15,7 @@ final class Env(
flood: lila.security.Flood,
db: lila.db.Env,
hub: lila.hub.Env,
ai: lila.ai.Ai,
ai: () lila.ai.Ai,
getUsername: String Fu[Option[String]],
i18nKeys: lila.i18n.I18nKeys,
scheduler: lila.common.Scheduler) {

View file

@ -9,7 +9,7 @@ import lila.game.{ Game, GameRepo, PgnRepo, Pov, Progress }
import lila.hub.actorApi.Tell
private[round] final class Player(
ai: Ai,
ai: () Ai,
notifyMove: (String, String, Option[String]) Unit,
finisher: Finisher,
roundMap: lila.hub.ActorLazyRef) {
@ -46,7 +46,7 @@ private[round] final class Player(
(game.variant.exotic ?? { GameRepo initialFen game.id }) zip
(PgnRepo get game.id) flatMap {
case (fen, pgn)
ai.play(game.toChess, pgn, fen, ~game.aiLevel) flatMap {
ai().play(game.toChess, pgn, fen, ~game.aiLevel) flatMap {
case (newChessGame, move) {
val (progress, pgn2) = game.update(newChessGame, move)
(GameRepo save progress) >>

View file

@ -1,7 +1,7 @@
package lila.setup
import akka.actor._
import com.typesafe.config.{ Config => AppConfig }
import com.typesafe.config.{ Config AppConfig }
import lila.common.PimpedConfig._
import lila.user.Context
@ -11,7 +11,7 @@ final class Env(
db: lila.db.Env,
hub: lila.hub.Env,
messenger: lila.round.Messenger,
ai: lila.ai.Ai,
ai: () lila.ai.Ai,
system: ActorSystem) {
private val FriendMemoTtl = config duration "friend.memo.ttl"
@ -20,7 +20,7 @@ final class Env(
lazy val forms = new FormFactory
def filter(implicit ctx: Context): Fu[FilterConfig] =
def filter(implicit ctx: Context): Fu[FilterConfig] =
ctx.me.fold(AnonConfigRepo filter ctx.req)(UserConfigRepo.filter)
lazy val processor = new Processor(
@ -28,7 +28,7 @@ final class Env(
friendConfigMemo = friendConfigMemo,
timeline = hub.actor.gameTimeline,
router = hub.actor.router,
ai = ai)
getAi = ai)
lazy val friendJoiner = new FriendJoiner(
messenger = messenger,

View file

@ -21,7 +21,7 @@ private[setup] final class Processor(
friendConfigMemo: FriendConfigMemo,
timeline: lila.hub.ActorLazyRef,
router: lila.hub.ActorLazyRef,
ai: Ai) {
getAi: () Ai) {
def filter(config: FilterConfig)(implicit ctx: Context): Funit =
saveConfig(_ withFilter config)
@ -35,7 +35,7 @@ private[setup] final class Processor(
game.player.isHuman.fold(fuccess(pov), for {
initialFen game.variant.exotic ?? (GameRepo initialFen game.id)
pgnString PgnRepo get game.id
aiResult ai.play(game.toChess, pgnString, initialFen, ~game.aiLevel)
aiResult getAi().play(game.toChess, pgnString, initialFen, ~game.aiLevel)
(newChessGame, move) = aiResult
(progress, pgn) = game.update(newChessGame, move)
_ (GameRepo save progress) >> PgnRepo.save(game.id, pgn)
@ -52,7 +52,7 @@ private[setup] final class Processor(
def hook(config: HookConfig, uid: String)(implicit ctx: Context): Funit = {
val hook = config.hook(uid, ctx.me)
saveConfig(_ withHook config) >>- (lobby ! AddHook(hook))
saveConfig(_ withHook config) >>- (lobby ! AddHook(hook))
}
def api(implicit ctx: Context): Fu[JsObject] = {