public static void HqCommand() throws GameActionException {
    if (rc.getType() == RobotType.HQ) {
      //			if (rc.isActive()) {
      // Spawn a soldier

      int[] directionOffSets = {0, 1, -1, 2, -2};

      //			    Team mineSpawn = rc.senseMine(rc.getLocation().add(spawnDir));
      Direction dir =
          rc.getLocation().directionTo(rc.senseEnemyHQLocation()); // this does not work!
      Direction spawnDir = dir;
      // spawn robots in the direction of the enemy
      if (rc.senseMine(rc.getLocation().add(dir)) != null) {
        lookForDir:
        for (int d : directionOffSets) {
          spawnDir = Direction.values()[(dir.ordinal() + d + 8) % 8];
          if (rc.canMove(spawnDir) && rc.senseMine(rc.getLocation().add(spawnDir)) != null) {
            rc.spawn(Direction.SOUTH);
            rc.spawn(spawnDir);
            break lookForDir;
          }
        }
      }

      if (rc.canMove(dir)) {
        rc.spawn(dir);
      }
      //			}
    }
  }
  public static void moveCloserFavorNoMines() throws GameActionException {
    Direction dir = rc.getLocation().directionTo(destination);
    double distance = rc.getLocation().distanceSquaredTo(destination);
    double currDist;
    if (rc.canMove(dir) && !hasBadMine(rc.getLocation().add(dir))) {
      rc.move(dir);
    } else {
      Direction bestDir = dir;
      Direction currentDir = dir;
      for (int directionOffset : directionOffsets) {
        if (directionOffset != 0) {
          currentDir = Direction.values()[(dir.ordinal() + directionOffset + 8) % 8];
          if (rc.canMove(currentDir) && !hasBadMine(rc.getLocation().add(currentDir))) {
            currDist = rc.getLocation().add(currentDir).distanceSquaredTo(destination);
            if (currDist < distance) {
              distance = currDist;
              bestDir = currentDir;
            }
          }
        }
      }

      NavSystem.moveOrDefuse(bestDir);
    }
  }
 private static void goToLocationAvoidMines(MapLocation whereToGo) throws GameActionException {
   int dist = rc.getLocation().distanceSquaredTo(whereToGo);
   if (dist > 0 && rc.isActive()) {
     Direction dir = rc.getLocation().directionTo(whereToGo);
     goDirectionAvoidMines(dir);
   }
 }
Example #4
0
 // TODO this method needs a lot of work...isn't doing things properly even if there's just an
 // archon making bots with open space around it. Add onto that later, when there are more bots
 // around,
 // others will need to move forward in order for those just next to the archon to move.
 private static void moveAwayFromArchons(RobotController rc) throws GameActionException {
   int mySenseRadius = rc.getType().sensorRadiusSquared;
   int archonReserveDistance = 9;
   // @Hope make this more finessed
   archonReserveDistance =
       archonReserveDistance < mySenseRadius ? archonReserveDistance : mySenseRadius;
   List<RobotInfo> robots = Arrays.asList(rc.senseNearbyRobots(archonReserveDistance, myTeam));
   List<RobotInfo> archons = new ArrayList<>();
   for (RobotInfo robot : robots) {
     if (robot.type == RobotType.ARCHON) {
       archons.add(robot);
     }
   }
   boolean tooClose = false;
   MapLocation myLocation = rc.getLocation();
   for (RobotInfo archon : archons) {
     if (!tooClose && myLocation.distanceSquaredTo(archon.location) < archonReserveDistance) {
       tooClose = true;
     }
   }
   if (tooClose) {
     for (RobotInfo archon : archons) {
       if (rc.isCoreReady())
         moveTowards(rc, rc.getLocation().directionTo(archon.location).opposite());
     }
   }
 }
