Esempio n. 1
0
  private static void shallWeAllIn() throws GameActionException {
    if (rc.senseEnemyNukeHalfDone() && Clock.getRoundNum() < 300) {
      rc.broadcast(Constants.attackChannel, Constants.attackAllIn);
      return;
    }

    int massedRobos = 0;
    double massedAmountNeeded = .5 * (40 + (10 * gencount) - (1 * othercount));

    if (rc.senseEnemyNukeHalfDone()) massedAmountNeeded -= 10;

    int rallyRadius = 33;
    if (massedAmountNeeded > 50) rallyRadius = 63;

    Robot[] robos =
        rc.senseNearbyGameObjects(Robot.class, findRallyPoint(), rallyRadius, rc.getTeam());

    for (Robot r : robos) {
      if (rc.senseRobotInfo(r).type == RobotType.SOLDIER) {
        ++massedRobos;
      }
    }

    if (massedRobos > massedAmountNeeded) // if we should all in...
    {
      rc.broadcast(Constants.attackChannel, Constants.attackAllIn);
      allInRound = Clock.getRoundNum();
    }
  }
Esempio n. 2
0
  public static boolean doWeNeedGenerator() throws GameActionException {
    if (rc.readBroadcast(Constants.campChannel) == Constants.campGenInProduction) return false;
    if (Clock.getRoundNum() - allInRound < 80) return false;
    if (rc.readBroadcast(Constants.commandChannel) == Constants.commandRally
        && rc.getTeamPower() > powerThreshold) return false;

    if (rc.getTeamPower() < minPowerThreshold && Clock.getRoundNum() > minRoundThreshold) {
      return true;
    }

    gencount = 0;
    soldiercount = 0;
    othercount = 0;

    Robot[] robos =
        rc.senseNearbyGameObjects(Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam());
    for (Robot r : robos) {
      RobotType rt = rc.senseRobotInfo(r).type;
      if (rt == RobotType.GENERATOR) ++gencount;
      else if (rt == RobotType.SOLDIER) ++soldiercount;
      else ++othercount;
    }

    double decay = .8;
    if (rc.hasUpgrade(Upgrade.FUSION)) {
      decay = .99;
    }

    if ((40 + (10 * gencount) - (1.6 * soldiercount) - (1 * othercount)) * decay < 1) {
      return true;
    }
    return false;
  }
Esempio n. 3
0
  // After a little while, if nothing has gone wrong, if we are next to a pastr and no one
  // else is building or has built a noise tower, build one.
  private boolean tryBuildNoiseTower() throws GameActionException {
    if (!rc.isActive()) return false;
    if (Clock.getRoundNum() < 200) return false;
    if (rc.senseRobotCount() < 6) return false;

    // A problem with building a noise tower is that it makes us more vulnerable to
    // a rush. If it's early and the opponent hasn't build a pastr, let's hold off
    // in case it means that they are rushing.
    if (Clock.getRoundNum() < 300 && rc.sensePastrLocations(them).length == 0) return false;

    // Only allowed to build noise tower if adjacent to pastr
    MapLocation[] ourPastrs = rc.sensePastrLocations(us);
    if (ourPastrs.length == 0 || !here.isAdjacentTo(ourPastrs[0])) return false;

    // Check if someone else is already building a noise tower
    MapLocation existingBuilder = MessageBoard.BUILDING_NOISE_TOWER.readMapLocation();
    if (existingBuilder != null) {
      if (rc.senseNearbyGameObjects(Robot.class, existingBuilder, 1, us).length > 0) {
        return false;
      }
    }

    // Construct the noise tower and advertise the fact that we are doing it
    MessageBoard.BUILDING_NOISE_TOWER.writeMapLocation(here);
    constructNoiseTower(ourPastrs[0]);
    return true;
  }
Esempio n. 4
0
  public void run() {
    while (true) {
      try {
        Robot[] enemies = rc.senseNearbyGameObjects(Robot.class, 35, rc.getTeam().opponent());

        if (rc.isActive()) {
          Movement.fire(rc, enemies, null);
          HQFunctions.SpawnSoldiers(rc);
        }

        if (Clock.getRoundNum() % 50 == 0) {
          System.out.println();
          System.out.println("Enemy Bots: ");
          int[] AllEnemies = FightMicro.AllEnemyBots(rc);
          for (int i = 0; i < AllEnemies.length; i++) {
            System.out.print(FightMicro.getBotLocation(AllEnemies[i]));
          }
          System.out.println();
        }

        int broadcast = rc.readBroadcast(rallyPoint2);
        if (broadcast != 0) {
          if (broadcast != fightZone) {
            fightZone = broadcast;
            roundSet = Clock.getRoundNum();
          }
          // now it is time for us to move on
          else if (roundSet + 75 < Clock.getRoundNum()) {
            fightZone = 0;
            rc.broadcast(rallyPoint2, 0);
          }
        }

        if (Clock.getRoundNum() % 5 == 0 && Clock.getRoundNum() > 100) {
          // HQFunctions.moveTargetLocationRandomly(rc);
          /*
          if (goneForPastr && (rc.sensePastrLocations(rc.getTeam()).length > 0 || roundNum > (Clock.getRoundNum() - 250)))
          {
              HQFunctions.setTargetLocation(rc, goneForPastr);
          }
          else
          {
              goneForPastr = HQFunctions.setTargetLocation(rc, goneForPastr);
              roundNum = Clock.getRoundNum();
          }*/
          HQFunctions.setTargetLocation(rc, true);
          // HQFunctions.findInitialRally(rc);

        }
      } catch (Exception e) {
      }
      rc.yield();
    }
  }
Esempio n. 5
0
  // HQ or pastr calls this function to spend spare bytecodes computing paths for soldiers
  public static void work(MapLocation dest, int priority, int bytecodeLimit)
      throws GameActionException {
    int page = findFreePage(dest, priority);
    Debug.indicate("path", 1, "BFS Pathing to " + dest.toString() + "; using page " + page);
    if (page == -1) return; // We can't do any work, or don't have to

    if (!dest.equals(previousDest)) {
      Debug.indicate("path", 0, "BFS initingQueue");
      initQueue(dest);
    } else {
      Debug.indicate("path", 0, "BFS queue already inited");
    }

    previousDest = dest;
    previousRoundWorked = Clock.getRoundNum();
    previousPage = page;

    int mapWidth = rc.getMapWidth();
    int mapHeight = rc.getMapHeight();
    MapLocation enemyHQ = rc.senseEnemyHQLocation();
    boolean destInSpawn = dest.distanceSquaredTo(enemyHQ) <= 25;

    while (locQueueHead != locQueueTail && Clock.getBytecodeNum() < bytecodeLimit) {
      // pop a location from the queue
      MapLocation loc = locQueue[locQueueHead];
      locQueueHead++;

      int locX = loc.x;
      int locY = loc.y;
      for (int i = 8; i-- > 0; ) {
        int x = locX + dirsX[i];
        int y = locY + dirsY[i];
        if (x >= 0 && y >= 0 && x < mapWidth && y < mapHeight && !wasQueued[x][y]) {
          MapLocation newLoc = new MapLocation(x, y);
          if (rc.senseTerrainTile(newLoc) != TerrainTile.VOID
              && (destInSpawn || !Bot.isInTheirHQAttackRange(newLoc))) {
            publishResult(page, newLoc, dest, dirs[i]);

            // push newLoc onto queue
            locQueue[locQueueTail] = newLoc;
            locQueueTail++;
            wasQueued[x][y] = true;
          }
        }
      }
    }

    boolean finished = locQueueHead == locQueueTail;
    Debug.indicate("path", 2, "BFS finished = " + finished + "; locQueueHead = " + locQueueHead);
    writePageMetadata(page, Clock.getRoundNum(), dest, priority, finished);
  }
Esempio n. 6
0
  private static void runMissile() {
    int lastTurn = Clock.getRoundNum() + GameConstants.MISSILE_LIFESPAN;
    int[] damageRange = {0, 8, 15, 24, 35, 48};
    MapLocation target = null;
    boolean targetMoves = true;

    while (true) {
      myLoc = rc.getLocation();
      int turns = lastTurn - Clock.getRoundNum();

      if (targetMoves) { // Re-acquire the target's location
        RobotInfo[] inRange = rc.senseNearbyRobots(damageRange[turns], enemyTeam);
        if (inRange.length > 0) { // No units to target
          target = inRange[0].location;
          targetMoves = inRange[0].type.canMove();
          rc.setIndicatorString(0, "Missile targetting " + inRange[0].type + "@" + target);
        } else {
          targetMoves = false; // Pick a tower or the HQ
          MapLocation[] enemyTowers = rc.senseEnemyTowerLocations();
          for (MapLocation t : enemyTowers) {
            if (myLoc.distanceSquaredTo(t) <= damageRange[turns]) {
              target = t;
              rc.setIndicatorString(0, "Missile targetting Tower @" + target);
              break;
            }
          }
          if (target == null) {
            target = rc.senseEnemyHQLocation();
            rc.setIndicatorString(0, "Missile targetting HQ @" + target);
          }
        }
      }

      try {
        if (target != null) {
          if (myLoc.distanceSquaredTo(target) <= GameConstants.MISSILE_RADIUS_SQUARED) rc.explode();
          else {
            Direction d = myLoc.directionTo(target);
            if (rc.canMove(d)) rc.move(d);
            else if (rc.canMove(d.rotateLeft())) rc.move(d.rotateLeft());
            else if (rc.canMove(d.rotateRight())) rc.move(d.rotateRight());
          }
        }
      } catch (GameActionException e) {
        System.out.println("Missile exception");
        // e.printStackTrace();
      }
      rc.yield();
    }
  }
