tweak scala charts generators
This commit is contained in:
parent
c7d9397acf
commit
eeeb1e8fc3
|
@ -7,39 +7,29 @@ final class AdvantageChart(advices: Analysis.InfoAdvices) {
|
|||
|
||||
val max = 15
|
||||
|
||||
def columns = AdvantageChart.columns
|
||||
def columns = Json generate List(
|
||||
"string" :: "Move" :: Nil,
|
||||
"number" :: "Advantage" :: Nil)
|
||||
|
||||
def rows = Json generate chartValues
|
||||
def rows = Json generate {
|
||||
|
||||
val scale = floatBox(-max to max) _
|
||||
|
||||
def move(info: Info, advice: Option[Advice]) = info.color.fold(
|
||||
"%d. %s", "%d... %s"
|
||||
).format(info.turn, info.move.uci) + advice.fold(" " + _.nag.symbol, "")
|
||||
|
||||
private lazy val values: List[(String, Float)] =
|
||||
(advices sliding 2 collect {
|
||||
case (info, advice) :: (next, _) :: Nil ⇒
|
||||
(next.score, next.mate) match {
|
||||
case (Some(score), _) ⇒ move(info, advice) -> scale(score.pawns)
|
||||
case (_, Some(mate)) ⇒ move(info, advice) -> {
|
||||
case (Some(score), _) ⇒ List(move(info, advice), scale(score.pawns))
|
||||
case (_, Some(mate)) ⇒ List(move(info, advice), {
|
||||
val mateDelta = math.abs(mate.toFloat / 100)
|
||||
val whiteWins = info.color.fold(mate < 0, mate > 0)
|
||||
scale(whiteWins.fold(max - mateDelta, mateDelta - max))
|
||||
}
|
||||
case _ ⇒ move(info, none) -> scale(0)
|
||||
})
|
||||
case _ ⇒ List(move(info, none), scale(0))
|
||||
}
|
||||
}).toList
|
||||
|
||||
private val scale = floatBox(-max to max) _
|
||||
|
||||
private def chartValues: List[List[Any]] = values map {
|
||||
case (move, score) ⇒ List(move, score)
|
||||
}
|
||||
|
||||
private def move(info: Info, advice: Option[Advice]) = info.color.fold(
|
||||
"%d. %s", "%d... %s"
|
||||
).format(info.turn, info.move.uci) + advice.fold(" " + _.nag.symbol, "")
|
||||
|
||||
}
|
||||
|
||||
object AdvantageChart {
|
||||
|
||||
val columns = Json generate List(
|
||||
"string" :: "Move" :: Nil,
|
||||
"number" :: "Advantage" :: Nil)
|
||||
}
|
||||
|
|
|
@ -7,14 +7,14 @@ import com.codahale.jerkson.Json
|
|||
|
||||
final class TimePie(val pov: Pov) {
|
||||
|
||||
import pov._
|
||||
|
||||
val columns = Json generate List(
|
||||
def columns = Json generate List(
|
||||
"string" :: "Move time" :: Nil,
|
||||
"number" :: "Moves" :: Nil)
|
||||
|
||||
def rows = Json generate {
|
||||
|
||||
import pov._
|
||||
|
||||
val steps = (0 to 5) ++ (6 to 12 by 2) ++ (15 to 30 by 3) ++ (35 to 60 by 5)
|
||||
|
||||
val ranges = steps zip (steps drop 1) map { case (a, b) ⇒ Range(a, b) }
|
||||
|
@ -29,8 +29,8 @@ final class TimePie(val pov: Pov) {
|
|||
else "%d to %d seconds".format(min, max)
|
||||
}
|
||||
|
||||
ranges zip (ranges map nbMoves) collect {
|
||||
case (range, nb) if nb > 0 ⇒ List(nameRange(range), nb)
|
||||
ranges zip (ranges map nbMoves) collect {
|
||||
case (range, nb) if nb > 0 ⇒ List(nameRange(range), nb)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue