Created
January 11, 2017 20:30
-
-
Save muandrew/dcb6fe1899f6f95a4144b67876c134e3 to your computer and use it in GitHub Desktop.
Kotlin Integration for battlecode 2017
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
battlecode/common | |
java/io | |
java/lang | |
java/lang/invoke | |
java/math | |
java/util | |
java/util/function | |
java/util/regex | |
java/util/stream | |
java/text | |
kotlin | |
kotlin/collections | |
kotlin/comparisons | |
kotlin/concurrent | |
kotlin/internal | |
kotlin/io | |
kotlin/jvm | |
kotlin/jvm/functions | |
kotlin/jvm/internal | |
kotlin/properties | |
kotlin/ranges | |
kotlin/reflect | |
kotlin/sequences | |
kotlin/system | |
kotlin/text | |
scala | |
scala/collection | |
scala/collection/generic | |
scala/collection/immutable | |
scala/collection/interfaces | |
scala/collection/mutable | |
scala/collection/script | |
scala/math | |
scala/runtime | |
scala/util | |
scala/util/automata | |
scala/util/continuations | |
scala/util/control | |
scala/util/grammar | |
scala/util/logging | |
scala/util/regexp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@file:JvmName("RobotPlayer") | |
package examplekotlinplayer | |
import battlecode.common.Clock | |
import battlecode.common.Direction | |
import battlecode.common.RobotController | |
/** | |
* run() is the method that is called when a robot is instantiated in the Battlecode world. | |
* If this method returns, the robot dies! | |
**/ | |
@Suppress("unused") | |
fun run(controller: RobotController) { | |
System.out.println("EK: " + controller.type) | |
while (true) { | |
try { | |
val direction = randomDir() | |
if (controller.canMove(direction)) { | |
controller.move(direction) | |
} | |
Clock.`yield`() | |
} catch (e: Exception) { | |
e.printStackTrace() | |
} | |
} | |
} | |
fun randomDir(): Direction { | |
return Direction((Math.random() * Math.PI * 2).toFloat()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment