Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.65 KB | None | 0 0
  1. class Action {
  2.     final ActionType type;
  3.     Coord pos;
  4.     final EntityType item;
  5.     String message;
  6.  
  7.     private Action(ActionType command, Coord pos, EntityType item, String... message) {
  8.         this.type = command;
  9.         this.pos = pos;
  10.         this.item = item;
  11.         if(message.length == 1)
  12.         {
  13.             this.message = message[0];
  14.         }
  15.     }
  16.     // none() == wait()
  17.     static Action none(String... message) {
  18.         return new Action(ActionType.WAIT, null, null, message);
  19.     }
  20.  
  21.     static Action move(Coord pos, String... message) {
  22.  
  23.         return new Action(ActionType.MOVE, pos, null, message);
  24.     }
  25.  
  26.     static Action dig(Coord pos, String... message) {
  27.         return new Action(ActionType.DIG, pos, null, message);
  28.     }
  29.  
  30.     static Action request(EntityType item, String... message) {
  31.         return new Action(ActionType.REQUEST, null, item, message);
  32.     }
  33.     public Action clone()
  34.     {
  35.         return new Action(type, pos.clone(), item);
  36.     }
  37.     public String toString() {
  38.         StringBuilder builder = new StringBuilder(type.toString());
  39.         if (pos != null) {
  40.             builder.append(' ').append(pos);
  41.         }
  42.         if (item != null) {
  43.             builder.append(' ').append(item);
  44.         }
  45.         if (message != null) {
  46.              builder.append(' ').append(message);
  47.         }
  48.         return builder.toString();
  49.     }
  50. }
  51. class Entity {
  52.     private static final Coord DEAD_POS = new Coord(-1, -1);
  53.  
  54.     // Updated every turn
  55.     final int id;
  56.     final EntityType type;
  57.     Coord pos;
  58.     final EntityType item;
  59.  
  60.     // Computed for my robots
  61.     Action action = null;
  62.     Action nextAction = null;
  63.  
  64.     Entity(Scanner in) {
  65.         id = in.nextInt();
  66.         type = EntityType.valueOf(in.nextInt());
  67.         pos = new Coord(in);
  68.         item = EntityType.valueOf(in.nextInt());
  69.     }
  70.     Entity(int id, EntityType type, Coord pos, EntityType item, Action action)
  71.     {
  72.         this.id = id;
  73.         this.type = type;
  74.         this.pos = pos;
  75.         this.item = item;
  76.         this.action = action;
  77.     }
  78.     public Entity clone()
  79.     {
  80.         return new Entity(id, type, pos.clone(), item, action.clone());
  81.     }
  82.  
  83.     boolean isAlive() {
  84.         return !DEAD_POS.equals(pos);
  85.     }
  86. }
  87.  
  88. class Game {
  89.     // Given at startup
  90.     final int width;
  91.     final int height;
  92.  
  93.     // Updated each turn
  94.     final Team myTeam = new Team();
  95.     final Team opponentTeam = new Team();
  96.     public Cell[][] cells;
  97.     int myRadarCooldown;
  98.     int myTrapCooldown;
  99.     Map<Integer, Entity> entitiesById;
  100.     ArrayList<Coord> myRadarPos;
  101.     ArrayList<Coord> myTrapPos;
  102.  
  103. }
  104.  
  105. // visa mano boto logika
  106. // game dabartinio turn žaidimo state
  107. // lastGame praeito
  108.  void think(Game game, Game lastGame)
  109.     {
  110.         turns++;
  111.         this.game = game;
  112.         this.lastGame = lastGame;
  113.         // prediction of the enemy
  114.         // jei žaidimas tęsiasi ilgiau nei 130 turns, pradedu kasti ores, kurie priklauso mano sukurtam bankui
  115.         if(turns > 130)
  116.         {
  117.             MineBankOres = true;
  118.         }
  119.        
  120.         // enemy prediction
  121.         predictEnemy();
  122.         // randa geriausią radarą
  123.         Pair<Coord, Integer> radar = getBestRadarPosition();
  124.         // randa geriausią robotą radarui nešti
  125.         int id = getRadarBuyer();
  126.  
  127.         ArrayList<Entity> robotsLeft = new ArrayList<>();
  128.  
  129.         for (Entity robot : game.myTeam.robots) {
  130.             // jeigu miręs robotas, nieko nedaryti
  131.             if(!robot.isAlive())
  132.             {
  133.                 robot.action = Action.none();
  134.                 continue;
  135.             }
  136.             //jeigu robotas neša ore, eiti į HQ
  137.             if(robot.item == EntityType.AMADEUSIUM)
  138.             {
  139.                 robot.action = Action.move(new Coord(0, robot.pos.y));
  140.                 continue;
  141.             }
  142.             // patikrinu ar galiu susisprogdinti ir tuo pačiu nužudyti priešų botą
  143.             Cell suicide = suicideAttack(robot);
  144.             if(suicide != null)
  145.             {
  146.                 game.getCell(suicide.pos).possibilityOfBomb = 0;
  147.                 robot.action = Action.dig(suicide.pos, "REEEEEEEEE");
  148.                 continue;
  149.             }
  150.             // radaro logiką
  151.             // ------------------
  152.             if(game.getKnownSafeOres(MineBankOres).size() / 2 < game.myTeam.robots.size() && robot.id == radar.second)
  153.             {
  154.                 if(!robot.item.equals(EntityType.RADAR))
  155.                 {
  156.                     robot.action = Action.request(EntityType.RADAR);
  157.                 }
  158.                 else
  159.                 {
  160.                     robot.action = Action.dig(radar.first);
  161.                 }
  162.                 continue;
  163.             }
  164.             else if(game.getKnownSafeOres(MineBankOres).size() / 2 < game.myTeam.robots.size() && robot.id == id && radar.second == -1)
  165.             {
  166.                 robot.action = Action.move(new Coord(0, robot.pos.y));
  167.                 continue;
  168.             }
  169.  
  170.             if(lastGame == null)
  171.             {
  172.                 robot.action = Action.none();
  173.                 continue;
  174.             }
  175.             robot.action = null;   
  176.             // robotai like be komandų
  177.             robotsLeft.add(robot);
  178.         }
  179.  
  180.  
  181.         // with left robots go mine minerals etc. Find most efficient ways to gather them
  182.         findBestBotMineOrderNoRandom(robotsLeft);
  183.  
  184.         // jeigu vis dar yra robotų kurie neturi priskirto action, tada pritaikoma kita logika
  185.         for(Entity robot : robotsLeft)
  186.         {
  187.             if(!robot.isAlive())
  188.                 continue;
  189.             if(robot.action == null)
  190.             {
  191.                 boolean found = false;
  192.                 for(int i = 3; i < 10;i++) {
  193.                     Coord bestPos = game.findClosestDigInRange(robot.pos, radar.first, i);
  194.                     if (radar.second != -1 && bestPos != null && bestPos.isValid()) {
  195.                         game.getCell(bestPos).hole = true;
  196.                         robot.action = Action.dig(bestPos);
  197.                         found = true;
  198.                         break;
  199.                     }
  200.                 }
  201.                 if(!found)
  202.                 {
  203.                     Coord bestPos2 = findClosestUnknownDig(robot).pos;
  204.                     game.getCell(bestPos2).hole = true;
  205.                     robot.action =  Action.dig(bestPos2);
  206.                 }
  207.             }
  208.         }
  209.  
  210.         // now if robot is at x == 0
  211.         // try to fake take bomb action, a.k.a wait
  212.         faking();
  213.         predictNextOre();
  214.         // Jau turiu visus robotų action, dabar sutaisau judėjimą robotų, kad neįeičiau į priešų spastus ir pan.
  215.         Movement.fixMovement(game);
  216.         game.reset();
  217.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement