Skip to content

Commit

Permalink
don't pass Situation when only Board is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 13, 2016
1 parent 9ceff35 commit a5917d8
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/main/scala/Situation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ case class Situation(board: Board, color: Color) {
)

def canCastle = board.history.canCastle _

def unary_! = copy(color = !color)
}

object Situation {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/variant/Antichess.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ case object Antichess extends Variant(

// In antichess, there is no checkmate condition therefore a player may only draw either by agreement
// , blockade or stalemate - a player always has sufficient material to win otherwise
override def insufficientWinningMaterial(situation: Situation, color: Color) = false
override def insufficientWinningMaterial(board: Board, color: Color) = false

// No player can win if the only remaining pieces are opposing bishops on different coloured
// diagonals. There may be pawns that are incapable of moving and do not attack the right color
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/variant/Atomic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ case object Atomic extends Variant(
* a piece in the opponent's king's proximity. On the other hand, a king alone or a king with
* immobile pawns is not sufficient material to win with.
*/
override def insufficientWinningMaterial(situation: Situation, color: Color) =
situation.board.rolesOf(color) == List(King)
override def insufficientWinningMaterial(board: Board, color: Color) =
board.rolesOf(color) == List(King)

/** Atomic chess has a special end where a king has been killed by exploding with an adjacent captured piece */
override def specialEnd(situation: Situation) = situation.board.kingPos.size != 2
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/variant/Horde.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ case object Horde extends Variant(
* In horde chess, white cannot win on * V K or [BN]{2} v K or just one piece since they don't have a king
* for support.
*/
override def insufficientWinningMaterial(situation: Situation, color: Color) = {
color == Color.white && situation.board.piecesOf(Color.white).size == 1 ||
situation.board.piecesOf(Color.white).size == 2 &&
situation.board.piecesOf(Color.white).forall(_._2.isMinor)
override def insufficientWinningMaterial(board: Board, color: Color) = {
color == Color.white && board.piecesOf(Color.white).size == 1 ||
board.piecesOf(Color.white).size == 2 &&
board.piecesOf(Color.white).forall(_._2.isMinor)
}

override def isUnmovedPawn(color: Color, pos: Pos) = {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/variant/KingOfTheHill.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ case object KingOfTheHill extends Variant(
/**
* You only need a king to be able to win in this variant
*/
override def insufficientWinningMaterial(situation: Situation, color: Color) = false
override def insufficientWinningMaterial(board: Board, color: Color) = false

override def insufficientWinningMaterial(board: Board) = false
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/variant/Threecheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ case object ThreeCheck extends Variant(
/**
* It's not possible to check or checkmate the opponent with only a king
*/
override def insufficientWinningMaterial(situation: Situation, color: Color) =
situation.board.rolesOf(color) == List(King)
override def insufficientWinningMaterial(board: Board, color: Color) =
board.rolesOf(color) == List(King)

// When there is insufficient mating material, there is still potential to win by checking the opponent 3 times
// by the variant ending. However, no players can check if there are only kings remaining
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/variant/Variant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ abstract class Variant(
* This can be used to determine whether a player losing on time against a player
* who doesn't have enough material to win should draw instead.
*/
def insufficientWinningMaterial(situation: Situation, color: Color) = InsufficientMatingMaterial(situation.board, color)
def insufficientWinningMaterial(board: Board, color: Color) = InsufficientMatingMaterial(board, color)

// Some variants have an extra effect on the board on a move. For example, in Atomic, some
// pieces surrounding a capture explode
Expand Down

0 comments on commit a5917d8

Please sign in to comment.