forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAiConfig.scala
77 lines (65 loc) · 1.65 KB
/
AiConfig.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
73
74
75
76
77
package lila
package setup
import chess.{ Variant, Mode, Color ⇒ ChessColor }
import game.{ DbGame, DbPlayer }
case class AiConfig(
variant: Variant,
clock: Boolean,
time: Int,
increment: Int,
level: Int,
color: Color) extends Config with GameGenerator {
def >> = (variant.id, clock, time, increment, level, color.name).some
def game = DbGame(
game = makeGame,
ai = Some(!creatorColor -> level),
whitePlayer = DbPlayer(
color = ChessColor.White,
aiLevel = creatorColor.black option level),
blackPlayer = DbPlayer(
color = ChessColor.Black,
aiLevel = creatorColor.white option level),
creatorColor = creatorColor,
mode = Mode.Casual,
variant = variant).start
def encode = RawAiConfig(
v = variant.id,
k = clock,
t = time,
i = increment,
l = level)
}
object AiConfig extends BaseConfig {
def <<(v: Int, k: Boolean, t: Int, i: Int, level: Int, c: String) = new AiConfig(
variant = Variant(v) err "Invalid game variant " + v,
clock = k,
time = t,
increment = i,
level = level,
color = Color(c) err "Invalid color " + c)
val default = AiConfig(
variant = variantDefault,
clock = false,
time = 5,
increment = 8,
level = 1,
color = Color.default)
val levels = (1 to 8).toList
val levelChoices = levels map { l ⇒ l.toString -> l.toString }
}
private[setup] case class RawAiConfig(
v: Int,
k: Boolean,
t: Int,
i: Int,
l: Int) {
def decode = for {
variant ← Variant(v)
} yield AiConfig(
variant = variant,
clock = k,
time = t,
increment = i,
level = l,
color = Color.White)
}