Skip to content

Instantly share code, notes, and snippets.

@muandrew
Created January 11, 2017 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muandrew/dcb6fe1899f6f95a4144b67876c134e3 to your computer and use it in GitHub Desktop.
Save muandrew/dcb6fe1899f6f95a4144b67876c134e3 to your computer and use it in GitHub Desktop.
Kotlin Integration for battlecode 2017
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
@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