Skip to content

Instantly share code, notes, and snippets.

Created October 4, 2014 03:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
CodingGame Training
import math._
import scala.util._
* The code below will read all the game information for you.
* On each game turn, information will be available on the standard input, you will be sent:
* -> the total number of visible enemies
* -> for each enemy, its name and distance from you
* The system will wait for you to write an enemy name on the standard output.
* Once you have designated a target:
* -> the cannon will shoot
* -> the enemies will move
* -> new info will be available for you to read on the standard input.
object Player {
def main(args: Array[String]) {
// game loop
while(true) {
val count = readInt // The number of current enemy ships within range
val targets = for{i <- 0 until count
Array(enemy, _dist) = readLine split " "
dist = _dist.toInt
} yield (dist -> enemy)
// Write an action using println
// To debug: Console.err.println("Debug messages...")
println(targets.sortBy(_._1).map(_._2).head) // The name of the most threatening enemy (HotDroid is just one example)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment