forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pov.scala
36 lines (21 loc) · 748 Bytes
/
Pov.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package lila
package game
import chess.Color
case class Pov(game: DbGame, color: Color) {
def player = game player color
def playerId = player.id
def fullId = game fullIdOf color
def gameId = game.id
def opponent = game player !color
def unary_! = Pov(game, !color)
def isPlayerFullId(fullId: Option[String]): Boolean =
fullId some { game.isPlayerFullId(player, _) } none false
def ref = PovRef(game.id, color)
def withGame(g: DbGame) = Pov(g, color)
}
object Pov {
def apply(game: DbGame, player: DbPlayer) = new Pov(game, player.color)
def apply(game: DbGame, playerId: String): Option[Pov] =
game player playerId map { p ⇒ new Pov(game, p.color) }
}
case class PovRef(gameId: String, color: Color)