Example #5
0
  // In this function the HQ spawns a soldier ideally toward the enemy base but in any direction
  // otherwise
  public static void SpawnSoldiers(RobotController rc) {
    try {
      if (rc.isActive() && rc.getType() == RobotType.HQ) {
        Direction toEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
        if (rc.senseObjectAtLocation(rc.getLocation().add(toEnemy)) == null) {
        } else {
          for (int i = 0; i < 7; i++) {
            toEnemy = toEnemy.rotateLeft();

            if (rc.senseObjectAtLocation(rc.getLocation().add(toEnemy)) == null) {
              i = 47;
            } else if (i == 6) {
              toEnemy = Direction.NONE;
            }
          }
        }

        if (toEnemy != Direction.NONE) {
          if (rc.isActive()) {
            if (rc.getType() == RobotType.HQ) {
              rc.spawn(toEnemy);
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Utility Exception");
    }
  }
 /**
  * @param whereToGo
  * @throws GameActionException The original/old version of progressMove.
  */
 @SuppressWarnings("unused")
 private void progressMoveOld(MapLocation whereToGo) throws GameActionException {
   rc.setIndicatorString(1, "Swarm target: " + whereToGo.toString());
   int dist = rc.getLocation().distanceSquaredTo(whereToGo);
   if (dist > 0 && rc.isActive()) {
     Direction toTarget = rc.getLocation().directionTo(whereToGo);
     int[] directionOffsets = {0, 1, -1, 2, -2};
     Direction move;
     MapLocation ahead;
     for (int offset : directionOffsets) {
       move = Direction.values()[(toTarget.ordinal() + offset + 8) % 8];
       ahead = rc.getLocation().add(move);
       Team mine = rc.senseMine(ahead);
       int move_num = move.ordinal();
       if (rc.canMove(move)
           && (mine == rc.getTeam() || mine == null)
           && move_num != (previousMove + 4) % 8) {
         previousMove = move_num;
         rc.move(move);
         return;
       }
     }
     previousMove = -1;
     if (rc.canMove(toTarget) || rc.senseMine(rc.getLocation()) == rc.getTeam()) {
       moveOrDefuse(toTarget);
     }
   }
 }
Example #7
0
  protected ArrayList<MapLocation> createDividedSquarePerimNodes(int searchRange)
      throws GameActionException {
    ArrayList<MapLocation> answer = new ArrayList<MapLocation>();

    if (searchRange <= 0) {
      answer.add(rc.getLocation()); // zero range is yourself
    } else {
      int additive = 2 * ((int) (robotSenseRadius * Math.sqrt(2)) - 1) - 1;
      MapLocation prevPt = new MapLocation(Integer.MIN_VALUE, Integer.MIN_VALUE);
      for (int x = -searchRange; x <= searchRange; x += additive) {
        for (int y = -searchRange; y <= searchRange; y += additive) {
          if (x == -searchRange
              || y == -searchRange
              || x + additive >= searchRange
              || y + additive >= searchRange) {
            MapLocation test = temperLocation(rc.getLocation().add(x, y));
            if (test.distanceSquaredTo(prevPt)
                > rc.getType().sensorRadiusSquared
                    / 2) { // Only add points if it is further than half away?
              // //test.distanceSquaredTo(prevPt) > rc.getType().sensorRadiusSquared/2
              // &&
              answer.add(rc.getLocation().add(x, y));
            }
          }
        }
      }
    }
    for (int n = 0; n < answer.size(); n++) { // This way the direction comparator works properly
      answer.set(n, temperLocation(answer.get(n)));
    }

    Utility.removeMapLocDuplicate(answer); // Remove duplicates
    return answer;
  }
Example #8
0
  static void runAttacker(RobotController rc, int squad) throws GameActionException {

    Team team = rc.getTeam();
    Team enemy = team.opponent();

    int squadInfo = rc.readBroadcast(squad);
    MapLocation target = Conversion.intToMapLocation(squadInfo);
    MapLocation curr = rc.getLocation();

    Robot[] allies =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().attackRadiusMaxSquared * 2, team);

    // First steps away from home HQ
    if (curr.distanceSquaredTo(rc.senseHQLocation()) < 25) Move.tryToMove(rc);

    // attack!
    Robot[] enemyRobots =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().sensorRadiusSquared * 2, enemy);
    MapLocation eloc = Attack.nearestEnemyLoc(rc, enemyRobots, rc.getLocation());

    if (eloc != null) {
      if (rc.isActive()) Move.moveToward(rc, eloc);
      if (rc.isActive() && rc.canAttackSquare(eloc)) rc.attackSquare(eloc);
    }

    // Go to right place
    if (curr.distanceSquaredTo(target) > 7) {
      // System.out.println(target + " target " + allies.length + "ally length");
      Move.moveTo(rc, target);
    }
  }
  private static void goToLocation(MapLocation whereToGo) throws GameActionException {

    //		if (rc.isActive()) {
    //			if(encampmentLocationArray == null){ // find encampments
    //				encampmentLocationArray = rc.senseAllEncampmentSquares();
    //			}
    //			if (counter < 10 && rc.senseMine(rc.getLocation()) == null) { // lay mines behind robots
    //				if(rc.senseMine(rc.getLocation())==null)
    //					rc.layMine();

    // Send all robots to the passed in argument.
    int dist = rc.getLocation().distanceSquaredTo(whereToGo);
    if (dist > 0) { // dist > 0 && rc.isActive()
      Direction dir = rc.getLocation().directionTo(whereToGo);
      Direction curDir = dir;

      int[] directionOffSets = {0, 1, -1, 2, -2};

      lookForDir:
      for (int d : directionOffSets) {
        curDir = Direction.values()[(dir.ordinal() + d + 8) % 8];
        if (rc.canMove(curDir)) {
          break lookForDir;
        }
      }
      Team mine = rc.senseMine(rc.getLocation().add(curDir));
      if (mine != null && mine != rc.getTeam()) {
        rc.defuseMine(rc.getLocation().add(curDir));
      } else {
        rc.move(curDir);
        rc.setIndicatorString(0, "Last direction moved: " + dir.toString());
      }
    }
  }
Example #10
0
 /**
  * Follow the waypoint stored in currentWaypoint
  *
  * @param defuseMines whether or not to defuse mines while following waypoints
  * @throws GameActionException
  */
 public static void followWaypoints(boolean defuseMines, boolean swarm)
     throws GameActionException {
   // If we're close to currentWaypoint, find the next one
   if (rc.getLocation().distanceSquaredTo(destination) <= Constants.PATH_GO_ALL_IN_SQ_RADIUS) {
     // Stop nav-ing?
     navMode = NavMode.REGULAR;
     // We're done following waypoints
     if (defuseMines) {
       goToLocation(destination);
     } else {
       goToLocationAvoidMines(destination);
     }
   } else if (rc.getLocation().distanceSquaredTo(currentWaypoint)
       <= Constants.WAYPOINT_SQUARED_DISTANCE_CHECK) {
     // We're close to currentWaypoint, so find the next one
     switch (navMode) {
       case SMART:
         getSmartWaypoint();
         break;
       case BACKDOOR:
         getBackdoorWaypoint();
         break;
       default:
         break;
     }
     if (defuseMines) {
       if (swarm) {
         //					rc.setIndicatorString(2, currentWaypoint.toString());
         goToLocationSwarm(currentWaypoint, true);
       } else {
         goToLocation(currentWaypoint);
       }
     } else {
       if (swarm) {
         goToLocationSwarm(currentWaypoint, false);
       } else {
         goToLocationAvoidMines(currentWaypoint);
       }
     }
   } else {
     // Keep moving to the current waypoint
     if (defuseMines) {
       if (swarm) {
         //					rc.setIndicatorString(2, currentWaypoint.toString());
         goToLocationSwarm(currentWaypoint, true);
       } else {
         goToLocation(currentWaypoint);
       }
     } else {
       if (swarm) {
         goToLocationSwarm(currentWaypoint, false);
       } else {
         goToLocationAvoidMines(currentWaypoint);
       }
     }
   }
 }
  public void progressMove(MapLocation whereToGo, Boolean inBattle) throws GameActionException {
    MapLocation currentLocation = rc.getLocation();
    int dist = currentLocation.distanceSquaredTo(whereToGo);

    if (dist > 0 && rc.isActive()) {
      Direction toTarget = currentLocation.directionTo(whereToGo);
      int[] directionOffsets = {-2, 2, -1, 1, 0};
      Direction potentialDirectionMovement; // direction of where we are going to move
      MapLocation newLocation;

      int offset;
      for (int i = 5; --i >= 0; ) {
        offset = directionOffsets[i];
        potentialDirectionMovement = Direction.values()[(toTarget.ordinal() + offset + 8) % 8];
        newLocation = rc.getLocation().add(potentialDirectionMovement);
        Team mineAtPotentialNewLocation = rc.senseMine(newLocation);
        if (rc.canMove(potentialDirectionMovement)
            && this.shouldMakeMoveRand(newLocation, currentLocation)
            && (mineAtPotentialNewLocation == myTeam || mineAtPotentialNewLocation == null)) {
          rc.move(potentialDirectionMovement);
          // this.previousFour[lastIndex] = currentLocation;
          // lastIndex = (lastIndex + 1)%4;
          try {
            this.mapIntDistribution[newLocation.x][newLocation.y]++;
          } catch (Exception e) {
            this.mapIntDistribution[newLocation.x][newLocation.y] = 1;
          }
          rc.setIndicatorString(0, Arrays.toString(this.previousFour));
          rc.setIndicatorString(1, "locationBeforeMove: " + currentLocation);
          rc.setIndicatorString(2, "to Target Direction: " + toTarget.toString());
          return;
        }
      }
      for (int i = 5; --i >= 0; ) {
        offset = directionOffsets[i];
        potentialDirectionMovement = Direction.values()[(toTarget.ordinal() + offset + 8) % 8];
        if (rc.canMove(potentialDirectionMovement) && !inBattle) {
          newLocation = currentLocation.add(toTarget);
          this.defuseFirstorThenMove(potentialDirectionMovement);
          // this.previousFour[lastIndex] = currentLocation;
          // lastIndex = (lastIndex + 1)%4;
          try {
            this.mapIntDistribution[newLocation.x][newLocation.y]++;
          } catch (Exception e) {
            this.mapIntDistribution[newLocation.x][newLocation.y] = 1;
          }
          rc.setIndicatorString(0, Arrays.toString(this.previousFour));
          rc.setIndicatorString(1, "locationBeforeMove: " + currentLocation);
          rc.setIndicatorString(2, "to Target Direction: " + toTarget.toString());
          return;
        }
      }
    }
  }
Example #12
0
 public void go() throws GameActionException {
   if (rc.senseParts(rc.getLocation()) > 5) {
     signalSendb.foundSomeParts(70);
   }
   moveb.visit(rc.getLocation());
   if (attackb.canChertAttack()) attackb.chertAttack();
   else {
     moveb.move(moveb.randomDirectionHasNotVisited());
   }
   reset();
 }
Example #13
0
 /**
  * If rc has no core delay, attempts to move towards the first allied archon sensed. Does not move
  * if rc is already within ARCHON_RESERVED_DISTANCE_SQUARED of the archon
  *
  * @param rc
  * @return true if rc moves else false
  * @throws GameActionException
  */
 private static void moveTowardsArchon(RobotController rc) throws GameActionException {
   RobotInfo[] nearbyRobots = rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, myTeam);
   for (int i = 0; i < nearbyRobots.length; i++) {
     if (nearbyRobots[i].type == (RobotType.ARCHON) && rc.isCoreReady()) {
       if (nearbyRobots[i].location.distanceSquaredTo(rc.getLocation())
           > ARCHON_RESERVED_DISTANCE_SQUARED) {
         Direction dir = rc.getLocation().directionTo(nearbyRobots[i].location);
         moveTowards(rc, dir);
       }
     }
   }
 }
Example #14
0
  static void runDefender(RobotController rc, int squad) throws GameActionException {
    Team team = rc.getTeam();
    Team enemy = team.opponent();

    int squadInfo = rc.readBroadcast(squad);
    MapLocation target = Conversion.intToMapLocation(squadInfo);
    MapLocation curr = rc.getLocation();

    int status = rc.readBroadcast(squad + 1);
    int PASTRstatus = Channels.NTPASTRDecoding(status)[1];
    int NTstatus = Channels.NTPASTRDecoding(status)[0];

    Robot[] allies =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().attackRadiusMaxSquared * 2, team);

    // Create a PASTR/NT if not already there

    // System.out.println(allies.length + " " + rc.readBroadcast(Channels.numAlliesNeededChannel));
    if (allies.length >= rc.readBroadcast(Channels.numAlliesNeededChannel)
        && curr.distanceSquaredTo(target) < distanceThreshold
        && rc.isActive()) {
      if (PASTRstatus == 0) {
        rc.construct(RobotType.PASTR);
        rc.broadcast(squad + 1, Channels.NTPASTREncoding(NTstatus, 1));
        System.out.println("Constructing a PASTR...");

      } else if (NTstatus == 0) {
        rc.construct(RobotType.NOISETOWER);
        rc.broadcast(squad + 1, Channels.NTPASTREncoding(1, PASTRstatus));
        System.out.println("Constructing a NT...");
      }
    }

    // Then go to right place
    if (curr.distanceSquaredTo(target) > 8) Move.moveTo(rc, target);

    // Then attack!
    Robot[] enemyRobots =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().sensorRadiusSquared * 2, enemy);
    MapLocation eloc = Attack.nearestEnemyLoc(rc, enemyRobots, rc.getLocation());

    if (eloc != null) {
      if (rc.isActive()) Move.moveToward(rc, eloc);
      if (rc.isActive() && rc.canAttackSquare(eloc)) rc.attackSquare(eloc);
    }

    // If there is a pastr and noisetower, don't block them!
    if (PASTRstatus == 1 && NTstatus == 1) {
      if (enemyRobots.length == 0 && rc.senseCowsAtLocation(rc.getLocation()) > 30) {
        Move.tryToSneak(rc);
      }
    }
  }
