new tournament system wip
This commit is contained in:
parent
a4bb8bc58e
commit
fc4a42eb73
|
@ -40,13 +40,13 @@ object Tournament extends LilaController {
|
|||
}
|
||||
|
||||
private def fetchTournaments =
|
||||
env allCreatedSorted true zip repo.started zip repo.finished(20)
|
||||
env allCreatedSorted true zip repo.started zip repo.finished(30)
|
||||
|
||||
def show(id: String) = Open { implicit ctx =>
|
||||
repo byId id flatMap {
|
||||
_ match {
|
||||
case Some(tour: Created) => showCreated(tour) map { Ok(_) }
|
||||
case Some(tour: Started) => showStarted(tour) map { Ok(_) }
|
||||
case Some(tour: Started) => showStarted(tour.refreshPlayers) map { Ok(_) }
|
||||
case Some(tour: Finished) => showFinished(tour) map { Ok(_) }
|
||||
case _ => tournamentNotFound.fuccess
|
||||
}
|
||||
|
|
|
@ -43,18 +43,18 @@ private[tournament] object Player {
|
|||
nbWin: Int = 0,
|
||||
nbLoss: Int = 0,
|
||||
score: Int = 0,
|
||||
winSeq: Int = 0,
|
||||
bestWinSeq: Int = 0,
|
||||
prevWin: Boolean = false) {
|
||||
wins: List[Boolean] = Nil) {
|
||||
|
||||
def +(winner: Option[String]) = {
|
||||
|
||||
val (win, loss): Pair[Boolean, Boolean] = winner.fold(false -> false) { w =>
|
||||
if (w == player.id) true -> false else false -> true
|
||||
}
|
||||
|
||||
val basePoints = if (win) 2 else if (loss) 0 else 1
|
||||
val extraPoint = if(!loss && prevWin) 1 else 0
|
||||
val points = basePoints + extraPoint
|
||||
val isWinStreak = wins take 2 == List(true, true)
|
||||
val points = if (isWinStreak) ti
|
||||
|
||||
val newWinSeq = if (win) prevWin.fold(winSeq + 1, 1) else 0
|
||||
|
||||
|
@ -64,7 +64,7 @@ private[tournament] object Player {
|
|||
score = score + points,
|
||||
winSeq = newWinSeq,
|
||||
bestWinSeq = math.max(bestWinSeq, newWinSeq),
|
||||
prevWin = win)
|
||||
wins = win :: wins)
|
||||
}
|
||||
|
||||
def toPlayer = player.copy(
|
||||
|
|
|
@ -246,7 +246,7 @@ case class Started(
|
|||
|
||||
private def userPairings(user: String) = pairings filter (_ contains user)
|
||||
|
||||
private def refreshPlayers = withPlayers(Player refresh this)
|
||||
def refreshPlayers = withPlayers(Player refresh this)
|
||||
|
||||
def encode = refreshPlayers.encode(Status.Started)
|
||||
|
||||
|
|
Loading…
Reference in a new issue