Skip to content

Commit

Permalink
Merge pull request #15680 from lenguyenthanh/code-golf/8
Browse files Browse the repository at this point in the history
Scala code tweak
  • Loading branch information
ornicar committed Jul 8, 2024
2 parents 673655e + d7dcb88 commit b6cfd10
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions modules/tree/src/main/Advice.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ sealed trait Advice:
export info.{ ply, prevPly, prevMoveNumber, color, cp, mate }

def makeComment(withEval: Boolean, withBestMove: Boolean): Comment = Comment {
withEval.so(evalComment.so { c =>
s"($c) "
}) +
withEval.so(evalComment.so(c => s"($c) ")) +
(this.match
case MateAdvice(seq, _, _, _) => seq.desc
case CpAdvice(judgment, _, _) => judgment.toString
Expand All @@ -26,9 +24,8 @@ sealed trait Advice:

}

def evalComment: Option[String] = {
List(prev.evalComment, info.evalComment).flatten.mkString("")
}.some.filter(_.nonEmpty)
def evalComment: Option[String] =
List(prev.evalComment, info.evalComment).flatten.mkString("").some.filter(_.nonEmpty)

object Advice:

Expand Down Expand Up @@ -63,10 +60,8 @@ private[tree] object CpAdvice:
infoCp <- info.cp
prevWinningChances = WinPercent.winningChances(cp)
currentWinningChances = WinPercent.winningChances(infoCp)
delta = (currentWinningChances - prevWinningChances).pipe { d =>
info.color.fold(-d, d)
}
judgement <- winningChanceJudgements.find { case (d, _) => d <= delta }.map(_._2)
delta = (currentWinningChances - prevWinningChances).pipe(d => info.color.fold(-d, d))
judgement <- winningChanceJudgements.find((d, _) => d <= delta).map(_._2)
yield CpAdvice(judgement, info, prev)

sealed abstract private[tree] class MateSequence(val desc: String)
Expand Down

0 comments on commit b6cfd10

Please sign in to comment.