Esempio n. 7
0
  public LinkedList<MapLocation> pathFind(MapLocation start, MapLocation target)
      throws GameActionException {
    //		for (int i = 0; i < myRobot.allies.length; i++) {
    //			RobotInfo r = rc.senseRobotInfo(myRobot.allies[i]);
    //			if (myRobot.allies[i].getID() == myRobot.ID) continue;
    //			map[r.location.x][r.location.y] = -2;
    //		}
    //		for (int i = 0; i < myRobot.enemies.length; i++) {
    //			RobotInfo r = rc.senseRobotInfo(myRobot.enemies[i]);
    //			map[r.location.x][r.location.y] = -2;
    //		}
    int x = Clock.getRoundNum();
    SearchNode bugSearch = bugSearch(start, target);
    SearchNode[] nodes = new SearchNode[bugSearch.length];
    int counter = bugSearch.length - 1;
    while (bugSearch.prevLoc != null) {
      nodes[counter] = bugSearch;
      bugSearch = bugSearch.prevLoc;
      counter--;
    }

    nodes[0] = bugSearch;
    LinkedList<MapLocation> pivots = new LinkedList<MapLocation>();
    pivots.add(nodes[0].loc);

    for (int i = 1; i < nodes.length; i++) {
      if (nodes[i].isPivot) {
        pivots.add(nodes[i].loc);
      }
    }

    counter = 0;
    ListIterator<MapLocation> li1 = pivots.listIterator(), li2;
    while (li1.hasNext()) {
      li2 = pivots.listIterator(pivots.size());
      while (li2.hasPrevious() && li2.previousIndex() > li1.nextIndex() + 1) {
        if (canTravel(li1.next(), li2.previous())) {
          pivots.subList(li1.nextIndex(), li2.previousIndex() + 1).clear();
          li1 = pivots.listIterator(++counter);
          break;
        }
        li1.previous();
      }
      li1.next();
    }

    if (false) System.out.println(Clock.getRoundNum() - x);
    return pivots;
  }
Esempio n. 8
0
  // Drones
  private static void runDrone() {
    moveDir = Direction.NORTH;
    droneMoveCurrent = 1;
    droneMoveMax = 2;
    patrolClockwise = true;
    droneCentred = false; // We haven't made it to the centre of our spiral yet

    while (true) {
      threats.update();
      myLoc = rc.getLocation();

      // Attack if there is an enemy in sight
      if (rc.isWeaponReady()) attackWeakest();

      // Move if we can and want to
      if (rc.isCoreReady()) {
        if (shouldRetreat()) {
          doRetreatMove(); // Pull back if in range of the enemy guns
        } else if (Clock.getRoundNum() < 600) {
          doPatrol();
        } else {
          doSupply();
        }
      }

      doTransfer();

      rc.yield();
    }
  }
Esempio n. 9
0
  // Determines squad of robot to by spawned next
  private static int nextSquadNum(RobotController rc) throws GameActionException {
    // If it reads that defensive robots are dying from channel 10
    int squad = rc.readBroadcast(Util.spawnNext);
    if (squad != 0 && squad < 11 && !rush) {
      rc.broadcast(Util.spawnNext, 0); // reset value
      //			System.out.println("spawning a replacement for defender" + squad);
      return squad;
    }

    // If starting out a rush, spawn enough attacking squads.
    boolean rushFailed = false; // temporary hot fix - later this should be a checkpoint
    int rushRetreat = computeRushRetreat(rc);
    if (rush && Clock.getRoundNum() < rushRetreat && !rushFailed) { // TODO decide when to stop rush
      for (int i = 11; i < 12; i++) {
        if ((rc.readBroadcast(i) / 10000) % 10 < 8) return i;
      }
    }

    // Else if didn't establish pastures yet, need defensive squads
    for (int i = 3; i < 3 + desiredPASTRs.length; i++) {
      if ((rc.readBroadcast(i) / 10000) % 10 < 6) return i;
    }

    // else spawn attackers
    for (int i = 11; i < 21; i++) {
      if ((rc.readBroadcast(i) / 10000) % 10 < 6) return i;
    }

    return 3;
  }
Esempio n. 10
0
  public void turn() throws GameActionException {
    updateStrategicInfo();

    // First turn gets special treatment: spawn then do a bunch of computation
    // (which we devoutly hope will finished before the spawn timer is up
    // and before anyone attacks us).
    if (Clock.getRoundNum() == 0) {
      doFirstTurn();
      return;
    }

    if (rc.isActive()) {
      spawnSoldier();
    }

    attackEnemies();

    directStrategy();

    // Use spare bytecodes to do pathing computations
    MapLocation pathingDest;
    if (attackModeTarget != null) pathingDest = attackModeTarget;
    else if (computedBestPastrLocation != null) pathingDest = computedBestPastrLocation;
    else pathingDest = null;

    if (pathingDest != null) Bfs.work(pathingDest, rc, 9000);
  }
