Skip to content

Commit

Permalink
Apply insufficient material check when both players have bishops
Browse files Browse the repository at this point in the history
  • Loading branch information
ddugovic committed Aug 27, 2018
1 parent d5df15f commit 57f507b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/InsufficientMatingMaterial.scala
Expand Up @@ -11,8 +11,8 @@ object InsufficientMatingMaterial {
def nonKingPieces(board: Board) = board.pieces.filter(_._2.role != King).toList

/**
* Returns true when the only non-king pieces that remain are bishops that cannot
* capture each other and cannot checkmate (in atomic chess).
* Returns true when remaining non-King pieces are only bishops that cannot
* capture each other and cannot checkmate
*/
def bishopsOnDifferentColor(board: Board) = {
val notKingPieces = nonKingPieces(board)
Expand Down Expand Up @@ -63,7 +63,7 @@ object InsufficientMatingMaterial {
board rolesOf color filter (King !=) match {
case Nil => true
case List(Knight) => board rolesOf !color filter (King !=) filter (Queen !=) isEmpty
case List(Bishop) => board rolesOf !color filter (King !=) filter (Queen !=) filter (Rook !=) isEmpty
case List(Bishop) => (board rolesOf !color filter (King !=) filter (Queen !=) filter (Rook !=) filter (Bishop !=) isEmpty) || bishopsOnDifferentColor(board)
case _ => false
}
}
5 changes: 2 additions & 3 deletions src/test/scala/VariantTest.scala
Expand Up @@ -15,7 +15,7 @@ class VariantTest extends ChessTest {
}

"Identify insufficient mating material when called (bishop)." in {
val position = "8/3k4/2q5/8/8/K1B5/8/8 w - -"
val position = "krq5/bqqq4/qqr5/1qq5/8/8/8/3qB2K b - -"
val game = fenToGame(position, Standard)

game should beSuccess.like {
Expand All @@ -25,14 +25,13 @@ class VariantTest extends ChessTest {
}

"Identify insufficient mating material when called (knight)." in {
val position = "8/3k4/2q5/8/8/K1N5/8/8 w - -"
val position = "8/3k4/2q5/8/8/K1N5/8/8 b - -"
val game = fenToGame(position, Standard)

game should beSuccess.like {
case game =>
game.situation.board.variant.insufficientWinningMaterial(game.situation.board, Color.white) must beTrue
}

}
}

Expand Down

0 comments on commit 57f507b

Please sign in to comment.