Last active
October 9, 2017 14:00
Halite-II starter bot in Scala (using Java starter kit)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hlt._ | |
import scala.collection.JavaConverters._ | |
object MyBot extends App { | |
val networking = new Networking | |
val gameMap = networking.initialize("ScalaBot") | |
def navHelp(ship: Ship, planet: Planet): Option[Move] = { | |
if (ship canDock planet) Some { | |
new DockMove(ship, planet) | |
} | |
else Option { | |
new Navigation(ship, planet) | |
.navigateToDock(gameMap, Constants.MAX_SPEED/2) | |
} | |
} | |
while (true) { | |
gameMap.updateMap(Networking.readAndSplitLine()) | |
val moveList = for { | |
ship <- gameMap.getMyPlayer.getShips.values.asScala | |
if ship.getDockingStatus == Ship.DockingStatus.Undocked | |
planets = gameMap.getAllPlanets.values.asScala | |
planet <- planets.filterNot(_.isOwned).take(1) | |
move <- navHelp(ship, planet) | |
} yield move | |
Networking.sendMoves(moveList.asJava) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment