You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is the literal translation of the Java client into Scala:
importbattlehack17._objectRobotPlayer {
defmain(args: Array[String]):Unit= {
BHLogger.setVerbosity(BHLogger.VERBOSITY_CHATTYDEV)
valgame=newGame("rick-bot")
game.waitForStart()
while (!game.over) {
game.waitTillNextTurn()
/* YOUR CODE HERE */valmybots= game.gameInfo.local.getMyEntities
valrobots= mybots.filter(_.isRobot)
robots.forEach(handleRobot(_, game))
/* DON'T PUT CODE AFTER HERE */if (game.gameInfo.myTurn) game.sendTurn()
}
BHLogger.log("Done!", BHLogger.VERBOSITY_OUTPUT)
}
/** * This code will handle the actions of a single robot. * * @paramrobot The robot to handle * @paramgame The game (contains info on map and entities)*/defhandleRobot(robot: EntityData, game: Game):Unit= {
if (!robot.canAct) return// This robot can't act! We don't want to waste time on it.for (eachDirection <-Direction.cardinalDirections) { // We access our local copy of the game info to determine if we control the// sectors around this robot.// The local copy might desync from the server (in theory, it won't)// But, it means that all our robots will have updated information on what// we THINK will happen.
game.gameInfo.local.controlArea(robot.location.add(eachDirection)) match {
caseAreaControlType.ALLY_CONTROLS_SECTOR=>caseAreaControlType.ENEMY_CONTROLS_SECTOR=>caseAreaControlType.NUETRAL_SECTOR=>if (robot.canBuild(eachDirection)) {
valbuildWorked= robot.build(eachDirection)
// We built something!if (buildWorked) return//If this didn't work, something must have gone wrong...
}
caseAreaControlType.NO_SECTOR=>
}
}
// Okay, we didn't build any statues. Let's move towards the nearest enemy statue.// (Almost) All of Battlehacks iterables are provided to you via streams.// Streams are a feature of Java 1.8 that make manipulation of the iterable// really easy (compared to an array or list)// We'll start off by getting a stream of all the entities around this bot within throwing range// NOTE: One great thing about streams is that you can apply several functionsvalnearby= robot.nearbyEntities(Constants.THROW_TILE_DISTANCE)
robot.build(Direction.NORTH, true)
}
}
The text was updated successfully, but these errors were encountered:
Here is the literal translation of the Java client into Scala:
The text was updated successfully, but these errors were encountered: