Created
October 4, 2014 03:39
-
-
Save daiksy/29d44cedf07942a95884 to your computer and use it in GitHub Desktop.
CodingGame Training
This file contains hidden or 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
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