Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 29, 2016
1 parent 5fac992 commit 1563eb3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
28 changes: 12 additions & 16 deletions src/main/scala/InsufficientMatingMaterial.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,24 @@ object InsufficientMatingMaterial {
val notKingPieces = nonKingPieces(board)
val onlyBishopsRemain = !notKingPieces.exists(_._2.role != Bishop)

if (!onlyBishopsRemain) {
false
}
if (!onlyBishopsRemain) false
else {
val whitePlayerBishops = notKingPieces.filter(_._2.color == Color.White)
val blackPlayerBishops = notKingPieces.filter(_._2.color == Color.Black)
val whitePlayerBishops = notKingPieces.filter(_._2.color == Color.White)
val blackPlayerBishops = notKingPieces.filter(_._2.color == Color.Black)

!whitePlayerBishops.exists {
case (pos, _) =>
val squareColor = pos.color
blackPlayerBishops.exists(_._1.color == squareColor)
}
!whitePlayerBishops.exists {
case (pos, _) => blackPlayerBishops.exists(_._1.color == pos.color)
}
}
}

/*
* Returns true if a pawn cannot progress forward because it is blocked by a pawn
*/
def pawnBlockedByPawn(pawn: Actor, board: Board) = pawn.moves.isEmpty && {
val blockingPosition = Actor.posAheadOfPawn(pawn.pos, pawn.piece.color)
blockingPosition.flatMap(board.actorAt(_)).exists(_.piece.is(Pawn))
}
val blockingPosition = Actor.posAheadOfPawn(pawn.pos, pawn.piece.color)
blockingPosition.flatMap(board.actorAt(_)).exists(_.piece.is(Pawn))
}
/*
* Determines whether a board position is an automatic draw due to neither player
* being able to mate the other as informed by the traditional chess rules.
Expand All @@ -62,7 +58,7 @@ object InsufficientMatingMaterial {

def apply(board: Board, color: Color) =
board rolesOf color filter (King !=) match {
case Nil | List(Knight) | List(Bishop) => true
case _ => false
}
case Nil | List(Knight) | List(Bishop) => true
case _ => false
}
}
14 changes: 7 additions & 7 deletions src/test/scala/AutodrawTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,37 @@ class AutodrawTest extends ChessTest {
k
K """.autoDraw must_== true
}
"two kings and one pawn" in {
"one pawn" in {
"""
P k
K """.autoDraw must_== false
}
"two kings and one bishop" in {
"one bishop" in {
"""
k
K B""".autoDraw must_== true
}
"two kings, one bishop and one knight of different colors" in {
"one bishop and one knight of different colors" in {
"""
k
K n B""".autoDraw must_== false
}
"two kings, one bishop and one knight of same color" in {
"one bishop and one knight of same color" in {
"""
B k
K N """.autoDraw must_== false
}
"two kings, one bishop and one rook of different colors" in {
"one bishop and one rook of different colors" in {
"""
k
K r B""".autoDraw must_== false
}
"two kings, one bishop and one bishop of same colors" in {
"one bishop and one bishop of same colors" in {
"""
k
K b B""".autoDraw must_== true
}
"two kings, one bishop and one bishop of different colors" in {
"one bishop and one bishop of different colors" in {
"""
k
K bB""".autoDraw must_== false
Expand Down

0 comments on commit 1563eb3

Please sign in to comment.