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

34 lines
1.0 KiB
Scala
Raw Permalink 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-09-21 03:31:16 -06:00
def rankMatches(f: Option[Piece] => Boolean)(rank: Rank) =
File.all forall { file =>
2020-05-05 22:11:15 -06:00
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
2020-09-21 03:31:16 -06:00
}(Rank.First) &&
2020-05-05 22:11:15 -06:00
rankMatches {
case Some(Piece(White, Pawn)) => true
case _ => false
2020-09-21 03:31:16 -06:00
}(Rank.Second) &&
List(Rank.Third, Rank.Fourth, Rank.Fifth, Rank.Sixth).forall(rankMatches(_.isEmpty)) &&
2020-05-05 22:11:15 -06:00
rankMatches {
case Some(Piece(Black, Pawn)) => true
case _ => false
2020-09-21 03:31:16 -06:00
}(Rank.Seventh) &&
2020-05-05 22:11:15 -06:00
rankMatches {
case Some(Piece(Black, King | Queen | Rook | Knight | Bishop)) => true
case _ => false
2020-09-21 03:31:16 -06:00
}(Rank.Eighth)
2020-05-05 22:11:15 -06:00
}
}