Skip to content

Commit

Permalink
Scala tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Mar 20, 2024
1 parent 47658a3 commit 89632e8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/main/scala/Situation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ case class Situation(board: Board, color: Color):
*/
lazy val potentialEpSquare: Option[Square] = history.lastMove.flatMap:
case Uci.Move(orig, dest, _) =>
board(dest).flatMap { piece =>
board(dest).flatMap: piece =>
if piece.color != color && piece.role == Pawn &&
orig.yDist(dest) == 2 && orig.rank != piece.color.backRank
then dest.prevRank(!color)
else None
}
case _ => None

def genNonKingAndNonPawn(mask: Bitboard): List[Move] =
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/Square.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object Square:
inline def upLeft: Option[Square] = Square.at(file.value - 1, rank.value + 1)
inline def upRight: Option[Square] = Square.at(file.value + 1, rank.value + 1)

inline def prevRank(color: Color) = color.fold(s.down, s.up)
inline def prevRank(color: Color): Option[Square] = color.fold(s.down, s.up)

@targetName("onLeftOf")
inline def ?<(inline other: Square): Boolean = file < other.file
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/format/Uci.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ object Uci:
yield Move(orig, dest, promotion)

def fromChars(move: String) = for
orig <- move.headOption.flatMap { Square.fromChar(_) }
dest <- move.lift(1).flatMap { Square.fromChar(_) }
promotion = move.lift(2).flatMap { Role.promotable(_) }
orig <- move.headOption.flatMap(Square.fromChar)
dest <- move.lift(1).flatMap(Square.fromChar)
promotion = move.lift(2).flatMap(Role.promotable)
yield Move(orig, dest, promotion)

def fromStrings(origS: String, destS: String, promS: Option[String]) = for
Expand All @@ -68,7 +68,7 @@ object Uci:

def fromChars(move: String) = for
role <- move.headOption.flatMap(Role.allByPgn.get)
square <- move.lift(2).flatMap { Square.fromChar(_) }
square <- move.lift(2).flatMap(Square.fromChar)
yield Uci.Drop(role, square)

def fromStrings(roleS: String, posS: String) = for
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/format/pgn/parsingModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ case class Castle(side: Side) extends San:
if !variant.allowsCastling then error.asLeft
else
ourKing
.flatMap(k =>
.flatMap: k =>
variant
.applyVariantEffect(genCastling(k))
.filter(variant.kingSafety)
.find(_.castle.exists(_.side == side))
)
.toRight(error)

opaque type Sans = List[San]
Expand Down

0 comments on commit 89632e8

Please sign in to comment.