Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import math._
  2. import scala.util._
  3.  
  4. /**
  5. * Auto-generated code below aims at helping you parse
  6. * the standard input according to the problem statement.
  7. **/
  8. object Player extends App {
  9. // w: number of columns.
  10. // h: number of rows.
  11. val Array(w, h) = for(i <- readLine split " ") yield i.toInt
  12.  
  13. val tunnelMap = (1 to h).toList.map(_ -> readLine.split(" ").map(_.toInt).toList)
  14. val exit = readInt
  15.  
  16. val tileFlow = Map(
  17. 0 -> null,
  18. 1 -> Map("TOP" -> "BOTTOM", "LEFT" -> "BOTTOM", "RIGHT" -> "BOTTOM"),
  19. 2 -> Map("LEFT" -> "RIGHT", "RIGHT" -> "LEFT"),
  20. 3 -> Map("TOP" -> "BOTTOM"),
  21. 4 -> Map("TOP" -> "LEFT", "RIGHT" -> "BOTTOM"),
  22. 5 -> Map("TOP" -> "RIGHT", "LEFT" -> "BOTTOM"),
  23. 6 -> Map("TOP" -> null, "LEFT" -> "RIGHT", "RIGHT" -> "LEFT"),
  24. 7 -> Map("TOP" -> "BOTTOM", "RIGHT" -> "BOTTOM"),
  25. 8 -> Map("LEFT" -> "BOTTOM", "RIGHT" -> "BOTTOM"),
  26. 9 -> Map("LEFT" -> "BOTTOM", "TOP" -> "BOTTOM"),
  27. 10 -> Map("TOP" -> "LEFT", "LEFT" -> null),
  28. 11 -> Map("TOP" -> "RIGHT", "RIGHT" -> null),
  29. 12 -> Map("RIGHT" -> "BOTTOM"),
  30. 13 -> Map("LEFT" -> "BOTTOM")
  31. )
  32.  
  33. // game loop
  34. while(true) {
  35. val Array(_xi, _yi, pos) = readLine split " "
  36. val xi = _xi.toInt
  37. val yi = _yi.toInt
  38.  
  39. val tile = tunnelMap(yi)._2(xi)
  40. val flow = tileFlow(tile)(pos)
  41.  
  42. val (nx, ny) = flow match {
  43. case "LEFT" => (xi - 1, yi)
  44. case "RIGHT" => (xi + 1, yi)
  45. case "BOTTOM" => (xi, yi + 1)
  46. }
  47.  
  48. println(s"$nx $ny")
  49. }
  50. }
Add Comment
Please, Sign In to add comment