Esempio n. 11
0
  public static void run(RobotController myRC) {
    BaseRobot br = null;
    try {
      switch (myRC.getType()) {
        case HQ:
          br = new HQRobot(myRC);
          break;
        case SOLDIER:
          br = new SoldierRobot(myRC);
          break;
        case ARTILLERY:
          br = new Artillery(myRC);
          break;
        default:
          br = new PassiveEncampment(myRC);
      }

      while (true) {
        br.curRound = Clock.getRoundNum();
        br.run();

        br.rc.yield();
      }

    } catch (Exception e) {
      // DEBUG
      System.out.println("Shit happened!");
      e.printStackTrace();
      br.rc.addMatchObservation(e.toString());
    }
  }
Esempio n. 12
0
 public void fightingCode() throws GameActionException {
   if (DataCache.numEnemyRobots == 0) {
     if (DataCache.numAlliedSoldiers < Constants.FIGHTING_NOT_ENOUGH_ALLIED_SOLDIERS) {
       if (!ourNukeHalfDone && enemyNukeHalfDone) {
         nextSoldierState = SoldierState.PUSHING;
         pushingCode();
       } else {
         if (Clock.getRoundNum() >= 200) {
           nextSoldierState = SoldierState.RALLYING;
           rallyingCode();
         } else {
           nextSoldierState = SoldierState.PUSHING;
           pushingCode();
         }
       }
     } else {
       nextSoldierState = SoldierState.PUSHING;
       pushingCode();
     }
   } else {
     // Otherwise, just keep fighting
     if (strategy == Strategy.NUKE) {
       defendMicro();
     } else {
       microCode();
     }
   }
 }
