Skip to content

Commit

Permalink
Fix SmallTest conversion
Browse files Browse the repository at this point in the history
This happen when in White's turn, and there is a enpassant on b6.
Before this fix, it is mistaken the b from b6 as Black's turn. So,
the fix is make sure that only set black turn if there is no number
after character b.
  • Loading branch information
lenguyenthanh committed Dec 14, 2023
1 parent ad76af5 commit c3a2cec
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/scala/format/Fen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ object SmallFen extends OpaqueString[SmallFen]:
val (board, error) = Fen.makeBoardWithCrazyPromoted(e, chess.variant.Standard)
val boardStr = Fen.writeBoard(board)
val boardSize = boardStr.value.count(_ != '/')
val isBlackTurn = e.lift(boardSize).exists(_ == 'b')
val isBlackTurn = e.lift(boardSize).exists(_ == 'b') && !e.lift(boardSize + 1).exists(_.isDigit)
val turnSize = if isBlackTurn then 1 else 0
val castlingStr = e.drop(boardSize + turnSize).takeWhile(Set('K', 'Q', 'k', 'q').contains)
val enpassantStr = e.drop(boardSize + turnSize + castlingStr.size)
Expand All @@ -108,5 +108,6 @@ object SmallFen extends OpaqueString[SmallFen]:
if variant == chess.variant.ThreeCheck
then fen.value.split(' ').lift(6).foldLeft(base)(_ + _)
else base

def validate(variant: Variant, fen: Fen.Epd): Option[SmallFen] =
Fen.read(variant, fen).exists(_ playable false) option make(variant, fen.simple)

0 comments on commit c3a2cec

Please sign in to comment.