Skip to content
Merged
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
26 changes: 15 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ lazy val app = project
"-Wunused:all",
"-release:21"
),
resolvers ++= Seq("lila-maven".at("https://raw.githubusercontent.com/lichess-org/lila-maven/master")),
resolvers ++= Seq(
"lila-maven".at("https://raw.githubusercontent.com/lichess-org/lila-maven/master"),
"jitpack".at("https://jitpack.io")
),
resolvers += Resolver.sonatypeRepo("public"),
libraryDependencies ++= Seq(
"org.reactivemongo" %% "reactivemongo" % "1.1.0-RC15",
"org.reactivemongo" %% "reactivemongo-akkastream" % "1.1.0-RC15",
"org.lichess" %% "scalalib-core" % "11.7.0",
"org.lichess" %% "scalachess" % "17.5.0",
"com.typesafe.akka" %% "akka-actor" % "2.6.21",
"com.typesafe.akka" %% "akka-stream" % "2.6.21",
"com.typesafe.akka" %% "akka-slf4j" % "2.6.21",
"org.playframework" %% "play-json" % "3.0.4",
"org.lichess" %% "compression" % "3.0",
"org.slf4j" % "slf4j-nop" % "1.7.36"
"org.reactivemongo" %% "reactivemongo" % "1.1.0-RC15",
"org.reactivemongo" %% "reactivemongo-akkastream" % "1.1.0-RC15",
"org.lichess" %% "scalalib-core" % "11.7.0",
"com.github.lichess-org.scalachess" %% "scalachess" % "17.8.3",
"com.typesafe.akka" %% "akka-actor" % "2.6.21",
"com.typesafe.akka" %% "akka-stream" % "2.6.21",
"com.typesafe.akka" %% "akka-slf4j" % "2.6.21",
"org.playframework" %% "play-json" % "3.0.4",
"org.lichess" %% "compression" % "3.0",
"org.slf4j" % "slf4j-nop" % "1.7.36"
// "ch.qos.logback" % "logback-classic" % "1.4.14"
)
)
2 changes: 1 addition & 1 deletion src/main/scala/Evals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ object Evals:
err = Cursor.ContOnError((_, e) => println(e.getMessage))
)
.buffer(1000, OverflowStrategy.backpressure)
.filter(_._id.position.read.board.variant.standard)
.filter(_._id.position.read.position.variant.standard)
.via(toJson)
.runWith(ndjsonSink)
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/lila/game/BSONHandlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import chess.{
Game as ChessGame,
HalfMoveClock,
History as ChessHistory,
Mode,
Rated,
Ply,
Status,
UnmovedRooks
Expand Down Expand Up @@ -114,7 +114,7 @@ object BSONHandlers:
)

val chessGame = ChessGame(
board = chess.Position(
position = chess.Position(
board = decoded.board,
history = ChessHistory(
lastMove = decoded.lastMove,
Expand Down Expand Up @@ -158,7 +158,7 @@ object BSONHandlers:
status = light.status,
daysPerTurn = r.getO[Int](F.daysPerTurn),
binaryMoveTimes = r.bytesO(F.moveTimes),
mode = Mode(r.boolD(F.rated)),
rated = Rated(r.boolD(F.rated)),
createdAt = createdAt,
movedAt = r.dateD(F.movedAt, createdAt),
metadata = Metadata(
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/lila/game/BinaryFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ object BinaryFormat:
.to(Map)

// cache standard start position
val standard = write(Position.init(chess.variant.Standard, White).pieces)
val standard = write(chess.variant.Standard.initialPieces)

private def intToRole(int: Int, variant: Variant): Option[Role] =
int match
Expand Down
15 changes: 6 additions & 9 deletions src/main/scala/lila/game/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import chess.format.{ Fen, Uci }
import chess.opening.{ Opening, OpeningDb }
import chess.variant.Variant
import chess.format.pgn.SanStr
import chess.{ ByColor, Castles, Centis, CheckCount, Clock, Color, Game as ChessGame, Mode, Status }
import chess.{ ByColor, Castles, Centis, CheckCount, Clock, Color, Game as ChessGame, Rated, Status }

import lila.common.Sequence
import lila.db.ByteArray
Expand All @@ -22,13 +22,13 @@ case class Game(
daysPerTurn: Option[Int],
binaryMoveTimes: Option[ByteArray] = None,
clockHistory: Option[ClockHistory] = Option(ClockHistory()),
mode: Mode = Mode.default,
rated: Rated = Rated.default,
createdAt: Instant,
movedAt: Instant,
metadata: Metadata
):
export chess.{ clock, player as turnColor, ply, sans, board, startedAtPly }
export chess.board.{ history, variant }
export chess.{ clock, player as turnColor, ply, sans, position, startedAtPly }
export chess.position.{ history, variant }

def player: Player = players(turnColor)

Expand Down Expand Up @@ -147,10 +147,7 @@ case class Game(

def aiPov: Option[Pov] = players.find(_.isAi).map(_.color).map(pov)

def boosted = rated && finished && bothPlayersHaveMoved && playedTurns < 10

def rated = mode.rated
def casual = !rated
def boosted = rated.yes && finished && bothPlayersHaveMoved && playedTurns < 10

def finished = status >= Status.Mate

Expand Down Expand Up @@ -197,7 +194,7 @@ case class Game(
def startColor = startedAtPly.turn

def ratingVariant =
if isTournament && board.variant.fromPosition then _root_.chess.variant.Standard
if isTournament && position.variant.fromPosition then _root_.chess.variant.Standard
else variant

def fromPosition = variant.fromPosition || source.contains(Source.Position)
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/lila/game/PgnDump.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ object PgnDump:
val player = g.players(color)
player.aiLevel.fold(users(color).name)("lichess AI level " + _)

private def modeName(g: Game) = if g.rated.yes then "Rated" else "Casual"

private def eventOf(game: Game) =
val perf = game.perfType.fold("Standard")(_.name)
game.tournamentId
.map { id =>
s"${game.mode} $perf tournament https://lichess.org/tournament/$id"
s"${modeName(game)} $perf tournament https://lichess.org/tournament/$id"
}
.orElse(game.simulId.map { id =>
s"$perf simul https://lichess.org/simul/$id"
Expand All @@ -46,7 +48,7 @@ object PgnDump:
s"$perf swiss https://lichess.org/swiss/$id"
})
.getOrElse {
s"${game.mode} $perf game"
s"${modeName(game)} $perf game"
}

private def ratingDiffTag(p: Player, tag: Tag.type => TagType) =
Expand Down
20 changes: 12 additions & 8 deletions src/main/scala/lila/game/PgnStorage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ private object PgnStorage:
private def chessBoard(b: JavaBoard): Board =
Board(
occupied = Bitboard(b.occupied),
white = Bitboard(b.white),
black = Bitboard(b.black),
pawns = Bitboard(b.pawns),
knights = Bitboard(b.knights),
bishops = Bitboard(b.bishops),
rooks = Bitboard(b.rooks),
queens = Bitboard(b.queens),
kings = Bitboard(b.kings)
ByColor(
white = Bitboard(b.white),
black = Bitboard(b.black)
),
ByRole(
pawn = Bitboard(b.pawns),
knight = Bitboard(b.knights),
bishop = Bitboard(b.bishops),
rook = Bitboard(b.rooks),
queen = Bitboard(b.queens),
king = Bitboard(b.kings)
)
)

case class Decoded(
Expand Down