Skip to content

Commit

Permalink
unified openings working
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Feb 25, 2016
1 parent 30316b4 commit 08e0b84
Show file tree
Hide file tree
Showing 22 changed files with 64 additions and 86 deletions.
6 changes: 1 addition & 5 deletions app/controllers/Export.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object Export extends LilaController {
initialFen <- GameRepo initialFen game
pgn = Env.api.pgnDump(game, initialFen)
analysis (~get("as") != "raw") ?? (Env.analyse.analyser getDone game.id)
} yield Env.analyse.annotator(pgn, analysis, gameOpening(game), game.winnerColor, game.status, game.clock).toString
} yield Env.analyse.annotator(pgn, analysis, game.opening, game.winnerColor, game.status, game.clock).toString
}) map { content =>
Ok(content).withHeaders(
CONTENT_TYPE -> ContentTypes.TEXT,
Expand Down Expand Up @@ -71,8 +71,4 @@ object Export extends LilaController {
if (HTTPRequest isFacebookBot ctx.req) result
else if (HTTPRequest isBot ctx.req) fuccess(NotFound)
else result

private def gameOpening(game: GameModel) =
if (game.fromPosition || game.variant.exotic) none
else chess.OpeningExplorer openingOf game.pgnMoves
}
2 changes: 1 addition & 1 deletion app/views/analyse/replay.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@import pov._

@title = @{ s"${playerText(pov.player)} vs ${playerText(pov.opponent)} in $gameId : ${game.opening.fold(trans.analysis.str())(_.fullName)}" }
@title = @{ s"${playerText(pov.player)} vs ${playerText(pov.opponent)} in $gameId : ${game.opening.fold(trans.analysis.str())(_.opening.ecoName)}" }

@moreCss = {
@cssTag("analyse.css")
Expand Down
4 changes: 2 additions & 2 deletions app/views/analyse/replayBot.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@import pov._

@title = @{ s"${playerText(pov.player)} vs ${playerText(pov.opponent)} in $gameId : ${game.opening.fold(trans.analysis.str())(_.fullName)}" }
@title = @{ s"${playerText(pov.player)} vs ${playerText(pov.opponent)} in $gameId : ${game.opening.fold(trans.analysis.str())(_.opening.ecoName)}" }

@moreJs = {
@embedJs {
Expand Down Expand Up @@ -57,7 +57,7 @@
<div class="lichess_ground for_bot">
<h1>@titleGame(pov.game)</h1>
<p>@describePov(pov)</p>
<p>@pov.game.opening.map(_.fullName)</p>
<p>@pov.game.opening.map(_.opening.ecoName)</p>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/game/widgets.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
@defining(g openingPgnMoves 20) { pgnMoves =>
@if(!g.fromPosition) {
@g.opening.map { opening =>
<div class="opening">@opening.name</div>
<div class="opening">@opening.opening.ecoName</div>
}
}
<div class="pgn">@pgnMoves.take(6).grouped(2).zipWithIndex.map {
Expand Down
8 changes: 2 additions & 6 deletions app/views/opening/JsData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object JsData extends lila.Steroids {

def apply(
opening: Opening,
identified: List[Identified],
identified: List[String],
userInfos: Option[lila.opening.UserInfos],
play: Boolean,
attempt: Option[Attempt],
Expand All @@ -35,11 +35,7 @@ object JsData extends lila.Steroids {
"quality" -> quality.name)
}),
"url" -> s"$netBaseUrl${routes.Opening.show(opening.id)}",
"identified" -> identified.map { ident =>
Json.obj(
"name" -> ident.name,
"moves" -> ident.moves)
}
"identified" -> identified
),
"pref" -> Json.obj(
"coords" -> ctx.pref.coords
Expand Down
2 changes: 1 addition & 1 deletion app/views/opening/show.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(opening: lila.opening.Opening, identified: List[lila.opening.Identified], userInfos: Option[lila.opening.UserInfos], animationDuration: scala.concurrent.duration.Duration)(implicit ctx: Context)
@(opening: lila.opening.Opening, identified: List[String], userInfos: Option[lila.opening.UserInfos], animationDuration: scala.concurrent.duration.Duration)(implicit ctx: Context)

@evenMoreJs = {
@helper.javascriptRouter("openingRoutes")(
Expand Down
25 changes: 25 additions & 0 deletions bin/mongodb/wesley02.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
db.tournament2.insert({
"_id": "wesley02",
"clock": {
"limit": NumberInt(3 * 60),
"increment": NumberInt(0)
},
"createdAt": new Date(),
"createdBy": "lichess",
"minutes": NumberInt(60),
"name": "GM Wesley So Arena",
"nbPlayers": NumberInt(0),
"startsAt": ISODate("2016-03-02T22:00:00Z"),
"schedule": {
"freq": "unique",
"speed": "blitz"
},
"status": NumberInt(10),
"variant": NumberInt(1),
"spotlight": {
"homepageHours": 24,
"headline": "Tournament by Chess at Three",
"description": "Your chance to play Super GM Wesley So! Tournament organized and [livestreamed](www.twitch.tv/chessat3) by [chessat3.com](http:https://chessat3.com).",
"iconImg": "chessat3.logo.png"
}
});
8 changes: 4 additions & 4 deletions modules/analyse/src/main/Annotator.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package lila.analyse

import chess.format.pgn.{ Pgn, Tag, Turn, Move }
import chess.Opening
import chess.opening._
import chess.{ Status, Color, Clock }

private[analyse] final class Annotator(netDomain: String) {

def apply(
p: Pgn,
analysis: Option[Analysis],
opening: Option[Opening],
opening: Option[FullOpening.AtPly],
winner: Option[Color],
status: Status,
clock: Option[Clock]): Pgn =
Expand Down Expand Up @@ -44,8 +44,8 @@ private[analyse] final class Annotator(netDomain: String) {
case None => p
}

private def annotateOpening(opening: Option[Opening])(p: Pgn) = opening.fold(p) { o =>
p.updatePly(o.size, _.copy(opening = o.name.some))
private def annotateOpening(opening: Option[FullOpening.AtPly])(p: Pgn) = opening.fold(p) { o =>
p.updatePly(o.ply, _.copy(opening = o.opening.ecoName.some))
}

private def annotateTurns(p: Pgn, advices: List[Advice]): Pgn =
Expand Down
8 changes: 3 additions & 5 deletions modules/api/src/main/GameApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ private[api] final class GameApi(
pgnDump: PgnDump,
analysisApi: AnalysisApi) {

import lila.round.JsonView.openingWriter

def byUser(
user: User,
rated: Option[Boolean],
Expand Down Expand Up @@ -166,11 +168,7 @@ private[api] final class GameApi(
}),
"analysis" -> analysisOption.ifTrue(withAnalysis).|@|(pgnOption).apply(analysisApi.game),
"moves" -> withMoves.option(g.pgnMoves mkString " "),
"opening" -> withOpening.?? {
g.opening map { opening =>
Json.obj("code" -> opening.code, "name" -> opening.name)
}
},
"opening" -> withOpening.??(g.opening),
"fens" -> withFens ?? {
chess.Replay.boards(g.pgnMoves, initialFen, g.variant).toOption map { boards =>
JsArray(boards map chess.format.Forsyth.exportBoard map JsString.apply)
Expand Down
4 changes: 1 addition & 3 deletions modules/api/src/main/UserGameApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ final class UserGameApi(bookmarkApi: lila.bookmark.BookmarkApi) {
}),
"fen" -> Forsyth.exportBoard(g.toChess.board),
"lastMove" -> g.castleLastMoveTime.lastMoveString,
"opening" -> g.opening.map { o =>
Json.obj("code" -> o.code, "name" -> o.name)
},
"opening" -> g.opening,
"winner" -> g.winnerColor.map(_.name),
"bookmarks" -> g.bookmarks,
"bookmarked" -> bookmarked.option(true)
Expand Down
2 changes: 1 addition & 1 deletion modules/chess
Submodule chess updated from 1d00ae to a70949
2 changes: 1 addition & 1 deletion modules/game/src/main/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ case class Game(

def resetTurns = copy(turns = 0, startedAtTurn = 0)

lazy val opening: Option[FullOpening] =
lazy val opening: Option[FullOpening.AtPly] =
if (fromPosition || !Game.openingSensiblevariants(variant)) none
else FullOpeningDB search pgnMoves

Expand Down
4 changes: 2 additions & 2 deletions modules/game/src/main/PgnDump.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ final class PgnDump(
Tag("PlyCount", game.turns),
Tag(_.Variant, game.variant.name.capitalize),
Tag(_.TimeControl, game.clock.fold("-") { c => s"${c.limit}+${c.increment}" }),
Tag(_.ECO, game.opening.fold("?")(_.eco)),
Tag(_.Opening, game.opening.fold("?")(_.name)),
Tag(_.ECO, game.opening.fold("?")(_.opening.eco)),
Tag(_.Opening, game.opening.fold("?")(_.opening.name)),
Tag(_.Termination, {
import chess.Status._
game.status match {
Expand Down
2 changes: 1 addition & 1 deletion modules/gameSearch/src/main/GameSearchApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class GameSearchApi(client: ESClient) extends SearchReadApi[Game, Query] {
Fields.ai -> game.aiLevel,
Fields.date -> (lila.search.Date.formatter print game.updatedAtOrCreatedAt),
Fields.duration -> game.estimateTotalTime,
Fields.opening -> (game.opening map (_.code.toLowerCase)),
Fields.opening -> (game.opening map (_.opening.eco.toLowerCase)),
Fields.analysed -> analysed,
Fields.whiteUser -> game.whitePlayer.userId,
Fields.blackUser -> game.blackPlayer.userId,
Expand Down
7 changes: 4 additions & 3 deletions modules/gameSearch/src/main/Query.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lila.gameSearch

import chess.{ Mode, Status, Openings }
import chess.{ Mode, Status }
import chess.opening._
import org.joda.time.DateTime

import lila.rating.RatingRange
Expand Down Expand Up @@ -76,8 +77,8 @@ object Query {

val modes = Mode.all map { mode => mode.id -> mode.name.capitalize }

val openings = Openings.generals map {
case (code, name) => code -> s"$code ${name.take(50)}"
val openings = EcopeningDB.all map { o =>
o.eco -> s"${o.eco} ${o.name.take(50)}"
}

val turns = options(
Expand Down
33 changes: 0 additions & 33 deletions modules/opening/src/main/Identified.scala

This file was deleted.

8 changes: 4 additions & 4 deletions modules/opening/src/main/OpeningApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ private[opening] final class OpeningApi(
}

object identify {
def apply(fen: String, max: Int): Fu[List[Identified]] = nameColl.find(
def apply(fen: String, max: Int): Fu[List[String]] = nameColl.find(
BSONDocument("_id" -> fen),
BSONDocument("_id" -> false)
).one[BSONDocument] map { opt =>
Identified.many(~(opt ?? (_.getAs[List[String]]("names"))), max)
}
).one[BSONDocument] map { obj =>
~obj.??(_.getAs[List[String]]("names"))
}
}
}
8 changes: 4 additions & 4 deletions modules/round/src/main/JsonView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ object JsonView {
"emerg" -> c.emerg)
}

implicit val openingWriter: OWrites[chess.Opening] = OWrites { o =>
implicit val openingWriter: OWrites[chess.opening.FullOpening.AtPly] = OWrites { o =>
Json.obj(
"code" -> o.code,
"name" -> o.name,
"size" -> o.size
"eco" -> o.opening.eco,
"name" -> o.opening.name,
"ply" -> o.ply
)
}
}
2 changes: 1 addition & 1 deletion public/stylesheets/opening.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
font-size: 1.3em;
font-weight: bold;
}
#opening table.identified td {
#opening .identified li {
padding-right: 2em;
}
#opening .meter {
Expand Down
1 change: 0 additions & 1 deletion public/stylesheets/transp.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ body.transp #video_side,
body.transp #video_side a,
body.transp .side div.user_lists,
body.transp .side div.user_lists a,
body.transp #opening .identified,
body.transp #puzzle .right .retry,
body.transp #trainer .explanation,
body.transp .tournament_home_side,
Expand Down
5 changes: 3 additions & 2 deletions ui/analyse/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,14 @@ function renderVariationTurn(ctrl, turn, path) {
}

function renderOpening(ctrl, opening) {
return m('div.comment.opening', opening.code + ': ' + opening.name);
console.log(ctrl.data, opening);
return m('div.comment.opening', opening.eco + ' ' + opening.name);
}

function renderMeta(ctrl, move, path) {
if (!ctrl.vm.comments) return;
var opening = ctrl.data.game.opening;
opening = (move && opening && opening.size === move.ply) ? renderOpening(ctrl, opening) : null;
opening = (move && opening && opening.ply === move.ply) ? renderOpening(ctrl, opening) : null;
if (!move || (!opening && empty(move.comments) && empty(move.variations))) return;
var children = [];
if (opening) children.push(opening);
Expand Down
7 changes: 2 additions & 5 deletions ui/opening/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,8 @@ module.exports = function(ctrl) {
m('div.underboard',
m('div.center', [
progress(ctrl),
m('table.identified', ctrl.data.opening.identified.map(function(ident) {
return m('tr', [
m('td', ident.name),
m('td', ident.moves)
]);
m('ul.identified', ctrl.data.opening.identified.map(function(name) {
return m('li', name);
})), (ctrl.data.user && ctrl.data.user.history) ? renderHistory(ctrl) : null,
ctrl.data.play ? null : renderContinueLinks(ctrl)
])
Expand Down

0 comments on commit 08e0b84

Please sign in to comment.