Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math._
- import scala.util._
- object Player {
- case class Coordinate(x: Int, y: Int)
- case class Universe(lightOfPower: Coordinate, thorsPosition: Coordinate) {
- def getDirection: (Universe, String) = {
- val (we, x2) =
- if (thorsPosition.x < lightOfPower.x)
- ("E", thorsPosition.x + 1)
- else
- if (thorsPosition.x > lightOfPower.x)
- ("W", thorsPosition.x - 1)
- else
- ("", thorsPosition.x)
- val (ns, y2) =
- if (thorsPosition.y < lightOfPower.y)
- ("S", thorsPosition.y + 1)
- else
- if (thorsPosition.y > lightOfPower.y)
- ("N", thorsPosition.y - 1)
- else
- ("", thorsPosition.y)
- (copy(thorsPosition = Coordinate(x2, y2)), ns + we)
- }
- }
- def readInputInitial: Universe = {
- val coordinates: Array[Int] =
- for(i <- readLine split " ")
- yield i.toInt
- val result =
- Universe(
- Coordinate(coordinates(0), coordinates(1))
- , Coordinate(coordinates(2), coordinates(3))
- )
- Console.err.println("readInputInitial.result=" + result)
- result
- }
- def readInputLoop: Int = {
- val result =
- readInt
- Console.err.println("readInputLoop.result=" + result)
- result
- }
- //def response(universe: Universe): (Coordinate, String) = {
- // //TODO: fill in the logic to figure out the actual logic to produce both the coordinate and the command
- // (Coordinate(universe.thor.x + 1, universe.thor.y + 1), "SE")
- //}
- def main(args: Array[String]) {
- var universe: Universe =
- readInputInitial
- // game loop
- while(readInputLoop > 0) {
- val (universeNew, command): (Universe, String) =
- universe.getDirection
- universe =
- universeNew
- Console.err.println(s"universe=$universe, command=$command")
- println(command) // 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