Skip to content

Instantly share code, notes, and snippets.

@mikekwright
Created June 16, 2018 06:36
Show Gist options
  • Select an option

  • Save mikekwright/9a31a3ff02aa007d3ee32f3b66cd1566 to your computer and use it in GitHub Desktop.

Select an option

Save mikekwright/9a31a3ff02aa007d3ee32f3b66cd1566 to your computer and use it in GitHub Desktop.
Codingame solution for The Last Crusade (Episode 1) - https://www.codingame.com/training/medium/the-last-crusade-episode-1
import math._
import scala.util._
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
object Player extends App {
// w: number of columns.
// h: number of rows.
val Array(w, h) = for(i <- readLine split " ") yield i.toInt
val tunnelMap = (1 to h).toList.map(_ -> readLine.split(" ").map(_.toInt).toList)
val exit = readInt
val tileFlow = Map(
0 -> null,
1 -> Map("TOP" -> "BOTTOM", "LEFT" -> "BOTTOM", "RIGHT" -> "BOTTOM"),
2 -> Map("LEFT" -> "RIGHT", "RIGHT" -> "LEFT"),
3 -> Map("TOP" -> "BOTTOM"),
4 -> Map("TOP" -> "LEFT", "RIGHT" -> "BOTTOM"),
5 -> Map("TOP" -> "RIGHT", "LEFT" -> "BOTTOM"),
6 -> Map("TOP" -> null, "LEFT" -> "RIGHT", "RIGHT" -> "LEFT"),
7 -> Map("TOP" -> "BOTTOM", "RIGHT" -> "BOTTOM"),
8 -> Map("LEFT" -> "BOTTOM", "RIGHT" -> "BOTTOM"),
9 -> Map("LEFT" -> "BOTTOM", "TOP" -> "BOTTOM"),
10 -> Map("TOP" -> "LEFT", "LEFT" -> null),
11 -> Map("TOP" -> "RIGHT", "RIGHT" -> null),
12 -> Map("RIGHT" -> "BOTTOM"),
13 -> Map("LEFT" -> "BOTTOM")
)
// game loop
while(true) {
val Array(_xi, _yi, pos) = readLine split " "
val xi = _xi.toInt
val yi = _yi.toInt
val tile = tunnelMap(yi)._2(xi)
val flow = tileFlow(tile)(pos)
val (nx, ny) = flow match {
case "LEFT" => (xi - 1, yi)
case "RIGHT" => (xi + 1, yi)
case "BOTTOM" => (xi, yi + 1)
}
println(s"$nx $ny")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment