Introduce game variants
parent
3c82093c68
commit
fa0d737191
|
@ -16,7 +16,8 @@ case class DbGame(
|
|||
lastMove: Option[String],
|
||||
positionHashes: String = "",
|
||||
castles: String = "KQkq",
|
||||
isRated: Boolean = false) {
|
||||
isRated: Boolean = false,
|
||||
variant: Variant.Value = Variant.standard) {
|
||||
|
||||
val players = List(whitePlayer, blackPlayer)
|
||||
|
||||
|
|
|
@ -18,12 +18,14 @@ case class RawDbGame(
|
|||
lastMove: Option[String],
|
||||
positionHashes: String = "",
|
||||
castles: String = "KQkq",
|
||||
isRated: Boolean = false) {
|
||||
isRated: Boolean = false,
|
||||
variant: Int = 1) {
|
||||
|
||||
def decode: Option[DbGame] = for {
|
||||
whitePlayer ← players find (_.color == "white") flatMap (_.decode)
|
||||
blackPlayer ← players find (_.color == "black") flatMap (_.decode)
|
||||
trueStatus ← Status fromInt status
|
||||
trueVariant ← Variant fromInt variant
|
||||
validClock = clock flatMap (_.decode)
|
||||
if validClock.isDefined == clock.isDefined
|
||||
} yield DbGame(
|
||||
|
@ -37,7 +39,8 @@ case class RawDbGame(
|
|||
lastMove = lastMove,
|
||||
positionHashes = positionHashes,
|
||||
castles = castles,
|
||||
isRated = isRated
|
||||
isRated = isRated,
|
||||
variant = trueVariant
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -55,7 +58,8 @@ object RawDbGame {
|
|||
lastMove = lastMove,
|
||||
positionHashes = positionHashes,
|
||||
castles = castles,
|
||||
isRated = isRated
|
||||
isRated = isRated,
|
||||
variant = Variant toInt variant
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -24,3 +24,19 @@ object Status extends Enumeration {
|
|||
|
||||
def fromInt(i: Int): Option[Value] = indexed get i
|
||||
}
|
||||
|
||||
object Variant extends Enumeration {
|
||||
|
||||
val standard, chess960 = Value
|
||||
|
||||
def toInt(s: Value) = s match {
|
||||
case x if x == standard ⇒ 1
|
||||
case x if x == chess960 ⇒ 2
|
||||
}
|
||||
|
||||
val indexed: Map[Int, Value] = values map { v =>
|
||||
toInt(v) -> v
|
||||
} toMap
|
||||
|
||||
def fromInt(i: Int): Option[Value] = indexed get i
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue