Start implementing AI support

pull/1/merge
Thibault Duplessis 2012-03-04 17:47:39 +01:00
parent 62b82e91af
commit 03dc668a79
3 changed files with 9 additions and 39 deletions

View File

@ -22,9 +22,14 @@ final class Server(repo: GameRepo) {
newChessGameAndMove chessGame(orig, dest, promotion)
(newChessGame, move) = newChessGameAndMove
g3 = g2.update(newChessGame, move)
g4 if (g3.player.isAi) aiResponse(g3) else success(g3)
result unsafe { repo save g3 }
} yield newChessGame.situation.destinations
private def aiResponse(dbGame: DbGame): Valid[DbGame] = {
success(dbGame)
}
private def moveToEvents(move: Move): Map[DbPlayer, EventStack] = Map.empty
private def decodeMoveString(moveString: String): Option[(String, String)] = moveString match {

View File

@ -1,38 +0,0 @@
package lila.system
import ornicar.scalalib.{IntStatus, IntStatuses}
import lila.chess.Situation
sealed case class GameStatus(id: Int, name: String) extends IntStatus
sealed case class GameVariant(id: Int, name: String) extends IntStatus
object GameStatuses extends IntStatuses[GameStatus] {
val values = Set(
GameStatus(10, "created"),
GameStatus(20, "started"),
GameStatus(25, "aborted"),
GameStatus(30, "mate"),
GameStatus(31, "resign"),
GameStatus(32, "stalemate"),
GameStatus(33, "timeout"),
GameStatus(34, "draw"),
GameStatus(35, "outoftime"),
GameStatus(36, "cheat")
)
def fromSituation(situation: Situation): Option[Int] = {
if (situation.checkMate) find("checkmate")
else if (situation.staleMate) find("stalemate")
else if (situation.autoDraw) find("draw")
else None
} map (_.toInt)
}
object GameVariants extends IntStatuses[GameVariant] {
val values = Set(
GameVariant(1, "variant_standard"),
GameVariant(2, "variant_960")
)
}

View File

@ -17,12 +17,15 @@ case class DbGame(
clock: Option[DbClock],
lastMove: Option[String],
positionHashes: String = "",
castles: String = "KQkq") {
castles: String = "KQkq",
isRated: Boolean = false) {
def playerById(id: String): Option[DbPlayer] = playersById get id
def playerByColor(color: String): Option[DbPlayer] = playersByColor get color
def player: DbPlayer = playerByColor(if (0 == turns % 2) "white" else "black") get
lazy val playersByColor: Map[String, DbPlayer] = players map { p (p.color, p) } toMap
lazy val playersById: Map[String, DbPlayer] = players map { p (p.id, p) } toMap