Example #15
0
 public static boolean getToAdjParts(RobotController rc) throws GameActionException {
   if (rc.isCoreReady()) {
     MapLocation myLoc = rc.getLocation();
     MapLocation[] squaresAdj = MapLocation.getAllMapLocationsWithinRadiusSq(rc.getLocation(), 2);
     for (MapLocation sq : squaresAdj) {
       if ((rc.senseParts(sq) > 0) && (rc.canMove(myLoc.directionTo(sq)))) {
         rc.move(myLoc.directionTo(sq));
         return true;
       }
     }
   }
   return false;
 }
Example #16
0
 /**
  * @param rc
  * @return true if rc moves else false
  * @throws GameActionException
  */
 private static void moveTowardsNearestEnemy(RobotController rc) throws GameActionException {
   List<RobotInfo> enemies = Arrays.asList(rc.senseHostileRobots(rc.getLocation(), -1));
   Optional<RobotInfo> nearestEnemy =
       enemies
           .stream()
           .min(
               (enemy1, enemy2) ->
                   rc.getLocation().distanceSquaredTo(enemy1.location)
                       - rc.getLocation().distanceSquaredTo(enemy2.location));
   if (nearestEnemy.isPresent() && rc.isCoreReady()) {
     moveTowards(rc, rc.getLocation().directionTo(nearestEnemy.get().location));
   }
 }
Example #17
0
  public static boolean turnNuke(RobotController rc) {
    boolean nuke = false;

    GameObject[] nearByEnemies =
        rc.senseNearbyGameObjects(Robot.class, 35, rc.getTeam().opponent());
    GameObject[] nearByFriends;

    if (nearByEnemies.length == 0) {

    } else {
      MapLocation[] nearBySpots = new MapLocation[8];

      Direction dir = rc.getLocation().directionTo(rc.senseHQLocation());

      for (int i = 0; i < nearBySpots.length; i++) {
        nearBySpots[i] = rc.getLocation().add(dir);
        dir.rotateLeft();
      }

      int[] damage = new int[8];

      for (int i = 0; i < damage.length; i++) {
        nearByEnemies =
            rc.senseNearbyGameObjects(Robot.class, nearBySpots[i], 2, rc.getTeam().opponent());
        nearByFriends = rc.senseNearbyGameObjects(Robot.class, nearBySpots[i], 2, rc.getTeam());

        int total = nearByEnemies.length - nearByFriends.length;
        damage[i] = total;
      }

      int largest = damage[0];
      int index = 0;

      for (int k = 1; k < damage.length; k++) {
        if (largest < damage[k]) {
          largest = damage[k];
          index = k;
        }
      }

      if (largest > 1) {
        // Nuke nuker = new Nuke(rc, nearBySpots[index]);
        // nuker.run();
        return true;
      } else {
        return false;
      }
    }
    return nuke;
  }
