Moved IO to main

This commit is contained in:
Armin Friedl 2017-10-30 09:27:02 +01:00
parent a429ffa000
commit 46d70661c3
3 changed files with 8 additions and 15 deletions

View file

@ -15,7 +15,7 @@ object Main {
var input = StdIn.readLine()
while(input != null){
Parser.dispatch(input)
Parser.dispatch(input) foreach (println(_))
input = StdIn.readLine()
}
}

View file

@ -4,15 +4,10 @@ import scala.util.Random
import bot.dbg
object Brain {
def move(in: Int): String = {
def move(time: Int): String = {
val dirs = Array("left", "right", "up", "down")
val dir = Random.nextInt(4)
dbg(Settings.toString)
dbg(CurrentState.board.toString())
dbg(dirs(dir))
dirs(dir)
}
}

View file

@ -4,16 +4,14 @@ import bot.{dbg,log}
object Parser {
def dispatch(input: String){
def dispatch(input: String): Option[String] = {
val parts: Seq[String] = input.split(" ")
parts(0) match {
case "settings" => settings(parts.tail)
case "update" => update(parts.tail)
case "action" => {
if(parts(1) equals "character") println("bixiette")
else println(Brain.move(parts(2).toInt))
}
parts match {
case Seq("settings", xs@_*) => settings(xs); None
case Seq("update", xs@_*) => update(xs); None
case Seq("action", "character", _) => Some("bixiette")
case Seq("action", "move", time) => Some(Brain.move(time.toInt))
}
}