show draw offers in analysis board - for #4800
parent
ec30ae4aae
commit
2d9dff39ba
|
@ -204,15 +204,7 @@ final private[api] class RoundApi(
|
||||||
obj: JsObject
|
obj: JsObject
|
||||||
) =
|
) =
|
||||||
obj + ("treeParts" -> partitionTreeJsonWriter.writes(
|
obj + ("treeParts" -> partitionTreeJsonWriter.writes(
|
||||||
lila.round.TreeBuilder(
|
lila.round.TreeBuilder(pov.game, analysis, initialFen | pov.game.variant.initialFen, withFlags)
|
||||||
id = pov.gameId,
|
|
||||||
pgnMoves = pov.game.pgnMoves,
|
|
||||||
variant = pov.game.variant,
|
|
||||||
analysis = analysis,
|
|
||||||
initialFen = initialFen | pov.game.variant.initialFen,
|
|
||||||
withFlags = withFlags,
|
|
||||||
clocks = withFlags.clocks ?? pov.game.bothClockStates
|
|
||||||
)
|
|
||||||
))
|
))
|
||||||
|
|
||||||
private def withSteps(pov: Pov, initialFen: Option[FEN])(obj: JsObject) =
|
private def withSteps(pov: Pov, initialFen: Option[FEN])(obj: JsObject) =
|
||||||
|
|
|
@ -203,13 +203,10 @@ final private[round] class RoundDuct(
|
||||||
"analysis" -> lila.analyse.JsonView.bothPlayers(a.game, a.analysis),
|
"analysis" -> lila.analyse.JsonView.bothPlayers(a.game, a.analysis),
|
||||||
"tree" -> lila.tree.Node.minimalNodeJsonWriter.writes {
|
"tree" -> lila.tree.Node.minimalNodeJsonWriter.writes {
|
||||||
TreeBuilder(
|
TreeBuilder(
|
||||||
id = a.analysis.id,
|
a.game,
|
||||||
pgnMoves = a.game.pgnMoves,
|
a.analysis.some,
|
||||||
variant = a.variant,
|
a.initialFen,
|
||||||
analysis = a.analysis.some,
|
JsonView.WithFlags()
|
||||||
initialFen = a.initialFen,
|
|
||||||
withFlags = JsonView.WithFlags(),
|
|
||||||
clocks = none
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package lila.round
|
package lila.round
|
||||||
|
|
||||||
import chess.Centis
|
import chess.{ Centis, Color }
|
||||||
import chess.format.pgn.Glyphs
|
import chess.format.pgn.Glyphs
|
||||||
import chess.format.{ FEN, Forsyth, Uci, UciCharPair }
|
import chess.format.{ FEN, Forsyth, Uci, UciCharPair }
|
||||||
import chess.opening._
|
import chess.opening._
|
||||||
|
@ -26,32 +26,14 @@ object TreeBuilder {
|
||||||
analysis: Option[Analysis],
|
analysis: Option[Analysis],
|
||||||
initialFen: FEN,
|
initialFen: FEN,
|
||||||
withFlags: WithFlags
|
withFlags: WithFlags
|
||||||
): Root =
|
|
||||||
apply(
|
|
||||||
id = game.id,
|
|
||||||
pgnMoves = game.pgnMoves,
|
|
||||||
variant = game.variant,
|
|
||||||
analysis = analysis,
|
|
||||||
initialFen = initialFen,
|
|
||||||
withFlags = withFlags,
|
|
||||||
clocks = withFlags.clocks ?? game.bothClockStates
|
|
||||||
)
|
|
||||||
|
|
||||||
def apply(
|
|
||||||
id: String,
|
|
||||||
pgnMoves: Vector[String],
|
|
||||||
variant: Variant,
|
|
||||||
analysis: Option[Analysis],
|
|
||||||
initialFen: FEN,
|
|
||||||
withFlags: WithFlags,
|
|
||||||
clocks: Option[Vector[Centis]]
|
|
||||||
): Root = {
|
): Root = {
|
||||||
val withClocks: Option[Vector[Centis]] = withFlags.clocks ?? clocks
|
val withClocks: Option[Vector[Centis]] = withFlags.clocks ?? game.bothClockStates
|
||||||
chess.Replay.gameMoveWhileValid(pgnMoves, initialFen, variant) match {
|
val drawOfferPlies = game.drawOffers.normalizedPlies
|
||||||
|
chess.Replay.gameMoveWhileValid(game.pgnMoves, initialFen, game.variant) match {
|
||||||
case (init, games, error) =>
|
case (init, games, error) =>
|
||||||
error foreach logChessError(id)
|
error foreach logChessError(game.id)
|
||||||
val openingOf: OpeningOf =
|
val openingOf: OpeningOf =
|
||||||
if (withFlags.opening && Variant.openingSensibleVariants(variant)) FullOpeningDB.findByFen
|
if (withFlags.opening && Variant.openingSensibleVariants(game.variant)) FullOpeningDB.findByFen
|
||||||
else _ => None
|
else _ => None
|
||||||
val fen = Forsyth >> init
|
val fen = Forsyth >> init
|
||||||
val infos: Vector[Info] = analysis.??(_.infos.toVector)
|
val infos: Vector[Info] = analysis.??(_.infos.toVector)
|
||||||
|
@ -83,18 +65,18 @@ object TreeBuilder {
|
||||||
eval = info map makeEval,
|
eval = info map makeEval,
|
||||||
glyphs = Glyphs.fromList(advice.map(_.judgment.glyph).toList),
|
glyphs = Glyphs.fromList(advice.map(_.judgment.glyph).toList),
|
||||||
comments = Node.Comments {
|
comments = Node.Comments {
|
||||||
advice.map(_.makeComment(withEval = false, withBestMove = true)).toList.map { text =>
|
drawOfferPlies(g.turns)
|
||||||
Node.Comment(
|
.option(makeLichessComment(s"${!Color.fromPly(g.turns)} offers draw"))
|
||||||
Node.Comment.Id.make,
|
.toList :::
|
||||||
Node.Comment.Text(text),
|
advice
|
||||||
Node.Comment.Author.Lichess
|
.map(_.makeComment(withEval = false, withBestMove = true))
|
||||||
)
|
.toList
|
||||||
}
|
.map(makeLichessComment)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
advices.get(g.turns + 1).flatMap { adv =>
|
advices.get(g.turns + 1).flatMap { adv =>
|
||||||
games.lift(index - 1).map { case (fromGame, _) =>
|
games.lift(index - 1).map { case (fromGame, _) =>
|
||||||
withAnalysisChild(id, branch, variant, Forsyth >> fromGame, openingOf)(adv.info)
|
withAnalysisChild(game.id, branch, game.variant, Forsyth >> fromGame, openingOf)(adv.info)
|
||||||
}
|
}
|
||||||
} getOrElse branch
|
} getOrElse branch
|
||||||
}
|
}
|
||||||
|
@ -108,6 +90,13 @@ object TreeBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def makeLichessComment(text: String) =
|
||||||
|
Node.Comment(
|
||||||
|
Node.Comment.Id.make,
|
||||||
|
Node.Comment.Text(text),
|
||||||
|
Node.Comment.Author.Lichess
|
||||||
|
)
|
||||||
|
|
||||||
private def withAnalysisChild(
|
private def withAnalysisChild(
|
||||||
id: String,
|
id: String,
|
||||||
root: Branch,
|
root: Branch,
|
||||||
|
|
Loading…
Reference in New Issue