Esempio n. 13
0
  private int findFreePage(MapLocation dest, int priority) throws GameActionException {
    // see if we can reuse a page we used before
    if (dest.equals(previousDest) && previousPage != -1) {
      int previousPageMetadata = readPageMetadata(previousPage);
      if (getMetadataRoundLastUpdated(previousPageMetadata) == previousRoundWorked) {
        MapLocation where = getMetadataDestination(previousPageMetadata);
        if (where.x == cropX(dest.x) && where.y == cropY(dest.y)) {
          if (getMetadataIsFinished(previousPageMetadata)) {
            if (getMetadataIsComplete(previousPageMetadata))
              return -1; // we're done! don't do any work!
            // Restart the search with more up to data map info
            initQueue(dest);
            // System.out.print("Restart BFS to " + dest + ", page " + previousPage+ ", start round
            // " + Clock.getRoundNum() + "\n");
            return previousPage;
          } else {
            return previousPage;
          }
        }
      }
    }

    // Check to see if anyone else is working on this destination. If so, don't bother doing
    // anything.
    // But as we loop over pages, look for the page that hasn't been touched in the longest time
    int lastRound = Clock.getRoundNum() - 1;
    int oldestPage = -1;
    int oldestPageRoundUpdated = 999999;
    for (int page = 0; page < NUM_PAGES; page++) {
      int metadata = readPageMetadata(page);
      if (metadata == 0) { // untouched page
        if (oldestPageRoundUpdated > 0) {
          oldestPage = page;
          oldestPageRoundUpdated = 0;
        }
      } else {
        int roundUpdated = getMetadataRoundLastUpdated(metadata);
        boolean isFinished = getMetadataIsFinished(metadata);
        if (roundUpdated >= lastRound || isFinished) {
          if (cropSame(getMetadataDestination(metadata), dest)) {
            return -1; // someone else is on the case!
          }
        }
        if (roundUpdated < oldestPageRoundUpdated) {
          oldestPageRoundUpdated = roundUpdated;
          oldestPage = page;
        }
      }
    }

    // No one else is working on our dest. If we found an inactive page, use that one.
    if (oldestPage != -1 && oldestPageRoundUpdated < lastRound) return oldestPage;

    // If there aren't any inactive pages, and we have high priority, just trash page 0:
    if (priority == PRIORITY_HIGH) return 0;

    // otherwise, give up:
    return -1;
  }
  public static void run(RobotController myRC) {
    rc = myRC;
    barracks = findBarracks();
    while (true) {
      try {
        if (rc.getType() == RobotType.SOLDIER) {
          Robot[] enemyRobots =
              rc.senseNearbyGameObjects(
                  Robot.class, 50000, rc.getTeam().opponent()); // list of enemy robots
          if (enemyRobots.length == 0) {
            Clock.getRoundNum(); // gets the round number
            if (Clock.getRoundNum() < 250) {
              goToLocation(
                  barracks); // if you are before round 250 travel to the "barracks" or meeting
                             // place.
            } else {
              goToLocation(rc.senseEnemyHQLocation());
            }
          } else { // else attack the closest enemy
            int closestDist = 50000;
            MapLocation closestEnemy = null;
            for (int i = 0; i < enemyRobots.length; i++) {
              Robot enemyBot = enemyRobots[i];
              RobotInfo arobotInfo = rc.senseRobotInfo(enemyBot);
              int dist = arobotInfo.location.distanceSquaredTo(rc.getLocation());
              if (dist < closestDist) {
                closestDist = dist;
                closestEnemy = arobotInfo.location;
              }
            }
            goToLocation(closestEnemy);
          }
        } else {
          HqCommand();
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
      rc.yield(); // end turn
    }
  }
Esempio n. 15
0
 public void enemyInSight(
     MapLocation[] locations,
     int[] ints,
     String[] strings,
     int locationStart,
     int intStart,
     int stringStart,
     int count) {
   closestEnemySeen = Clock.getRoundNum();
   closestEnemy = navigation.findClosest(locations, locationStart);
 }
Esempio n. 16
0
 public static void timerEnd(String message) {
   int endBytecodeNum = Clock.getBytecodeNum();
   int endRoundNum = Clock.getRoundNum();
   if (endRoundNum == startRoundNum)
     System.out.format(
         "timed %s: took %d bytecodes\n", message, endBytecodeNum - startBytecodeNum);
   else
     System.out.format(
         "timed %s: took %d turns + %d bytecodes\n",
         message, endRoundNum - startRoundNum, endBytecodeNum - startBytecodeNum);
 }
Esempio n. 17
0
  static void runScout(RobotController rc, int squad) throws GameActionException {
    int squadInfo = rc.readBroadcast(squad);
    MapLocation target = Conversion.intToMapLocation(Channels.scoutDecoding(squadInfo)[1]);
    MapLocation curr = rc.getLocation();

    if (curr.distanceSquaredTo(target) > 50) Move.moveTo(rc, target);
    else {
      int start = Channels.scoutDecoding(squadInfo)[0];
      rc.broadcast(
          Channels.scoutChannel, Channels.scoutEncoding((Clock.getRoundNum() - start), target, 1));
    }
  }
Esempio n. 18
0
  public void herdInward() throws GameActionException {
    radius = 20 - Math.min(13, (Clock.getRoundNum() % 120) * 16.0 / 120.0);

    MapLocation target =
        new MapLocation(
            (int) (here.x + radius * Math.cos(angle)), (int) (here.y + radius * Math.sin(angle)));
    angle += rate;
    rc.setIndicatorString(0, "angle = " + angle);
    if (rc.canAttackSquare(target)) {
      rc.attackSquare(target);
    }
  }
Esempio n. 19
0
  private static void turn() throws GameActionException {
    if (rc.getHealth() <= 6 * RobotType.SOLDIER.attackPower) {
      MessageBoard.PASTR_DISTRESS_SIGNAL.writeInt(Clock.getRoundNum());
    }

    // do speculative pathing calculations
    int bytecodeLimit = 9000;
    MapLocation[] enemyPastrs = rc.sensePastrLocations(them);
    for (int i = 0; i < enemyPastrs.length; i++) {
      if (Clock.getBytecodeNum() > bytecodeLimit) break;
      Bfs.work(enemyPastrs[i], Bfs.PRIORITY_LOW, bytecodeLimit);
    }
  }
Esempio n. 20
0
  private static int findFreePage(MapLocation dest, int priority) throws GameActionException {
    // see if we can reuse a page we used before
    if (dest.equals(previousDest) && previousPage != -1) {
      int previousPageMetadata = readPageMetadata(previousPage);
      if (getMetadataRoundLastUpdated(previousPageMetadata) == previousRoundWorked
          && getMetadataDestination(previousPageMetadata).equals(dest)) {
        if (getMetadataIsFinished(previousPageMetadata)) {
          return -1; // we're done! don't do any work!
        } else {
          return previousPage;
        }
      }
    }

    // Check to see if anyone else is working on this destination. If so, don't bother doing
    // anything.
    // But as we loop over pages, look for the page that hasn't been touched in the longest time
    int lastRound = Clock.getRoundNum() - 1;
    int oldestPage = -1;
    int oldestPageRoundUpdated = 999999;
    for (int page = 0; page < NUM_PAGES; page++) {
      int metadata = readPageMetadata(page);
      if (metadata == 0) { // untouched page
        if (oldestPageRoundUpdated > 0) {
          oldestPage = page;
          oldestPageRoundUpdated = 0;
        }
      } else {
        int roundUpdated = getMetadataRoundLastUpdated(metadata);
        boolean isFinished = getMetadataIsFinished(metadata);
        if (roundUpdated >= lastRound || isFinished) {
          if (getMetadataDestination(metadata).equals(dest)) {
            return -1; // someone else is on the case!
          }
        }
        if (roundUpdated < oldestPageRoundUpdated) {
          oldestPageRoundUpdated = roundUpdated;
          oldestPage = page;
        }
      }
    }

    // No one else is working on our dest. If we found an inactive page, use that one.
    if (oldestPage != -1 && oldestPageRoundUpdated < lastRound) return oldestPage;

    // If there aren't any inactive pages, and we have high priority, just trash page 0:
    if (priority == PRIORITY_HIGH) return 0;

    // otherwise, give up:
    return -1;
  }
Esempio n. 21
0
  public static void initUtils(RobotController rc) {
    RC = rc;
    ID = RC.getRobot().getID();

    MAP_WIDTH = rc.getMapWidth();
    MAP_HEIGHT = rc.getMapHeight();

    ALLY_TEAM = rc.getTeam();
    ENEMY_TEAM = (ALLY_TEAM == Team.A) ? Team.B : Team.A;
    ALLY_HQ = rc.senseHQLocation();
    ENEMY_HQ = rc.senseEnemyHQLocation();

    birthRound = Clock.getRoundNum();

    random = new Random(((long) ID << 32) ^ Clock.getRoundNum());

    //		messagingSystem = new MessagingSystem();

    for (Upgrade upgrade : Upgrade.values()) {
      UPGRADES_RESEARCHED[upgrade.ordinal()] = RC.hasUpgrade(upgrade);
    }
    updateUtils();
  }
Esempio n. 22
0
  // Launch a missile if there is an enemy in sight.
  // We ignore other missiles
  private static void doLaunch() {
    int count = rc.getMissileCount();
    if (count > 0 && Clock.getRoundNum() % 2 == 0) {
      MapLocation launchFrom; // We can launch 1 tile towards the enemy
      MapLocation explodeAt; // We can explode adjacent to the enemy (1 tile towards us)
      int missileRange = 30;
      RobotInfo[] enemies = rc.senseNearbyRobots(49, enemyTeam);
      MapLocation target = null;
      for (RobotInfo r : enemies) {
        if (r.type != RobotType.MISSILE) { // Ignore missiles
          launchFrom = myLoc.add(myLoc.directionTo(r.location));
          explodeAt = r.location.add(r.location.directionTo(myLoc));
          if (launchFrom.distanceSquaredTo(explodeAt) <= missileRange) {
            target = r.location;
            break;
          }
        }
      }
      if (target == null) { // Check for towers
        for (MapLocation t : threats.enemyTowers) {
          launchFrom = myLoc.add(myLoc.directionTo(t));
          explodeAt = t.add(t.directionTo(myLoc));
          if (launchFrom.distanceSquaredTo(explodeAt) <= missileRange) {
            target = t;
            break;
          }
        }

        if (target == null) { // Check for HQ
          MapLocation ehq = threats.enemyHQ;
          launchFrom = myLoc.add(myLoc.directionTo(ehq));
          explodeAt = ehq.add(ehq.directionTo(myLoc));
          if (launchFrom.distanceSquaredTo(explodeAt) <= missileRange) target = ehq;
        }
      }
      if (target != null) {
        try {
          Direction d = myLoc.directionTo(target);

          if (rc.canLaunch(d)) {
            rc.launchMissile(d);
          }
        } catch (GameActionException e) {
          System.out.println("Launch exception");
          e.printStackTrace();
        }
      }
    }
  }
Esempio n. 23
0
public class Util {

  static int m_z = Clock.getBytecodeNum();
  static int m_w = Clock.getRoundNum();

  /**
   * Sets up our RNG given two seeds.
   *
   * @param seed1
   * @param seed2
   */
  public static void randInit(int seed1, int seed2) {
    m_z = seed1;
    m_w = seed2;
  }

  private static int gen() {
    m_z = 36969 * (m_z & 0xFFFF) + (m_z >> 16);
    m_w = 18000 * (m_w & 0xFFFF) + (m_w >> 16);
    return (m_w << 16) + m_z;
  }

  /**
   * Returns a random {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE}
   *
   * @return
   */
  public static int randInt() {
    return gen();
  }

  /**
   * Returns a double between 0 and 1.0
   *
   * @return
   */
  public static double randDouble() {
    return (gen() * 2.32830644e-10 + 0.5);
  }

  /**
   * Calls randDouble()
   *
   * @return
   */
  public static double Random() {
    return randDouble();
  }
}
Esempio n. 24
0
  @Override
  public void run() {
    while (true) {
      try {

      } catch (Exception e) {
        System.out.println(
            "Robot "
                + myRC.getRobot().getID()
                + " during round number "
                + Clock.getRoundNum()
                + " caught exception:");
        e.printStackTrace();
      }
    }
  }
Esempio n. 25
0
  /*
   * Moves towards the nearest enemy
   * Returns true if we moved or are in the right place
   */
  private static boolean doCloseWithEnemyMove(boolean ignoreThreat) {
    // Move to within attack range of the nearest enemy - ignore towers and HQ until later in the
    // game
    // We can move in closer if we are still out of range of the enemy
    RobotInfo nearest = null;
    RobotInfo preferred = null;
    RobotInfo[] enemies = rc.senseNearbyRobots(senseRange * 16, enemyTeam);
    boolean canFly = (myType == RobotType.DRONE);

    int now = Clock.getRoundNum();
    for (RobotInfo e : enemies) {
      // We want to find and circle units, not towers or HQ (until later in the game)
      if (now < maxRounds / 2 && (e.type == RobotType.HQ || e.type == RobotType.TOWER)) continue;
      // Drones on VOID tiles cannot be reached by ground troops - ignore them
      if (!canFly && rc.senseTerrainTile(e.location) != TerrainTile.NORMAL) continue;
      // Commanders are good at picking off miners, beavers and non combat buildings - have a
      // preference for them
      if (myType == RobotType.COMMANDER
          && commanderLikes(e.type)
          && (preferred == null
              || e.location.distanceSquaredTo(myLoc) < preferred.location.distanceSquaredTo(myLoc)))
        preferred = e;
      if (nearest == null
          || e.location.distanceSquaredTo(myLoc) < nearest.location.distanceSquaredTo(myLoc))
        nearest = e;
    }

    if (preferred != null) nearest = preferred;

    int attackRange = myType.attackRadiusSquared;
    if (myType == RobotType.LAUNCHER)
      attackRange = (1 + GameConstants.MISSILE_LIFESPAN) * (1 + GameConstants.MISSILE_LIFESPAN);

    if (nearest != null) {
      if (ignoreThreat || myLoc.distanceSquaredTo(nearest.location) > attackRange) {
        rc.setIndicatorString(2, "Closing with " + nearest.type + " at " + nearest.location);
        if (rc.isCoreReady()) tryMove(rc.getLocation().directionTo(nearest.location), ignoreThreat);
      } else {
        rc.setIndicatorString(
            2, "Holding at range with " + nearest.type + " at " + nearest.location);
      }
      return true;
    }
    return false;
  }
Esempio n. 26
0
  public SoldierRobot(RobotController rc) throws GameActionException {
    super(rc);

    NavSystem.init(this);

    if (Clock.getRoundNum() < 10) {
      soldierState = soldierState.SCOUTING;
    } else {
      ChannelType channel = EncampmentJobSystem.findJob();
      if (channel != null) {
        unassigned = false;
        EncampmentJobSystem.updateJobTaken();
      }

      // TODO: this will f**k up if we ever build artillery for non-nuke bots
      // LEARN THE STRATEGY
      Message message = BroadcastSystem.read(ChannelType.STRATEGY);
      if (message.isValid && message.body < Strategy.values().length && message.body >= 0) {
        strategy = Strategy.values()[message.body];
      } else {
        // we couldn't read the strategy channel
        MapLocation[] alliedEncampmentSquares = rc.senseAlliedEncampmentSquares();
        if (alliedEncampmentSquares.length == 0) {
          strategy = Strategy.ECON;
        } else {
          Robot robot = (Robot) rc.senseObjectAtLocation(alliedEncampmentSquares[0]);
          RobotInfo robotInfo = rc.senseRobotInfo(robot);
          if (robotInfo.type == RobotType.ARTILLERY) {
            strategy = Strategy.NUKE;
          } else {
            strategy = Strategy.ECON;
          }
        }
      }

      //			rc.setIndicatorString(2, strategy.toString());

      rallyPoint = findRallyPoint();

      rSquared = DataCache.rushDistSquared / 4;

      initializeMining();
    }
  }
Esempio n. 27
0
  // Put team and enemy team pasture, squad, and role info into channels
  static void updateSquadLocs(RobotController rc) throws GameActionException {
    // DEFENDER CHANNELS - 3 to about 8
    // format: [N][XXYY] where N is robot count in the squad and XXYY are coordinates

    // RUSH CHANNEL - 11
    MapLocation[] enemyPASTRs = rc.sensePastrLocations(enemy);
    MapLocation rallyPoint = determineRallyPoint(rc);

    // TODO surround enemy HQ - rush ENDGAME :)
    if (rc.readBroadcast(Util.rushSuccess) > 0) {
      rc.broadcast(11, (rc.readBroadcast(11) / 10000) * 10000 + Util.locToInt(HQ.enemyHQ));
    } else if (rush && Clock.getRoundNum() < 1000) {
      // System.out.println("rush and under 1000");
      if (enemyPASTRs.length > 0) {
        rc.broadcast(11, (rc.readBroadcast(11) / 10000) * 10000 + Util.locToInt(enemyPASTRs[0]));
        attackedEnemy = true;
      } else if (attackedEnemy && enemyPASTRs.length == 0) { // shut down headquarters and endgame
        rc.broadcast(
            11, (rc.readBroadcast(11) / 10000) * 10000 + Util.locToInt(rc.senseEnemyHQLocation()));
      } else rc.broadcast(11, (rc.readBroadcast(11) / 10000) * 10000 + Util.locToInt(rallyPoint));
    }

    for (int i = 0; i < enemyPASTRs.length; i++) {
      if (enemyPASTRs[i].distanceSquaredTo(rc.senseEnemyHQLocation()) < 36) {
        // the pastr is untouchable
        rc.broadcast(
            i + 12, (rc.readBroadcast(i + 12) / 10000) * 10000 + Util.locToInt(rallyPoint));
      } else {
        rc.broadcast(
            i + 12, (rc.readBroadcast(i + 12) / 10000) * 10000 + Util.locToInt(enemyPASTRs[i]));
      }
    }

    for (int i = 0; i < desiredPASTRs.length; i++) {
      rc.broadcast(
          i + 3, (rc.readBroadcast(i + 3) / 10000) * 10000 + Util.locToInt(desiredPASTRs[i]));
      // System.out.println("SQUAD TRACKER " + (i+3));
    }
  }
Esempio n. 28
0
  public static void run(RobotController rc) {
    BaseRobot robot = null;

    int rseed = rc.getRobot().getID();
    Util.randInit(rseed, rseed * Clock.getRoundNum());

    try {
      switch (rc.getType()) {
        case HQ:
          robot = new HQRobot(rc);
          break;
        case SOLDIER:
          robot = new SoldierRobot(rc);
          break;
        case ARTILLERY:
          robot = new ArtilleryRobot(rc);
          break;
        case GENERATOR:
          robot = new GeneratorRobot(rc);
          break;
        case MEDBAY:
          robot = new MedbayRobot(rc);
          break;
        case SHIELDS:
          robot = new ShieldsRobot(rc);
          break;
        case SUPPLIER:
          robot = new SupplierRobot(rc);
          break;
        default:
          break;
      }
      robot.loop();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 29
0
  public AI act(RobotController rc) throws Exception {
    Direction d;

    // Check the panic channel.  If we're told to hold, then set
    //  destination to what the channel says and do so.
    if (Clock.getRoundNum() % 15 == 1) {
      if ((panic = radio.read(rc, RadioModule.CHANNEL_PANIC)) != 0) {
        if (panic == 0xFADCAD) {
          nav.setDestination(rc, rc.senseEnemyHQLocation());
        } else {
          target = new MapLocation(panic >>> 7, panic & 0x7F);
          nav.setDestination(rc, target);
        }
      }
    }

    // If there are enemies to fight, fight! Otherwise,
    // continue towards the enemy base
    if (rc.isActive()) {
      if ((d = fight.fightClosestRobot(rc)) == Direction.OMNI) {
        // If we're still holding, let's lay down some mines
        if (panic != 0xFADCAD
            && rc.getLocation().distanceSquaredTo(target) < MINE_DIST
            && rc.senseMine(rc.getLocation()) == null) {
          rc.layMine();
          return this;
        } else {
          d = nav.moveFlock(rc, 2);
        }
      }

      moveSafe(rc, d);
    }

    // Keep the same ai for next round
    return this;
  }
Esempio n. 30
0
  // Move towards enemy HQ if we can attack
  private static void doAdvanceMove() {
    try {
      if (myType == RobotType.COMMANDER
          && rc.hasLearnedSkill(CommanderSkillType.FLASH)
          && rc.getFlashCooldown() == 0) flashTowards(threats.enemyHQ, false);
    } catch (GameActionException e) {
      System.out.println("Flash exception");
      // e.printStackTrace();
    }

    if (rc.isCoreReady()) {
      Direction dir = null;

      if (myType.canAttack() || (myType == RobotType.LAUNCHER && Clock.getRoundNum() > 550)) {
        if (myType != RobotType.DRONE) dir = bfs.readResult(myLoc, threats.enemyHQ);
        if (dir == null) dir = myLoc.directionTo(threats.enemyHQ);
        rc.setIndicatorString(2, "Advancing " + dir);
      } else {
        dir = myLoc.directionTo(myHQ);
        rc.setIndicatorString(2, "HQ Defensive unit " + dir);
      }
      tryMove(dir, false);
    }
  }