improve ai server

This commit is contained in:
Thibault Duplessis 2013-06-04 16:27:07 +02:00
parent f6cbfd61da
commit 1109981800
8 changed files with 42 additions and 58 deletions

View file

@ -4,9 +4,9 @@ import akka.actor._
import com.typesafe.config.Config
final class Env(
config: Config,
system: ActorSystem,
appPath: String) {
config: Config,
system: ActorSystem,
appPath: String) {
val CliUsername = config getString "cli.username"
@ -40,23 +40,25 @@ final class Env(
domain = Env.api.Net.Domain
)), name = RouterName)
loginfo("[boot] Preloading modules")
(Env.site,
Env.tournament,
Env.lobby,
Env.game,
Env.ai,
Env.setup,
Env.round,
Env.team,
Env.message,
Env.socket,
Env.timeline,
Env.gameSearch,
Env.teamSearch,
Env.forumSearch,
Env.relation)
loginfo("[boot] Preloading complete")
if (!Env.ai.isServer) {
loginfo("[boot] Preloading modules")
(Env.site,
Env.tournament,
Env.lobby,
Env.game,
Env.ai,
Env.setup,
Env.round,
Env.team,
Env.message,
Env.socket,
Env.timeline,
Env.gameSearch,
Env.teamSearch,
Env.forumSearch,
Env.relation)
loginfo("[boot] Preloading complete")
}
if (Env.ai.isServer) println("Running as AI server")
}

View file

@ -10,12 +10,12 @@ object Ai extends LilaController {
private def stockfishServer = Env.ai.stockfishServer
private def isServer = Env.ai.isServer
def playStockfish = Open { implicit ctx
def playStockfish = Action { req
IfServer {
stockfishServer.play(
pgn = getOr("pgn", ""),
initialFen = get("initialFen"),
level = getIntOr("level", 1)
pgn = ~get("pgn", req),
initialFen = get("initialFen", req),
level = getInt("level", req) | 1
) fold (
err {
logwarn("[ai] stochfish server play: " + err)
@ -26,11 +26,11 @@ object Ai extends LilaController {
}
}
def analyseStockfish = Open { implicit ctx
def analyseStockfish = Action { req
IfServer {
stockfishServer.analyse(
pgn = getOr("pgn", ""),
initialFen = get("initialFen")
pgn = ~get("pgn", req),
initialFen = get("initialFen", req)
) fold (
err {
logwarn("[ai] stochfish server analyse: " + err)
@ -42,5 +42,5 @@ object Ai extends LilaController {
}
private def IfServer(result: Fu[Result]) =
isServer.fold(result, BadRequest("Not an AI server").fuccess)
isServer.fold(Async(result), BadRequest("Not an AI server"))
}

View file

@ -17,10 +17,4 @@ trait RequestGetter {
protected def getInt(name: String, req: RequestHeader): Option[Int] =
req.queryString get name flatMap (_.headOption) flatMap parseIntOption
protected def getOr(name: String, default: String)(implicit ctx: Context) =
get(name)(ctx) getOrElse default
protected def getIntOr(name: String, default: Int)(implicit ctx: Context) =
getInt(name)(ctx) getOrElse default
}

View file

@ -1,19 +1,13 @@
# /etc/init/lila.conf
#
# Assumes lila is deployed to /home/lila
#
# Start lila: service lila start
# Stop lila: service lila stop
# Restart lila: service lila restart
# /etc/init/lila
limit nofile 65536 65536
kill timeout 3 # wait between SIGTERM and SIGKILL.
pre-start script
rm -f /home/lila/RUNNING_PID
mkdir -p /home/lila/logs
chown -R lila:users /home/lila/logs
rm -f /home/lila4/RUNNING_PID
mkdir -p /home/lila4/logs
chown -R lila:users /home/lila4/logs
end script
start on runlevel [2345]
@ -21,4 +15,4 @@ stop on runlevel [06]
respawn
exec su -s /bin/sh -c 'exec "$0" "$@"' lila -- /home/lila/start -Dfile.encoding=UTF8 -Xms512M -Xmx8192M -Xss4M -XX:MaxPermSize=4096M > /home/lila/logs/output.log
exec su -s /bin/sh -c 'exec "$0" "$@"' lila -- /home/lila4/target/start -Dconfig.file=/home/lila4/application.conf -Dhttp.port=9004 -Dfile.encoding=UTF8 -Xms512M -Xmx8192M -Xss4M -XX:MaxPermSize=4096M > /home/lila4/logs/output.log

View file

@ -1,18 +1,14 @@
include "base"
mongodb {
servers = []
}
ai {
server = true
client = false
stockfish {
hash_size = 8192
analyse {
movetime = 500
}
play {
movetime = 400
}
analyse.movetime = 500
play.movetime = 400
}
}
app {
scheduler.enabled = false
}

View file

@ -16,7 +16,7 @@ object PlayApp {
play.api.libs.concurrent.Akka.system
}
private def enableScheduler = loadConfig getBoolean "app.scheduler.enabled"
private def enableScheduler = !(loadConfig getBoolean "app.scheduler.disabled")
def scheduler = new Scheduler(system, enabled = enableScheduler && isServer)

View file

@ -20,5 +20,5 @@ final class Ranking(ttl: Duration) {
UserRepo.enabledQuery ++ Json.obj("elo" -> $gt(User.STARTING_ELO)),
"_id",
_ sort UserRepo.sortEloDesc
)(_.asOpt[String]) map { _.pp.zipWithIndex.toMap }
)(_.asOpt[String]) map { _.zipWithIndex.toMap }
}

2
todo
View file

@ -56,9 +56,7 @@ show teams in user mini
badges for top players in ELO and number of games
the forum search user:mephostophilis returns no result
check team average elo http://en.lichess.org/inbox/benuegti#bottom
if game ends during move -> bug
challenge friends
computer players ranks once a day
players world map
---