diff --git a/src/main/scala/Bots.scala b/src/main/scala/Bots.scala index 09ff2e9..850f7fc 100644 --- a/src/main/scala/Bots.scala +++ b/src/main/scala/Bots.scala @@ -1,18 +1,22 @@ package bot import Dir._ -import scala.util.Random import Tile._ +import scala.util.Random +import scala.concurrent._ +import ExecutionContext.Implicits.global trait Bot { - def move(input: Input): Dir + def move(input: Input): Future[Dir] } class RandomBot extends Bot { - def move(input: Input) = { - Random.shuffle(List(Dir.North, Dir.South, Dir.East, Dir.West)) find { dir ⇒ - input.game.board at input.hero.pos.to(dir) exists (Wall!=) - } - } getOrElse Dir.Stay + def move(input: Input) = future { + { + Random.shuffle(List(Dir.North, Dir.South, Dir.East, Dir.West)) find { dir ⇒ + input.game.board at input.hero.pos.to(dir) exists (Wall!=) + } + } getOrElse Dir.Stay + } } diff --git a/src/main/scala/Kernel.scala b/src/main/scala/Kernel.scala index 51277b0..15bdce6 100644 --- a/src/main/scala/Kernel.scala +++ b/src/main/scala/Kernel.scala @@ -1,5 +1,9 @@ package bot +import scala.concurrent.Await +import scala.concurrent.Future +import scala.concurrent.duration._ + object Main { val bot: Bot = new RandomBot @@ -65,7 +69,7 @@ object Main { def step(server: Server, input: Input) { if (!input.game.finished) { print(".") - step(server, server.move(input.playUrl, bot move input)) + step(server, server.move(input.playUrl, Await.result(bot move input, 1.second))) } }