Skip to content

Commit

Permalink
Scala tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Mar 16, 2024
1 parent 67a810e commit eb930f1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/Speed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ object Speed:

def apply(clock: Option[Clock.Config]) = byTime(clock.fold(Int.MaxValue)(_.estimateTotalSeconds))

def byTime(seconds: Int): Speed = all.find(_.range contains seconds) | Correspondence
def byTime(seconds: Int): Speed = all.find(_.range.contains(seconds)) | Correspondence
4 changes: 2 additions & 2 deletions src/main/scala/format/Uci.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ object Uci:
def apply(drop: chess.Drop) = Uci.Drop(drop.piece.role, drop.square)

def apply(move: String): Option[Uci] =
if move.lift(1) contains '@' then
if move.lift(1).contains('@') then
for
role <- move.headOption.flatMap(Role.allByPgn.get)
square <- Square.fromKey(move.slice(2, 4))
yield Uci.Drop(role, square)
else Uci.Move(move)

def fromChars(move: String): Option[Uci] =
if move.lift(1) contains '@' then Uci.Drop.fromChars(move)
if move.lift(1).contains('@') then Uci.Drop.fromChars(move)
else Uci.Move.fromChars(move)

def readList(moves: String): Option[List[Uci]] =
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/format/pgn/Glyph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ case class Glyphs(
case g: Glyph.PositionAssessment => copy(position = (!position.contains(g)).option(g))
case g: Glyph.Observation =>
copy(observations =
if observations contains g then observations.filter(g !=)
if observations.contains(g) then observations.filter(g !=)
else g :: observations
)
case _ => this
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/opening/OpeningDb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ object OpeningDb:

// Keep only one opening per unique key: the shortest one
lazy val shortestLines: Map[OpeningKey, Opening] = OpeningDb.all
.foldLeft(Map.empty[OpeningKey, Opening]) { case (acc, op) =>
.foldLeft(Map.empty) { case (acc, op) =>
acc.updatedWith(op.key):
case Some(prev) if prev.uci.value.size < op.uci.value.size => prev.some
case _ => op.some
}

def isShortest(op: Opening) = shortestLines.get(op.key) contains op
def isShortest(op: Opening) = shortestLines.get(op.key).contains(op)

def findByEpdFen(fen: EpdFen): Option[Opening] = findByStandardFen(fen.opening)

Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/variant/Variant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ object Variant:
def byName(name: String): Option[Variant] =
list.all.find(_.name.toLowerCase == name.toLowerCase)

def exists(id: Id): Boolean = list.byId contains id
def exists(id: Id): Boolean = list.byId.contains(id)

private[variant] def symmetricRank(rank: IndexedSeq[Role]): Map[Square, Piece] =
File.all.zip(rank).map { (x, role) => Square(x, Rank.First) -> (White - role) } ++
File.all.map { Square(_, Rank.Second) -> White.pawn } ++
File.all.map { Square(_, Rank.Seventh) -> Black.pawn } ++
File.all.zip(rank).map { (x, role) => Square(x, Rank.Eighth) -> (Black - role) } toMap
File.all.zip(rank).map((x, role) => Square(x, Rank.First) -> (White - role)) ++
File.all.map(Square(_, Rank.Second) -> White.pawn) ++
File.all.map(Square(_, Rank.Seventh) -> Black.pawn) ++
File.all.zip(rank).map((x, role) => Square(x, Rank.Eighth) -> (Black - role)) toMap

0 comments on commit eb930f1

Please sign in to comment.