-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGen.scala
187 lines (158 loc) · 4.59 KB
/
Gen.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
val gen = "gen"
object Gen:
import Perft.*
def main(args: Array[String]): Unit =
cleanup()
write(os.pwd / ".github" / "workflows" / "insufficient.yml", prejob("insufficient", insufficient))
write(os.pwd / ".github" / "workflows" / "variant.yml", prejob("variant", variant))
genRandomTests()
genChess960Tests()
genTrickyTests()
private def cleanup(): Unit =
os.remove.all(os.pwd / ".github" / "workflows")
os.remove.all(os.pwd / gen)
def genRandomTests(): Unit =
val size = 6838 / randomSplit
(0 to size).foreach(genRandomTests)
def genChess960Tests(): Unit =
val size = 960 / chess960Split
(0 to size).foreach(genChess960Tests)
def genTrickyTests(): Unit =
(0 to 1).foreach(genTrickyTests)
private def genRandomTests(i: Int): Unit =
val scala = randomScala(i)
val scalaPath = os.pwd / gen / s"RandomPerftTests$i.scala"
write(scalaPath, scala)
val ci = randomCi(i)
val ciPath = os.pwd / ".github" / "workflows" / s"random-perft-$i.yml"
write(ciPath, ci)
private def genChess960Tests(i: Int): Unit =
val scala = chess960Scala(i)
val scalaPath = os.pwd / gen / s"Chess960PerftTests$i.scala"
write(scalaPath, scala)
val ci = chess960Ci(i)
val ciPath = os.pwd / ".github" / "workflows" / s"chess960-perft-$i.yml"
write(ciPath, ci)
private def genTrickyTests(i: Int): Unit =
val scala = trickyScala(i)
val scalaPath = os.pwd / gen / s"TrickyPerftTests$i.scala"
write(scalaPath, scala)
val ci = trickyCi(i)
val ciPath = os.pwd / ".github" / "workflows" / s"tricky-perft-$i.yml"
write(ciPath, ci)
private def write(path: os.Path, content: String): Unit =
os.write(path, content, createFolders = true)
def prejob(name: String, job: String) = s"""
name: $name
on:
push:
paths-ignore:
- 'README.md'
branches:
- main
pull_request:
jobs:
$job
""".strip
val insufficient = """
hord-insufficient-material:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: VirtusLab/scala-cli-setup@main
- name: Test
run: scala-cli test -j 21 HordeInsufficientMaterialTests.scala Common.scala project.scala
"""
val variant = """
variant:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: VirtusLab/scala-cli-setup@main
- name: Test
run: scala-cli test -j 21 VariantPerftTests.scala Common.scala project.scala
"""
def randomScala(i: Int) = s"""
import weaver.*
import chess.format.FullFen
import chess.variant.*
object RandomPerftTests$i extends SimpleIOSuite:
test("random.perft - part $i") {
Perft
.perfts(Perft.randomPerfts($i), Chess960)
.map(assert(_))
}
""".stripLeading()
def randomCi(i: Int) =
val name = s"random-perft-$i"
val ci = s"""
random-perft-$i:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: VirtusLab/scala-cli-setup@main
- name: Test
run: scala-cli test -j 21 gen/RandomPerftTests$i.scala Common.scala project.scala
"""
prejob(name, ci)
def chess960Scala(i: Int) = s"""
import weaver.*
import chess.format.FullFen
import chess.variant.*
object Chess960PerftTests$i extends SimpleIOSuite:
test("chess960 - part $i") {
Perft
.perfts(Perft.chess960($i), Chess960)
.map(assert(_))
}
""".stripLeading()
def chess960Ci(i: Int) =
val name = s"chess960-perft-$i"
val ci = s"""
chess960-perft-$i:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: VirtusLab/scala-cli-setup@main
- name: Test
run: scala-cli test -j 21 gen/Chess960PerftTests$i.scala Common.scala project.scala
"""
prejob(name, ci)
def trickyScala(i: Int) = s"""
import weaver.*
import chess.format.FullFen
import chess.variant.*
object TrickyPerftTests$i extends SimpleIOSuite:
test("tricky - part $i") {
Perft
.perfts(Perft.chess960($i), Chess960)
.map(assert(_))
}
""".stripLeading()
def trickyCi(i: Int) =
val name = s"tricky-perft-$i"
val ci = s"""
tricky-perft-$i:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: VirtusLab/scala-cli-setup@main
- name: Test
run: scala-cli test -j 21 gen/TrickyPerftTests$i.scala Common.scala project.scala
"""
prejob(name, ci)