generated from battlecode/battlecode26-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
425 lines (361 loc) · 13.6 KB
/
build.gradle
File metadata and controls
425 lines (361 loc) · 13.6 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
//////// General configuration ////////
apply plugin: 'java'
apply plugin: 'scala'
// Compatibility version: Java 21
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
// Vaildate Java version
if(JavaVersion.current() < JavaVersion.VERSION_21) {
throw new GradleException("The engine must be run using >= Java 21 JDK. Detected JDK " + JavaVersion.current())
}
// Directory layout.
sourceSets {
main {
java.srcDirs = ["src"]
java.includes = ["**/*.java"]
java.destinationDirectory.set(file("$buildDir/classes"))
scala.srcDirs = ["src"]
scala.includes = ["**/*.scala"]
scala.destinationDirectory.set(file("$buildDir/classes"))
}
test {
java.srcDirs = ["test"]
java.includes = ["**/*.java"]
java.destinationDirectory.set(file("$buildDir/tests"))
scala.srcDirs = ["test"]
scala.includes = ["**/*.scala"]
scala.destinationDirectory.set(file("$buildDir/tests"))
}
}
//////// IDE configuration ////////
apply plugin: 'idea'
apply plugin: 'eclipse'
idea {
module {
jdkName = 21
downloadJavadoc = true
downloadSources = true
}
}
eclipse {
classpath {
downloadJavadoc = true
downloadSources = true
defaultOutputDir = new File(project.buildDir, 'classes-eclipse')
}
}
//////// Versions and Files ////////
ext.versions = [
battlecodeEngine: new File(projectDir, "engine_version.txt").text.trim(),
battlecodeClient: new File(projectDir, "client_version.txt").text.trim()
]
ext.python = System.properties['os.name'].toLowerCase().contains('windows') ? 'python' : 'python3'
ext.pythonScript = new File(projectDir, "run.py")
ext.botDirectory = new File(projectDir, "src")
configurations.all {
resolutionStrategy.cacheDynamicVersionsFor 60, 'seconds'
}
static String[] getVersionsFromWeb(boolean onSaturn) {
String[] urls = ["https://api.battlecode.org/api/episode/e/bc26/?format=json"]
String engineVersion = null
String clientVersion = null
for (String url : urls) {
try {
String episodeInfo = new URL(url).text.trim()
def json = new groovy.json.JsonSlurper().parseText(episodeInfo)
if (onSaturn) {
engineVersion = json.release_version_saturn
} else {
engineVersion = json.release_version_public
}
clientVersion = json.release_version_client
} catch (Exception ex) {
System.out.println("Could not obtain version from " + url)
System.out.println(ex.toString())
}
}
return [engineVersion, clientVersion]
}
task version {
description 'Outputs the currently installed version of Battlecode.'
group 'battlecode'
doLast {
logger.quiet("Currently configured engine version: " + versions.battlecodeEngine)
logger.quiet("Currently configured client version: " + versions.battlecodeClient)
}
}
task checkNewVersion {
description 'Checks for a newer version of Battlecode.'
group 'battlecode'
doLast {
def vers = getVersionsFromWeb((project.findProperty("onSaturn") ?: "false").toBoolean())
def engineVersion = vers[0] ?: versions.battlecodeEngine
def clientVersion = vers[1] ?: versions.battlecodeClient
if (versions.battlecodeEngine != engineVersion || versions.battlecodeClient != clientVersion) {
logger.quiet("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
logger.quiet(" !!! NEW BATTLECODE VERSION AVAILABLE !!! ")
logger.quiet("Current engine version: " + versions.battlecodeEngine)
logger.quiet("New Battlecode engine version: " + engineVersion)
logger.quiet("Current client version: " + versions.battlecodeClient)
logger.quiet("New Battlecode client version: " + clientVersion)
logger.quiet("Run './gradlew update' to set new configurations")
logger.quiet("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
}
}
}
task update {
description 'Updates configurations to use the latest available version of Battlecode.'
group 'battlecode'
doLast {
def vers = getVersionsFromWeb((project.findProperty("onSaturn") ?: "false").toBoolean())
if (vers[0] == null || vers[1] == null) {
throw new Exception(
"Could not find new version number. Are you connected to the internet?"
)
}
if (versions.battlecodeEngine != vers[0]) {
versions.battlecodeEngine = vers[0]
new File(projectDir, "engine_version.txt").text = vers[0]
logger.quiet("Updated engine configuration to use version: " + vers[0])
logger.warn("Newest dependencies have not yet been downloaded.")
}
if (versions.battlecodeClient != vers[1]) {
versions.battlecodeClient = vers[1]
new File(projectDir, "client_version.txt").text = vers[1]
logger.quiet("Updated client configuration to use version: " + vers[1])
logger.warn("Newest dependencies have not yet been downloaded.")
}
}
}
task installPyLocal(type: Exec) {
description 'Updates configurations to use an already downloaded version of the Python engine.'
group 'battlecode'
commandLine python, pythonScript.absolutePath, 'install_current_version',
'--on-saturn', (project.findProperty("onSaturn") ?: "false").toString(),
'--force-reinstall', (project.findProperty("forceReinstallPy") ?: "false").toString()
}
//////// Dependencies ////////
repositories {
// Generic dependencies
mavenCentral()
}
if ((project.findProperty("onSaturn") ?: "false").toBoolean()) {
// Saturn: direct access to protected releases.
repositories {
maven {
url "gcs://mitbattlecode-releases/maven"
content {
includeGroup 'org.battlecode'
}
}
}
} else {
// Public Battlecode distribution.
repositories {
maven {
url "https://releases.battlecode.org/maven"
content {
includeGroup 'org.battlecode'
}
// Optional authentication for local private access
if (project.hasProperty('gcloudToken')) {
authentication {
header(HttpHeaderAuthentication)
}
credentials(HttpHeaderCredentials) {
name = "Authorization"
value = "Bearer ${project.gcloudToken}"
}
}
}
}
}
configurations {
client
}
def os = System.getProperty("os.name").toLowerCase()
def clientName = os.startsWith('windows')
? 'battlecode26-client-win-'
: os.startsWith('mac')
? 'battlecode26-client-mac-'
: 'battlecode26-client-linux-'
def clientType = project.findProperty("compatibilityClient").toBoolean()
? "electron"
: "tauri"
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
// The Battlecode engine.
implementation group: 'org.battlecode', name: 'battlecode26-java', version: versions.battlecodeEngine
// The Battlecode client.
client group: 'org.battlecode', name: clientName + clientType, version: versions.battlecodeClient
// Scala
implementation group: 'org.scala-lang', name: 'scala-library', version: '2.13.11'
testImplementation group: 'org.scalatest', name: 'scalatest_2.13', version: '3.2.9'
}
//////// Client ////////
def arch64 = System.getProperty("os.arch").matches("^(x86_64|amd64|ia32e|em64t|x64)\$")
def arch32 = System.getProperty("os.arch").matches("^(x86_32|x86|i[3-6]86|ia32|x32)\$")
if (arch32) {
logger.error('Sorry, the local Battlecode client does not support 32-bit architectures. Ensure you installed the 64-bit JDK')
}
// Add the unpackClient task, but only do it when we are not on the server
if (!(project.findProperty("onSaturn") ?: "false").toBoolean()) {
task unpackClient(type: Copy) {
description 'Downloads the client.'
group 'battlecode'
dependsOn configurations.client
finalizedBy checkNewVersion
from {
configurations.client.collect {
zipTree(it)
}
}
into 'client/'
}
build.configure {
group 'battlecode'
dependsOn unpackClient
}
}
task verify(type: JavaExec) {
description 'Runs basic verifications that a package is valid.'
group 'battlecode'
dependsOn build
mainClass = 'battlecode.instrumenter.Verifier'
classpath = sourceSets.main.runtimeClasspath
args = [
project.findProperty("team") ?: "examplefuncsplayer",
project.findProperty("url") ?: sourceSets.main.output.classesDirs.getAsPath(),
]
}
//////// Running ////////
task downloadPyPackage(type: Exec) {
description 'Downloads Python dependencies for running matches.'
group 'battlecode'
commandLine python, pythonScript.absolutePath, 'update',
'--on-saturn', (project.findProperty("onSaturn") ?: "false").toString(),
'--debug', (project.findProperty("debug") ?: "false").toString(),
'--force-reinstall', (project.findProperty("forceReinstallPy") ?: "false").toString()
}
def truncateString(String input, int maxLength) {
if (input.length() > maxLength) {
return input.substring(0, maxLength)
}
return input
}
def defaultClassLocation = sourceSets.main.output.classesDirs.getAsPath()
def defaultReplayName = truncateString(project.property('teamA') + '-vs-' + project.property('teamB') + '-on-' + project.property('maps'), 80)
def defaultReplayFile = 'matches/' + defaultReplayName + '.bc26'
task runJavaLocal(type: JavaExec) {
mainClass = 'battlecode.server.Main'
classpath = sourceSets.main.runtimeClasspath
args = ['-c=-']
jvmArgs = [
'--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED',
'--add-opens=java.base/jdk.internal.math=ALL-UNNAMED',
'--add-opens=java.base/jdk.internal.util=ALL-UNNAMED',
'--add-opens=java.base/jdk.internal.access=ALL-UNNAMED',
'--add-opens=java.base/sun.security.action=ALL-UNNAMED',
'-Dbc.server.wait-for-client=' + (project.findProperty('waitForClient') ?: 'false'),
'-Dbc.server.mode=headless',
'-Dbc.server.map-path=maps',
'-Dbc.server.robot-player-to-system-out=' + (project.findProperty('outputVerbose') ?: 'true'),
'-Dbc.server.debug=false',
'-Dbc.engine.debug-methods=' + (project.findProperty('debug') ?: 'false'),
'-Dbc.engine.enable-profiler=' + (project.findProperty('enableProfiler') ?: 'false'),
'-Dbc.engine.show-indicators=' + (project.findProperty('showIndicators') ?: 'true'),
'-Dbc.game.team-a=' + project.property('teamA'),
'-Dbc.game.team-b=' + project.property('teamB'),
'-Dbc.game.team-a.language=' + (project.findProperty('languageA') ?: 'java'),
'-Dbc.game.team-b.language=' + (project.findProperty('languageB') ?: 'java'),
'-Dbc.game.team-a.url=' + (project.findProperty('classLocationA') ?: defaultClassLocation),
'-Dbc.game.team-b.url=' + (project.findProperty('classLocationB') ?: defaultClassLocation),
'-Dbc.game.team-a.package=' + (project.findProperty('packageNameA') ?: project.property('teamA')),
'-Dbc.game.team-b.package=' + (project.findProperty('packageNameB') ?: project.property('teamB')),
'-Dbc.game.maps=' + project.property('maps'),
'-Dbc.server.validate-maps=' + project.property('validateMaps'),
'-Dbc.server.alternate-order=' + project.property('alternateOrder'),
'-Dbc.server.save-file=' + (project.findProperty('replay') ?: defaultReplayFile),
]
}
task runJava(dependsOn: runJavaLocal) {}
task runPyLocal(type: Exec, dependsOn: installPyLocal) {
commandLine python, '-m', 'battlecode26',
'--teamA', project.findProperty('languageA') == 'python' ? project.property('teamA') : '/',
'--teamB', project.findProperty('languageB') == 'python' ? project.property('teamB') : '/',
'--dirA', botDirectory.absolutePath,
'--dirB', botDirectory.absolutePath,
'--new-process'
}
task runPy(type: Exec) {
mustRunAfter downloadPyPackage
commandLine python, '-m', 'battlecode26',
'--teamA', project.findProperty('languageA') == 'python' ? project.property('teamA') : '/',
'--teamB', project.findProperty('languageB') == 'python' ? project.property('teamB') : '/',
'--dirA', botDirectory.absolutePath,
'--dirB', botDirectory.absolutePath,
'--new-process'
}
task runLocal {
description 'Runs a match locally (no updates) without starting the client.'
group 'battlecode'
dependsOn runJavaLocal
}
task run {
description 'Runs a match without starting the client.'
group 'battlecode'
dependsOn runJava
}
if (project.findProperty("languageA") == "python" || project.findProperty("languageB") == "python") {
run.dependsOn downloadPyPackage
run.dependsOn runPy
runJava.mustRunAfter runPy
runLocal.dependsOn installPyLocal
runLocal.dependsOn runPyLocal
runJavaLocal.mustRunAfter runPyLocal
}
//////// Informational ////////
task listPlayers {
description 'Lists all available players.'
group 'battlecode'
doLast {
sourceSets.main.allSource.each {
logger.debug(it.name)
if (it.getName().equals('RobotPlayer.java') || it.getName().equals('RobotPlayer.scala')) {
URI base = new File(project.projectDir, 'src').toURI()
URI full = it.toURI()
String path = base.relativize(full).toString()
logger.quiet(path.substring(0, path.lastIndexOf('/')).replaceAll('/', '.'))
}
}
}
}
task listMaps {
description 'Lists all available maps.'
group 'battlecode'
doLast {
sourceSets.main.compileClasspath.each {
logger.debug(it.name)
if (it.toString().contains('battlecode26-')) {
FileCollection fc = zipTree(it)
fc += fileTree(new File(project.projectDir, 'maps'))
fc.each {
String fn = it.getName()
if (fn.endsWith('.map26')) {
logger.quiet(fn.substring(0, fn.indexOf('.map26')))
}
}
}
}
}
}
//////// Submitting ////////
task zipForSubmit(type: Zip) {
description 'Produce a zip file for submission.'
group 'battlecode'
archiveFileName = 'submission.zip'
destinationDirectory = project.projectDir
from sourceSets.main.allSource
}