Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. // This Java API uses camelCase instead of the snake_case as documented in the API docs.
  2. //     Otherwise the names of methods are consistent.
  3.  
  4. import hlt.*;
  5.  
  6. import java.util.ArrayList;
  7. import java.util.Random;
  8.  
  9. public class MyBot {
  10.     public static void main(final String[] args) {
  11.         final long rngSeed;
  12.         if (args.length > 1) {
  13.             rngSeed = Integer.parseInt(args[1]);
  14.         } else {
  15.             rngSeed = System.nanoTime();
  16.         }
  17.         final Random rng = new Random(rngSeed);
  18.  
  19.         Game game = new Game();
  20.         // At this point "game" variable is populated with initial map data.
  21.         // This is a good place to do computationally expensive start-up pre-processing.
  22.         // As soon as you call "ready" function below, the 2 second per turn timer will start.
  23.         game.ready("Команда А");
  24.  
  25.         Log.log("Successfully created bot! My Player ID is " + game.myId + ". Bot rng seed is " + rngSeed + ".");
  26.  
  27.         for (;;) {
  28.             game.updateFrame();
  29.             final Player me = game.me;
  30.             final GameMap gameMap = game.gameMap;
  31.  
  32.             final ArrayList<Command> commandQueue = new ArrayList<>();
  33.  
  34.             for (final Ship ship : me.ships.values()) {
  35.                 if (gameMap.at(ship).halite < Constants.MAX_HALITE / 10 || ship.isFull()) {
  36.                     final Direction randomDirection = Direction.ALL_CARDINALS.get(rng.nextInt(4));
  37.                     commandQueue.add(ship.move(randomDirection));
  38.                 } else {
  39.                     commandQueue.add(ship.stayStill());
  40.                 }
  41.             }
  42.  
  43.             if (
  44.                 game.turnNumber <= 200 &&
  45.                 me.halite >= Constants.SHIP_COST &&
  46.                 !gameMap.at(me.shipyard).isOccupied())
  47.             {
  48.                 commandQueue.add(me.shipyard.spawn());
  49.             }
  50.  
  51.             game.endTurn(commandQueue);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement