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

41 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 {
2020-05-05 22:11:15 -06:00
def isStartPosition(board: Board) =
2020-08-16 06:55:33 -06:00
board valid {
2020-05-05 22:11:15 -06:00
def rankMatches(f: Option[Piece] => Boolean)(rank: Int) =
(1 to 8) forall { file =>
f(board(file, rank))
}
2020-05-05 22:11:15 -06:00
rankMatches {
case Some(Piece(White, King | Queen | Rook | Knight | Bishop)) => true
case _ => false
}(1) &&
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)
}
2020-05-05 22:11:15 -06:00
def fixVariantName(v: String) =
v.toLowerCase match {
case "chess 960" => "chess960"
case "fisherandom" => "chess960" // I swear, sometimes...
case _ => v
}
}