Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now move method returns a future. #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/main/scala/Bots.scala
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 5 additions & 1 deletion src/main/scala/Kernel.scala
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)))
}
}

Expand Down