forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFriendConfig.scala
72 lines (62 loc) · 1.52 KB
/
FriendConfig.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package lila
package setup
import chess.{ Variant, Mode, Clock, Color ⇒ ChessColor }
import elo.EloRange
import game.{ DbGame, DbPlayer }
case class FriendConfig(
variant: Variant,
clock: Boolean,
time: Int,
increment: Int,
mode: Mode,
color: Color) extends HumanConfig with GameGenerator {
def >> = (variant.id, clock, time, increment, mode.id.some, color.name).some
def game = DbGame(
game = makeGame,
ai = None,
whitePlayer = DbPlayer.white,
blackPlayer = DbPlayer.black,
creatorColor = creatorColor,
mode = mode,
variant = variant)
def encode = RawFriendConfig(
v = variant.id,
k = clock,
t = time,
i = increment,
m = mode.id)
}
object FriendConfig extends BaseHumanConfig {
def <<(v: Int, k: Boolean, t: Int, i: Int, m: Option[Int], c: String) =
new FriendConfig(
variant = Variant(v) err "Invalid game variant " + v,
clock = k,
time = t,
increment = i,
mode = m.fold(Mode.orDefault, Mode.default),
color = Color(c) err "Invalid color " + c)
val default = FriendConfig(
variant = variantDefault,
clock = true,
time = 5,
increment = 8,
mode = Mode.default,
color = Color.default)
}
private[setup] case class RawFriendConfig(
v: Int,
k: Boolean,
t: Int,
i: Int,
m: Int) {
def decode = for {
variant ← Variant(v)
mode ← Mode(m)
} yield FriendConfig(
variant = variant,
clock = k,
time = t,
increment = i,
mode = mode,
color = Color.White)
}