lila/modules/importer/src/main/Chess960.scala

39 lines
1.1 KiB
Scala
Raw Normal View History

package lila.importer
import chess._
2019-12-03 10:08:27 -07:00
private object Chess960 {
def isStartPosition(board: Board) = board valid true && {
def rankMatches(f: Option[Piece] => Boolean)(rank: Int) =
2019-12-13 07:30:20 -07:00
(1 to 8) forall { file =>
f(board(file, rank))
}
rankMatches {
case Some(Piece(White, King | Queen | Rook | Knight | Bishop)) => true
2019-12-13 07:30:20 -07:00
case _ => false
}(1) &&
2019-12-13 07:30:20 -07:00
rankMatches {
case Some(Piece(White, Pawn)) => true
case _ => false
}(2) &&
List(3, 4, 5, 6).forall(rankMatches(_.isEmpty)) &&
rankMatches {
case Some(Piece(Black, Pawn)) => true
case _ => false
}(7) &&
rankMatches {
case Some(Piece(Black, King | Queen | Rook | Knight | Bishop)) => true
case _ => false
}(8)
}
def fixVariantName(v: String) = v.toLowerCase match {
2019-12-13 07:30:20 -07:00
case "chess 960" => "chess960"
case "fisherandom" => "chess960" // I swear, sometimes...
2019-12-13 07:30:20 -07:00
case _ => v
}
}