Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 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("MyJavaBot");
  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. if (
  43. game.turnNumber <= 200 &&
  44. me.halite >= Constants.SHIP_COST &&
  45. !gameMap.at(me.shipyard).isOccupied())
  46. {
  47. commandQueue.add(me.shipyard.spawn());
  48. }
  49.  
  50. game.endTurn(commandQueue);
  51. }*/
  52. for (; ; ) {
  53. game.updateFrame();
  54. final Player me = game.me;
  55. final GameMap gameMap = game.gameMap;
  56.  
  57. final ArrayList<Command> commandQueue = new ArrayList<>();
  58. if (me.ships.values().size() < 1) {
  59. me.shipyard.spawn();
  60. }
  61. for (final Ship myShip : me.ships.values()) {
  62. int maxHalite = 0;
  63. Direction currentDirection = gameMap.naiveNavigate(myShip, me.shipyard.position);
  64. boolean farm = false;
  65. for (Direction direction : Direction.ALL_CARDINALS) {
  66. Position position = myShip.position;
  67. int currentHalite = gameMap.at(position.directionalOffset(direction)).halite;
  68. if (currentHalite > maxHalite && currentHalite > myShip.halite && myShip.halite < 500) {
  69. maxHalite = currentHalite;
  70. currentDirection = direction;
  71. farm = true;
  72. }
  73. }
  74. if (farm) {
  75. commandQueue.add(myShip.stayStill());
  76. } else {
  77. commandQueue.add(myShip.move(currentDirection));
  78. }
  79. }
  80. game.endTurn(commandQueue);
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement