Implement endgame table

This commit is contained in:
Thibault Duplessis 2012-05-18 23:11:43 +02:00
parent 3788c1e292
commit edb3ea980a
10 changed files with 58 additions and 50 deletions

View file

@ -51,6 +51,10 @@ object Round extends LilaController {
def drawOffer(fullId: String) = TODO
def drawCancel(fullId: String) = TODO
def drawDecline(fullId: String) = TODO
def rematchOffer(fullId: String) = TODO
def rematchAccept(fullId: String) = TODO
def rematchCancel(fullId: String) = TODO
def rematchDecline(fullId: String) = TODO
def takebackAccept(fullId: String) = TODO
def takebackOffer(fullId: String) = TODO
def takebackCancel(fullId: String) = TODO
@ -62,7 +66,9 @@ object Round extends LilaController {
def tablePlayer(fullId: String) = Open { implicit ctx
IOption(gameRepo pov fullId) { pov
pov.game.playable.fold(html.round.table.playing(pov), html.round.table.end(pov))
pov.game.playable.fold(
html.round.table.playing(pov),
html.round.table.end(pov))
}
}

View file

@ -23,8 +23,8 @@ object Cron {
implicit val executor = Akka.system.dispatcher
unsafe(5 seconds) {
(env.site.hub :: env.lobby.hub :: env.round.hubMaster :: Nil) foreach { actor
actor ! socket.Broom
(env.site.hub :: env.lobby.hub :: env.round.hubMaster :: Nil) foreach {
_ ! socket.Broom
}
}

View file

@ -15,8 +15,8 @@ object Global extends GlobalSettings {
coreEnv = CoreEnv(app)
//if (env.isAiServer) println("Running as AI server")
//else Cron start env
if (env.ai.isServer) println("Running as AI server")
else core.Cron start env
}
override def onRouteRequest(req: RequestHeader): Option[Handler] = {

View file

@ -9,17 +9,18 @@ import com.mongodb.DBRef
case class DbPlayer(
id: String,
color: Color,
ps: String,
aiLevel: Option[Int],
isWinner: Option[Boolean],
elo: Option[Int],
eloDiff: Option[Int],
isOfferingDraw: Boolean,
lastDrawOffer: Option[Int],
isProposingTakeback: Boolean,
user: Option[DBRef],
moveTimes: String,
blurs: Int) {
ps: String = "",
isWinner: Option[Boolean] = None,
isOfferingDraw: Boolean = false,
isOfferingRematch: Boolean = false,
lastDrawOffer: Option[Int] = None,
isProposingTakeback: Boolean = false,
user: Option[DBRef] = None,
elo: Option[Int] = None,
eloDiff: Option[Int] = None,
moveTimes: String = "",
blurs: Int = 0) {
def encodePieces(allPieces: Iterable[(Pos, Piece, Boolean)]): String =
allPieces withFilter (_._2.color == color) map {
@ -78,15 +79,5 @@ object DbPlayer {
aiLevel: Option[Int]): DbPlayer = DbPlayer(
id = IdGenerator.player,
color = color,
ps = "",
aiLevel = aiLevel,
isWinner = None,
elo = None,
eloDiff = None,
isOfferingDraw = false,
lastDrawOffer = None,
isProposingTakeback = false,
user = None,
moveTimes = "",
blurs = 0)
aiLevel = aiLevel)
}

View file

@ -14,6 +14,7 @@ case class RawDbPlayer(
elo: Option[Int],
eloDiff: Option[Int],
isOfferingDraw: Option[Boolean],
isOfferingRematch: Option[Boolean],
lastDrawOffer: Option[Int],
isProposingTakeback: Option[Boolean],
user: Option[DBRef],
@ -30,9 +31,10 @@ case class RawDbPlayer(
isWinner = w,
elo = elo,
eloDiff = eloDiff,
isOfferingDraw = isOfferingDraw getOrElse false,
isOfferingDraw = isOfferingDraw | false,
isOfferingRematch = isOfferingRematch | false,
lastDrawOffer = lastDrawOffer,
isProposingTakeback = isProposingTakeback getOrElse false,
isProposingTakeback = isProposingTakeback | false,
user = user,
moveTimes = mts | "",
blurs = blurs | 0
@ -52,6 +54,7 @@ object RawDbPlayer {
elo = elo,
eloDiff = eloDiff,
isOfferingDraw = if (isOfferingDraw) Some(true) else None,
isOfferingRematch = if (isOfferingRematch) Some(true) else None,
lastDrawOffer = lastDrawOffer,
isProposingTakeback = if (isProposingTakeback) Some(true) else None,
user = user,

View file

@ -17,7 +17,7 @@ sealed trait Member extends SocketMember {
def gameId = ref.gameId
def color = ref.color
def className = owner.fold("Owner", "Watcher")
override def toString = "%s(%s-%s,%s)".format(className, gameId, color)
override def toString = "%s(%s-%s,%s)".format(className, gameId, color, username)
}
object Member {

View file

@ -39,11 +39,7 @@
</div>
<div class="lichess_separator"></div>
<div class="table_inner">
@if(game.playable) {
@round.table.playing(pov)
} else {
@round.table.end(pov)
}
@game.playable.fold(round.table.playing(pov), round.table.end(pov))
</div>
</div>
@game.clock.map { c =>

View file

@ -3,23 +3,30 @@
@import pov._
<div class="lichess_current_player">
@if(game.finished || game.aborted) {
@round.table.result(game)
} else {
<div class="lichess_player white @game.turnColor.white.fold("", " none")">
<div class="lichess_piece king white"></div>
<p>@trans.whitePlays()</p>
</div>
<div class="lichess_player black @game.turnColor.black.fold("", " none")">
<div class="lichess_piece king black"></div>
<p>@trans.blackPlays()</p>
</div>
}
</div>
<div class="lichess_separator"></div>
@round.username(player)
@game.nextId.map { nextId =>
<div class="lichess_control buttons">
<a class="button" href="@routes.Round.watcher(nextId, opponent.color.name)">View rematch</a>
@if(opponent.isHuman) {
<div class="lichess_separator"></div>
@if(opponent.isOfferingRematch) {
<div class="lichess_play_again_join rematch_alert">
@trans.yourOpponentWantsToPlayANewGameWithYou().&nbsp;
<a class="lichess_play_again lichess_rematch" title="@trans.playWithTheSameOpponentAgain()" href="@routes.Round.rematchAccept(fullId)">@trans.joinTheGame()</a><br />
<a class="lichess_rematch_decline" href="@routes.Round.rematchDecline(fullId)">@trans.declineInvitation()</a>
</div>
} else {
@if(player.isOfferingRematch) {
<div class="lichess_play_again_join rematch_wait">
@trans.rematchOfferSent().<br />
@trans.waitingForOpponent()...<br /><br />
<a class="lichess_rematch_cancel" href="@routes.Round.rematchCancel(fullId)">@trans.cancelRematchOffer()</a>
</div>
} else {
<a class="lichess_rematch button" title="@trans.playWithTheSameOpponentAgain()" href="@routes.Round.rematchOffer(fullId)">@trans.rematch()</a>
}
}
} else {
<a class="button" title="@trans.playWithTheSameOpponentAgain()" href="@routes.Lobby.home()#ai">@trans.rematch()</a>
}
<a class="lichess_new_game button" title="@trans.playWithAnotherOpponent()" href="@routes.Lobby.home()">@trans.newOpponent()</a>
</div>
}

View file

@ -18,6 +18,10 @@ GET /draw-accept/$fullId<[\w\-]{12}> controllers.Round.drawAccept(fu
GET /draw-offer/$fullId<[\w\-]{12}> controllers.Round.drawOffer(fullId: String)
GET /draw-cancel/$fullId<[\w\-]{12}> controllers.Round.drawCancel(fullId: String)
GET /draw-decline/$fullId<[\w\-]{12}> controllers.Round.drawDecline(fullId: String)
GET /rematch-offer/:fullId controllers.Round.rematchOffer(fullId: String)
GET /rematch-accept/:fullId controllers.Round.rematchAccept(fullId: String)
GET /rematch-cancel/:fullId controllers.Round.rematchCancel(fullId: String)
GET /rematch-decline/:fullId controllers.Round.rematchDecline(fullId: String)
GET /takeback-accept/$fullId<[\w\-]{12}> controllers.Round.takebackAccept(fullId: String)
GET /takeback-offer/$fullId<[\w\-]{12}> controllers.Round.takebackOffer(fullId: String)
GET /takeback-cancel/$fullId<[\w\-]{12}> controllers.Round.takebackCancel(fullId: String)

1
todo
View file

@ -16,6 +16,7 @@ translate "view rematch"
translate clock name
start chess960 after both player move http://fr.lichess.org/forum/lichess-feedback/clock-fairness-in-chess960-games
elo floor 800
use true auth for socket username
next deploy:
db.user.update({},{$unset:{isOnline: true}}, false, true)