Example #18
0
 /**
  * Moves to a square that is closer to the goal returns true if was able to move, false otherwise
  *
  * @param goalLoc
  * @return
  * @throws GameActionException
  */
 public static boolean moveCloser() throws GameActionException {
   // first try to get closer
   double distance = rc.getLocation().distanceSquaredTo(destination);
   for (int i = 8; --i >= 0; ) {
     if (rc.canMove(DataCache.directionArray[i])) {
       MapLocation nextLoc = rc.getLocation().add(DataCache.directionArray[i]);
       if (nextLoc.distanceSquaredTo(destination) < distance) {
         NavSystem.moveOrDefuse(DataCache.directionArray[i]);
         return true;
       }
     }
   }
   return false;
 }
Example #19
0
 /**
  * If rc finds a zombie den, it signals out to surrounding robots If rc has no weapon delay,
  * attacks in the following priority: 1) adjacent robots (if robot is a bigzombie or standard
  * zombie move away every other turn to kite it) 2) big zombies 3) nearest enemy
  *
  * @param rc RobotController which will attack
  * @param RobotController
  * @throws GameActionException
  * @return true if this robot attacked else false
  */
 private static void attackFirst(RobotController rc) throws GameActionException {
   boolean equalHealth = true;
   int lowestHealthIndex = -1;
   int lowestDistanceIndex = -1;
   int attackIndex = -1;
   RobotInfo[] enemies = rc.senseHostileRobots(rc.getLocation(), rc.getType().attackRadiusSquared);
   if (rc.isWeaponReady() && enemies.length > 0) {
     for (int i = 0; i < enemies.length; i++) {
       if (enemies[i].type == RobotType.ZOMBIEDEN) {
         rc.broadcastSignal(rc.getType().sensorRadiusSquared * 2);
       }
       if (attackIndex < 0 && (rc.getLocation()).isAdjacentTo(enemies[i].location)) {
         attackIndex = i;
         // TODO test this part - work on kiting
         if ((enemies[i].type == RobotType.BIGZOMBIE
                 || enemies[i].type == RobotType.STANDARDZOMBIE)
             && rc.getRoundNum() % 2 == 0
             && rc.isCoreReady()) {
           moveAwayFromEnemy(rc, rc.getLocation().directionTo(enemies[i].location));
         }
         if (rc.isWeaponReady()) {
           rc.attackLocation(enemies[i].location);
         }
       }
       if (rc.isWeaponReady() && enemies[i].type == RobotType.BIGZOMBIE) {
         attackIndex = i;
         rc.attackLocation(enemies[i].location);
       }
       if (attackIndex < 0) {
         lowestHealthIndex = lowestHealthIndex < 0 ? 0 : lowestHealthIndex;
         lowestDistanceIndex = lowestDistanceIndex < 0 ? 0 : lowestDistanceIndex;
         equalHealth = equalHealth && enemies[i].health == enemies[lowestHealthIndex].health;
         lowestDistanceIndex =
             rc.getLocation().distanceSquaredTo(enemies[i].location)
                     < rc.getLocation().distanceSquaredTo(enemies[lowestDistanceIndex].location)
                 ? i
                 : lowestDistanceIndex;
         lowestHealthIndex =
             enemies[i].health < enemies[lowestHealthIndex].health ? i : lowestHealthIndex;
       }
     }
     if (attackIndex < 0 && enemies.length > 0) {
       attackIndex = equalHealth ? lowestDistanceIndex : lowestHealthIndex;
     }
     if (attackIndex >= 0 && rc.isWeaponReady()) {
       rc.attackLocation(enemies[attackIndex].location);
     }
   }
 }
Example #20
0
 public static boolean moveOrDefuse(Direction dir) throws GameActionException {
   if (rc.isActive()) {
     if (rc.canMove(dir)) {
       if (!hasBadMine(rc.getLocation().add(dir))) {
         rc.move(dir);
         return true;
       } else {
         rc.defuseMine(rc.getLocation().add(dir));
         return false;
       }
     }
     return false;
   }
   return false;
 }
Example #21
0
 private static void moveFromCorner(RobotController rc) throws GameActionException {
   int minRadius = 9; // units should try to maintain a minimum of 5 squared units
   // away from corner
   // @Hope - refine max radius
   int maxRadius = 26 + (int) Math.pow(rc.getRobotCount() / 6, 2); // based of number
   // of troops the max radius increases
   int distanceToCorner = rc.getLocation().distanceSquaredTo(turtleCorner);
   if (distanceToCorner <= minRadius && rc.isCoreReady()) {
     Direction dir = (rc.getLocation().directionTo(turtleCorner)).opposite();
     moveTowards(rc, dir);
   }
   if (distanceToCorner >= maxRadius && rc.isCoreReady()) {
     moveTowards(rc, rc.getLocation().directionTo(turtleCorner));
   }
 }
Example #22
0
  private static void expand() throws GameActionException {
    // rallyPoint = findClosestLocation(rc.senseAllEncampmentSquares());
    if (!localscan) {
      rallyPoint = findClosestEmptyCamp();
    }
    if (rc.getLocation().distanceSquaredTo(rallyPoint)
        < 1) // if we are at the location of the rally point
    {
      if (!localscan) {
        rallyPoint = findFurthestLocalCamp();
        localscan = true;
      }
    }
    if (rc.getLocation().distanceSquaredTo(rallyPoint)
        < 1) // if we are at the location of the rally point
    {

      if (rc.isActive()) // if we are allowed to capture
      {
        if (rc.senseCaptureCost() + 1.8 * getNumberOfAlliedRobosAfterMe()
            < rc.getTeamPower()) // if we have enough power to capture
        {
          int readIn = rc.readBroadcast(Constants.campChannel);
          if (readIn == Constants.campGen) {
            rc.broadcast(Constants.campChannel, Constants.campGenInProduction);
            rc.captureEncampment(RobotType.GENERATOR);
          } else if (readIn == Constants.campGenInProduction) {
            rc.captureEncampment(RobotType.SUPPLIER);
          } else if (readIn == Constants.campSupplier) {
            rc.captureEncampment(RobotType.SUPPLIER);
          } else // TODO: transmissions may be being scrambled, for now just make supplier
          {
            rc.captureEncampment(RobotType.SUPPLIER);
          }
        }
      }
    } else if (rc.senseNearbyGameObjects(Robot.class, rallyPoint, 0, rc.getTeam()).length
        > 0) // if there is an allied robot on our rally point
    {
      rallyPoint = findClosestEmptyCamp();
      if (rallyPoint == null) {
        rallyPoint = findRallyPoint();
      }
      goToLocation(rallyPoint);
    } else {
      goToLocation(rallyPoint);
    }
  }
  /* (non-Javadoc)
   * @see team001.robots.BasePlayer#attackEnemy(battlecode.common.MapLocation)
   */
  @Override
  public boolean enemyInSight(MapLocation enemyLocation) {

    try {
      if (rc.isActive()) {
        if (rc.getLocation().distanceSquaredTo(enemyLocation)
            < Constants.MINIMUM_ENEMY_VISIBLE_RANGE) {
          rc.setIndicatorString(1, "I see enemy robot at " + enemyLocation);
          Message enemyat = new Message();
          enemyat.setLocation(enemyLocation);
          enemyat.setMessageType(MessageType.ENEMYAT);
          enemyat.setRobotID(Constants.BROADCAST_CHANNEL);
          sendMessage(enemyat);
          rc.attackSquare(enemyLocation);
          return true;
        } else {
          return false;
        }
      } else {
        rc.yield();
      }

    } catch (GameActionException e) {
      e.printStackTrace();
    }
    return false;
  }
  private RobotInfo getBestEnemyToAttackFromEnemies(
      final RobotController robotController, final RobotInfo[] enemies) {

    MapLocation currentLocaiton = robotController.getLocation();
    RobotInfo bestEnemy = null;
    for (int i = 0; i < enemies.length; i++) {

      final RobotInfo enemy = enemies[i];
      if (currentLocaiton.distanceSquaredTo(enemy.location) < GameConstants.TURRET_MINIMUM_RANGE) {

        continue;
      }
      if (bestEnemy == null) {

        bestEnemy = enemy;
        continue;
      }
      if (enemy.type != RobotType.ZOMBIEDEN && bestEnemy.type == RobotType.ZOMBIEDEN) {

        bestEnemy = enemy;
        continue;
      }
      if (enemy.type == RobotType.ZOMBIEDEN && bestEnemy.type != RobotType.ZOMBIEDEN) {

        continue;
      }
      if (enemy.health < bestEnemy.health) {

        bestEnemy = enemy;
        continue;
      }
    }
    return bestEnemy;
  }
 public static void setRetreatingStatus(RobotController rc, RobotInfo[] hostiles)
     throws GameActionException {
   // Retreating is when your first hit less than a third health or when you were retreating
   // already and is not max health yet.
   // But you should not be retreating if you are infected. That's not a good idea!
   healing =
       (3 * rc.getHealth() < RobotType.SOLDIER.maxHealth
               || (wasHealing && rc.getHealth() < RobotType.SOLDIER.maxHealth))
           && (rc.getHealth() > 2 * rc.getViperInfectedTurns());
   if (!healing) {
     if (wasHealing) bugging = null;
     wasHealing = false;
   }
   if (healing) {
     RobotInfo[] nearbyRobots = rc.senseNearbyRobots(sightRadius, myTeam);
     for (RobotInfo r : nearbyRobots) {
       if (r.type == RobotType.ARCHON) nearestArchonLocation = r.location;
     }
     rc.setIndicatorString(0, "should be retreating " + nearestArchonLocation + rc.getRoundNum());
     if (!wasHealing || !bugging.destination.equals(nearestArchonLocation)) {
       if (nearestArchonLocation == null) {
         bugging = new Bugging(rc, rc.getLocation().add(Direction.EAST));
       } else {
         bugging = new Bugging(rc, nearestArchonLocation);
       }
     }
     wasHealing = true;
   }
 }
Example #26
0
 public static void goToLocationDontDefuseOrAvoidMines(MapLocation location)
     throws GameActionException {
   Direction dir = rc.getLocation().directionTo(location);
   if (dir != Direction.OMNI) {
     goDirectionAvoidMines(dir);
   }
 }
Example #27
0
 private static void turret(RobotController rc) {
   // do one time things here
   turtleCorner = turtleCorner == null ? LOCATION_NONE : turtleCorner;
   try {
     RobotInfo[] friendlyRobots =
         rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam());
     if (rc.getHealth() <= 3 && rc.isInfected() && friendlyRobots.length > 0) {
       rc.disintegrate();
     }
     turretAttack(rc);
     processFighterSignals(rc);
     if ((archonIsTooClose(rc) || isAdjacentToWall(rc))
         && rc.getType() == RobotType.TURRET
         && rc.isCoreReady()) {
       rc.pack();
     }
     if (turtleCorner != LOCATION_NONE && rc.isCoreReady() && rc.getType() == RobotType.TURRET) {
       int minCornerRadius = (20 + (rc.getRobotCount() / 10));
       if (rc.getLocation().distanceSquaredTo(turtleCorner) < minCornerRadius) {
         rc.pack();
       }
     }
     rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
     rc.setIndicatorString(1, "I am a turret");
     // if (turtleCorner.equals(LOCATION_NONE)) tryToLocateCorner(rc);
     Clock.yield();
   } catch (GameActionException e) {
     e.printStackTrace();
   }
 }
Example #28
0
  /**
   * Archon checks within a squared radius of 9 for neutral units. If neutral archon, always head
   * toward and activate. If no neutral archons are detected, activate adjacent units. If no
   * adjacent units, move towards nearest neutral unit.
   *
   * @param rc must be archon
   * @return if activated a unit
   * @throws GameActionException
   */
  private static void activateUnits(RobotController rc) throws GameActionException {

    if (rc.isCoreReady()) activateFirst(rc);
    int lowestDistanceIndex = 0;
    MapLocation myLocation = rc.getLocation();
    MapLocation robotLocation;
    RobotInfo[] robots = rc.senseNearbyRobots(ACTIVATION_RADIUS_SQUARED, Team.NEUTRAL);
    for (int i = 0; i < robots.length; i++) {
      robotLocation = robots[i].location;
      if (rc.isCoreReady() && robots[i].type == RobotType.ARCHON) {
        if (myLocation.isAdjacentTo(robotLocation)) {
          rc.activate(robotLocation);
        } else {
          moveTowards(rc, myLocation.directionTo(robotLocation));
        }
      }
      if (robots[i].type != RobotType.ARCHON) {
        lowestDistanceIndex =
            myLocation.distanceSquaredTo(robotLocation)
                    < myLocation.distanceSquaredTo(robots[lowestDistanceIndex].location)
                ? i
                : lowestDistanceIndex;
      }
    }
    if (rc.isCoreReady() && robots.length > 0) {
      if (myLocation.isAdjacentTo(robots[lowestDistanceIndex].location)) {
        rc.activate(robots[lowestDistanceIndex].location);
      } else {
        moveTowards(rc, myLocation.directionTo(robots[lowestDistanceIndex].location));
      }
    }
  }
Example #29
0
 static void updateMap(RobotController rc) throws GameActionException {
   MapLocation loc = rc.getLocation();
   if (xMin == MAP_NONE && !rc.onTheMap(loc.add(-straightSight, 0))) {
     int x = -straightSight;
     while (!rc.onTheMap(loc.add(++x, 0))) ;
     xMin = loc.x + x;
     xMax = twiceCenterX - xMin;
     sendBoundariesLow = true;
     mapBoundUpdate = true;
   }
   if (xMax == MAP_NONE && !rc.onTheMap(loc.add(straightSight, 0))) {
     int x = straightSight;
     while (!rc.onTheMap(loc.add(--x, 0))) ;
     xMax = loc.x + x;
     xMin = twiceCenterX - xMax;
     sendBoundariesHigh = true;
     mapBoundUpdate = true;
   }
   if (yMin == MAP_NONE && !rc.onTheMap(loc.add(0, -straightSight))) {
     int y = -straightSight;
     while (!rc.onTheMap(loc.add(0, ++y))) ;
     yMin = loc.y + y;
     sendBoundariesLow = true;
     mapBoundUpdate = true;
   }
   if (yMax == MAP_NONE && !rc.onTheMap(loc.add(0, straightSight))) {
     int y = straightSight;
     while (!rc.onTheMap(loc.add(0, --y))) ;
     yMax = loc.y + y;
     sendBoundariesHigh = true;
     mapBoundUpdate = true;
   }
 }
 public static void hqCode() throws GameActionException {
   if (rc.isActive()) {
     // Spawn a soldier
     Direction dir = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
     if (rc.canMove(dir)) rc.spawn(dir);
   }
 }