Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/common/src/main/mon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ object mon {
val coefVar = histogram("round.move.lag.coef_var_1000").withoutTags()
val compEstStdErr = histogram("round.move.lag.comp_est_stderr_1000").withoutTags()
val compEstOverErr = histogram("round.move.lag.avg_over_error_ms").withoutTags()
val moveComp = timer("round.move.lag.comped").withoutTags()
}
val time = timer("round.move.time").withoutTags()
}
Expand Down
33 changes: 21 additions & 12 deletions modules/round/src/main/Player.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import shogi.format.usi.Usi
import shogi.{ Centis, MoveMetrics, Status }

import actorApi.round.{ DrawNo, ForecastPlay, HumanPlay, TakebackNo, TooManyPlies }
import lila.game.actorApi.MoveGameEvent
import cats.data.Validated
import java.util.concurrent.TimeUnit

import lila.common.Bus
import lila.game.{ Game, Pov, Progress }
import lila.game.actorApi.MoveGameEvent
import lila.game.Game.PlayerId
import cats.data.Validated
import lila.game.{ Game, Pov, Progress }

final private class Player(
fishnetPlayer: lila.fishnet.Player,
Expand All @@ -17,8 +19,9 @@ final private class Player(
)(implicit ec: scala.concurrent.ExecutionContext) {

sealed private trait MoveResult
private case object Flagged extends MoveResult
private case class MoveApplied(progress: Progress) extends MoveResult
private case object Flagged extends MoveResult
private case class MoveApplied(progress: Progress, compedLag: Option[Centis])
extends MoveResult

private[round] def human(play: HumanPlay, round: RoundDuct)(
pov: Pov
Expand All @@ -35,7 +38,10 @@ final private class Player(
.fold(errs => fufail(ClientError(errs.toString)), fuccess)
.flatMap {
case Flagged => finisher.outOfTime(game)
case MoveApplied(progress) =>
case MoveApplied(progress, compedLag) =>
compedLag foreach { lag =>
lila.mon.round.move.lag.moveComp.record(lag.millis, TimeUnit.MILLISECONDS)
}
proxy.save(progress) >>
postHumanOrBotPlay(round, pov, progress, usi)
}
Expand All @@ -56,7 +62,7 @@ final private class Player(
.fold(errs => fufail(ClientError(errs.toString)), fuccess)
.flatMap {
case Flagged => finisher.outOfTime(game)
case MoveApplied(progress) =>
case MoveApplied(progress, _) =>
proxy.save(progress) >> postHumanOrBotPlay(round, pov, progress, usi)
}
case Pov(game, _) if game.finished => fufail(ClientError(s"$pov game is finished"))
Expand Down Expand Up @@ -89,7 +95,7 @@ final private class Player(
.fold(errs => fufail(ClientError(errs.toString)), fuccess)
.flatMap {
case Flagged => finisher.outOfTime(game)
case MoveApplied(progress) =>
case MoveApplied(progress, _) =>
proxy.save(progress) >>-
notifyMove(usi, progress.game) >> {
if (progress.game.finished) moveFinish(progress.game) dmap { progress.events ::: _ }
Expand All @@ -112,17 +118,20 @@ final private class Player(
}

private val fishnetLag = MoveMetrics(clientLag = Centis(5).some)
private val botLag = MoveMetrics(clientLag = Centis(10).some)
private val botLag = MoveMetrics(clientLag = Centis(0).some)

private def applyUsi(
game: Game,
usi: Usi,
blur: Boolean,
metrics: MoveMetrics
): Validated[String, MoveResult] =
game.shogi(usi) map { nsg =>
if (nsg.clock.exists(_.outOfTime(game.turnColor, withGrace = false))) Flagged
else MoveApplied(game.update(nsg, usi, blur))
game.shogi(usi, metrics) map { nsg =>
if (nsg.value.clock.exists(_.outOfTime(game.turnColor, withGrace = false))) Flagged
else MoveApplied(
game.update(nsg.value, usi, blur),
nsg.compensated
)
}

private def notifyMove(usi: Usi, game: Game): Unit = {
Expand Down
9 changes: 7 additions & 2 deletions modules/round/src/main/RoundSocket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,14 @@ object RoundSocket {
} yield PlayerDo(FullId(fullId), tpe)
}
case "r/move" =>
raw.get(5) { case Array(fullId, usiS, blurS, lagS, mtS) =>
raw.get(6) { case Array(fullId, usiS, blurS, lagS, mtS, fraS) =>
Usi(usiS) map { usi =>
PlayerMove(FullId(fullId), usi, P.In.boolean(blurS), MoveMetrics(centis(lagS), centis(mtS)))
PlayerMove(
FullId(fullId),
usi,
P.In.boolean(blurS),
MoveMetrics(centis(lagS), centis(mtS), centis(fraS))
)
}
}
case "chat/say" =>
Expand Down