Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define first player for #708 and for #738 #866

Merged
merged 2 commits into from
Sep 28, 2024
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
4 changes: 3 additions & 1 deletion modules/game/src/main/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ case class Game(

def opponent(c: Color): Player = player(!c)

lazy val firstColor = Color.fromSente(sentePlayer before gotePlayer)
// View handicap games from the handicap receiver's perspective
// View other games from the dominant (title/rating) player's perspective
lazy val firstColor = if (isHandicap) !startColor else Color.fromSente(sentePlayer before gotePlayer)
def firstPlayer = player(firstColor)
def secondPlayer = player(!firstColor)

Expand Down
25 changes: 17 additions & 8 deletions modules/game/src/main/Player.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ case class Player(
color: Color,
engineConfig: Option[EngineConfig] = None,
isBot: Boolean = false,
hasTitle: Boolean = false,
isWinner: Option[Boolean] = None,
isOfferingDraw: Boolean = false,
lastDrawOffer: Option[Int] = None,
Expand Down Expand Up @@ -82,11 +83,13 @@ case class Player(
}

def before(other: Player) =
((rating, id), (other.rating, other.id)) match {
case ((Some(a), _), (Some(b), _)) if a != b => a > b
case ((Some(_), _), (None, _)) => true
case ((None, _), (Some(_), _)) => false
case ((_, a), (_, b)) => a < b
((isHuman, hasTitle, rating, id), (other.isHuman, other.hasTitle, other.rating, other.id)) match {
case ((a, _, _, _), (b, _, _, _)) if a != b => a > b
case ((_, a, _, _), (_, b, _, _)) if a != b => a > b
case ((_, _, Some(a), _), (_, _, Some(b), _)) if a != b => a > b
case ((_, _, Some(_), _), (_, _, None, _)) => true
case ((_, _, None, _), (_, _, Some(_), _)) => false
case ((_, _, _, a), (_, _, _, b)) => a < b
}

def ratingAfter = rating map (_ + ~ratingDiff)
Expand Down Expand Up @@ -119,7 +122,8 @@ object Player {
userId: User.ID,
rating: Int,
provisional: Boolean,
isBot: Boolean
isBot: Boolean,
hasTitle: Boolean
): Player =
Player(
id = IdGenerator.player(color),
Expand All @@ -128,7 +132,8 @@ object Player {
userId = userId.some,
rating = rating.some,
provisional = provisional,
isBot = isBot
isBot = isBot,
hasTitle = hasTitle
)

def make(
Expand All @@ -143,7 +148,8 @@ object Player {
userId = u.id,
rating = perf.intRating,
provisional = perf.glicko.provisional,
isBot = u.isBot
isBot = u.isBot,
hasTitle = u.hasTitle
)
}

Expand All @@ -167,6 +173,7 @@ object Player {
val aiLevel = "ai"
val aiEngine = "a"
val isBot = "b"
val hasTitle = "t"
val isOfferingDraw = "od"
val lastDrawOffer = "ld"
val proposeTakebackAt = "ta"
Expand Down Expand Up @@ -222,6 +229,7 @@ object Player {
)
),
isBot = r boolD isBot,
hasTitle = r boolD hasTitle,
isWinner = win,
isOfferingDraw = r boolD isOfferingDraw,
lastDrawOffer = r intO lastDrawOffer,
Expand All @@ -242,6 +250,7 @@ object Player {
aiLevel -> p.aiLevel,
aiEngine -> p.aiEngine.map(_.code),
isBot -> w.boolO(p.isBot),
hasTitle -> w.boolO(p.hasTitle),
isOfferingDraw -> w.boolO(p.isOfferingDraw),
lastDrawOffer -> p.lastDrawOffer,
isOfferingPause -> w.boolO(p.isOfferingPause),
Expand Down
2 changes: 1 addition & 1 deletion modules/tournament/src/main/AutoPairing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ final class AutoPairing(
}

private def makePlayer(color: Color, player: Player) =
GamePlayer.make(color, player.userId, player.rating, provisional = player.provisional, isBot = false)
GamePlayer.make(color, player.userId, player.rating, provisional = player.provisional, isBot = false, hasTitle = false)

private def usernameOf(userId: User.ID) =
lightUserApi.sync(userId).fold(userId)(_.name)
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.9.4")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.6.0")
// addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.0.7")