Skip to content

Commit

Permalink
strictness of board validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Feb 20, 2013
1 parent 195b624 commit 5d7b1e1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/main/scala/Board.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,10 @@ case class Board(

def visual = Visual >> this

def valid = Color.all map rolesOf forall { roles
Seq(
(roles count (_ == King)) == 1,
(roles count (_ == Pawn)) <= 8,
roles.size <= 16
) forall identity
def valid(strict: Boolean) = Color.all map rolesOf forall { roles
((roles count (_ == King)) == 1) :: {
if (strict) List((roles count (_ == Pawn)) <= 8, roles.size <= 16) else Nil
} forall identity
}

override def toString = visual
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/Situation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ case class Situation(board: Board, color: Color) {

def end: Boolean = checkMate || staleMate || autoDraw

def playable: Boolean = board.valid && !end
def playable(strict: Boolean): Boolean = (board valid strict) && !end

def move(from: Pos, to: Pos, promotion: Option[PromotableRole]): Valid[Move] = for {
actor board.actors get from toValid "No piece on " + from
Expand Down

0 comments on commit 5d7b1e1

Please sign in to comment.