Start implementing AI support
parent
62b82e91af
commit
03dc668a79
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
)
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue