Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math._
- import scala.util._
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- object Player {
- case class Pos(x: Int, y: Int) {
- def compare(that: Pos): (Int, Int) = (x.compare(that.x), y.compare(that.y))
- def next(offset: (Int, Int)): Pos =
- new Pos(x + offset._1, y + offset._2)
- }
- def path(light: Pos, thor: Pos): Iterator[String] = {
- val xs = Array("W", "", "E")
- val ys = Array("N", "", "S")
- def move(thor: => Pos): Stream[String] = {
- val offset = light.compare(thor)
- val result = ys(offset._2 + 1) + xs(offset._1 + 1)
- if (result == "") Stream.empty
- else result #:: move(thor.next(offset))
- }
- move(thor).iterator
- }
- def main(args: Array[String]) {
- // lx: the X position of the light of power
- // ly: the Y position of the light of power
- // tx: Thor's starting X position
- // ty: Thor's starting Y position
- val Array(lx, ly, tx, ty) = for(i <- readLine split " ") yield i.toInt
- val moves = path(Pos(lx, ly), Pos(tx, ty))
- // game loop
- while(true) {
- val e = readInt // The level of Thor's remaining energy, representing the number of moves he can still make.
- // Write an action using println
- // To debug: Console.err.println("Debug messages...")
- println(moves.next) // A single line providing the move to be made: N NE E SE S SW W or NW
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement