Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This Java API uses camelCase instead of the snake_case as documented in the API docs.
- // Otherwise the names of methods are consistent.
- import hlt.*;
- import java.util.ArrayList;
- import java.util.Random;
- public class MyBot {
- public static void main(final String[] args) {
- final long rngSeed;
- if (args.length > 1) {
- rngSeed = Integer.parseInt(args[1]);
- } else {
- rngSeed = System.nanoTime();
- }
- final Random rng = new Random(rngSeed);
- Game game = new Game();
- // At this point "game" variable is populated with initial map data.
- // This is a good place to do computationally expensive start-up pre-processing.
- // As soon as you call "ready" function below, the 2 second per turn timer will start.
- game.ready("MyJavaBot");
- Log.log("Successfully created bot! My Player ID is " + game.myId + ". Bot rng seed is " + rngSeed + ".");
- /*for (;;) {
- game.updateFrame();
- final Player me = game.me;
- final GameMap gameMap = game.gameMap;
- final ArrayList<Command> commandQueue = new ArrayList<>();
- for (final Ship ship : me.ships.values()) {
- if (gameMap.at(ship).halite < Constants.MAX_HALITE / 10 || ship.isFull()) {
- final Direction randomDirection = Direction.ALL_CARDINALS.get(rng.nextInt(4));
- commandQueue.add(ship.move(randomDirection));
- } else {
- commandQueue.add(ship.stayStill());
- }
- }
- if (
- game.turnNumber <= 200 &&
- me.halite >= Constants.SHIP_COST &&
- !gameMap.at(me.shipyard).isOccupied())
- {
- commandQueue.add(me.shipyard.spawn());
- }
- game.endTurn(commandQueue);
- }*/
- for (; ; ) {
- game.updateFrame();
- final Player me = game.me;
- final GameMap gameMap = game.gameMap;
- final ArrayList<Command> commandQueue = new ArrayList<>();
- if (me.ships.values().size() < 1) {
- me.shipyard.spawn();
- }
- for (final Ship myShip : me.ships.values()) {
- int maxHalite = 0;
- Direction currentDirection = gameMap.naiveNavigate(myShip, me.shipyard.position);
- boolean farm = false;
- for (Direction direction : Direction.ALL_CARDINALS) {
- Position position = myShip.position;
- int currentHalite = gameMap.at(position.directionalOffset(direction)).halite;
- if (currentHalite > maxHalite && currentHalite > myShip.halite && myShip.halite < 500) {
- maxHalite = currentHalite;
- currentDirection = direction;
- farm = true;
- }
- }
- if (farm) {
- commandQueue.add(myShip.stayStill());
- } else {
- commandQueue.add(myShip.move(currentDirection));
- }
- }
- game.endTurn(commandQueue);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement