예제 #1
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());
     }
   }
 }
예제 #2
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();
   }
 }
예제 #3
0
 /**
  * Working on soldier behavior: 1) If about to die and infected and senses nearby friendly robots,
  * self destruct 2) Attack if possible 3) Process signals. (If another soldier signals, move
  * towards that soldier (means there is a zombie den nearby)) 4) Move away from walls / archons 5)
  * Use position and relative position to turtle corner to move away or toward turtle corner 6) Try
  * to clear surrounding rubble
  *
  * @param rc
  */
 private static void soldier(RobotController rc) {
   turtleCorner = LOCATION_NONE;
   while (true) {
     try {
       // 1)
       RobotInfo[] friendlyRobots =
           rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam());
       if (rc.getHealth() <= 3 && rc.isInfected() && friendlyRobots.length > 0) {
         rc.disintegrate();
       } else {
         // 2)
         attackFirst(rc);
         // 3)
         processFighterSignals(rc);
         // 4)
         moveAwayFromArchons(rc);
         moveAwayFromWalls(rc);
         // 5)
         if (!turtleCorner.equals(LOCATION_NONE)) {
           moveFromCorner(rc);
         } else if (currentMode == TRANSITION_MODE) {
           moveTowardsArchon(rc);
         }
         // 6)
         clearRubble(rc);
         //					if(turtleCorner.equals(LOCATION_NONE)) tryToLocateCorner(rc);
       }
       rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
       rc.setIndicatorString(1, "Current Mode" + currentMode);
       Clock.yield();
     } catch (GameActionException e) {
       e.printStackTrace();
     }
   }
 }
예제 #4
0
 private static void broadcastCollectibles(RobotController rc, boolean thereAreEnemies)
     throws GameActionException {
   MapLocation[] parts = rc.sensePartLocations(sightRange);
   RobotInfo[] neutrals = rc.senseNearbyRobots(sightRange, Team.NEUTRAL);
   MapLocation closestCollectible = null;
   int closestDist = 10000;
   for (MapLocation part : parts) {
     if (previouslyBroadcastedPartLoc != null) {
       if (part.distanceSquaredTo(previouslyBroadcastedPartLoc) <= 35) continue;
     }
     int dist = myLoc.distanceSquaredTo(part);
     if (dist < closestDist) {
       closestDist = dist;
       closestCollectible = part;
     }
   }
   for (RobotInfo neutral : neutrals) {
     if (previouslyBroadcastedPartLoc != null) {
       if (neutral.location.distanceSquaredTo(previouslyBroadcastedPartLoc) <= 35) continue;
     }
     int dist = myLoc.distanceSquaredTo(neutral.location);
     if (dist < closestDist) {
       closestDist = dist;
       closestCollectible = neutral.location;
     }
   }
   if (closestCollectible != null && rc.isCoreReady()) {
     if (thereAreEnemies) {
       Message.sendMessageGivenDelay(rc, closestCollectible, Message.COLLECTIBLES, 0.3);
     } else {
       Message.sendMessageGivenDelay(rc, closestCollectible, Message.COLLECTIBLES, 8.65);
     }
     previouslyBroadcastedPartLoc = closestCollectible;
   }
 }
예제 #5
0
 /**
  * 1) process signals, try to find turtleCorner 2) if enemies are within sensing radius, unpack 3)
  * if too close to archons, move away 4) if too close to wall, move away 5) if too close to
  * corner, move away 6) if it did nothing, unpack
  *
  * @param rc
  */
 private static void ttm(RobotController rc) {
   turtleCorner = turtleCorner.equals(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();
     }
     // 1)
     if (isNearbyEnemies(rc) && rc.isCoreReady()) {
       rc.unpack();
     }
     // 2)
     processFighterSignals(rc);
     // 3)
     moveAwayFromArchons(rc);
     // 4)
     moveAwayFromWalls(rc);
     // 5)
     if (turtleCorner != LOCATION_NONE) moveFromCorner(rc);
     // 6)
     if (rc.isCoreReady() && rc.getType() == RobotType.TTM && rc.getRoundNum() % 25 == 0)
       rc.unpack();
     rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
     rc.setIndicatorString(1, "I am a TTM!");
     Clock.yield();
   } catch (GameActionException e) {
     e.printStackTrace();
   }
 }
예제 #6
0
 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;
   }
 }
예제 #7
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));
      }
    }
  }
예제 #8
0
  public static void enemyMicro(RobotController rc, RobotInfo bestEnemy)
      throws GameActionException {
    // Prioritize movement
    Direction d = myLoc.directionTo(bestEnemy.location);
    if (rc.isCoreReady()) {
      if (rc.getHealth() > (numEnemySoldiers + 1) * RobotType.SOLDIER.attackPower) {
        // If the enemy can be killed but we're not in range, move forward
        if (!rc.canAttackLocation(bestEnemy.location)
            && bestEnemy.health <= RobotType.SOLDIER.attackPower) {
          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());
          }
          // If not in range, see if we should move in by comparing soldier health
        } else {
          double totalOurSoldierHealth = 0;
          RobotInfo[] allies = rc.senseNearbyRobots(bestEnemy.location, 18, rc.getTeam());
          for (RobotInfo ally : allies) {
            if (ally.type == RobotType.SOLDIER) {
              if (ally.health > numEnemySoldiers * RobotType.SOLDIER.attackPower) {
                totalOurSoldierHealth += ally.health;
              }
            }
          }
          // If we feel that we are strong enough, rush in.
          if (totalOurSoldierHealth > totalEnemySoldierHealth) {
            if (!rc.canAttackLocation(bestEnemy.location)) {
              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());
              }
            }
          } else if (4 * totalOurSoldierHealth < 3 * totalEnemySoldierHealth) {
            if (rc.canMove(d.opposite())) {
              rc.move(d.opposite());
            } else if (rc.canMove(d.opposite().rotateLeft())) {
              rc.move(d.opposite().rotateLeft());
            } else if (rc.canMove(d.opposite().rotateRight())) {
              rc.move(d.opposite().rotateRight());
            }
          }
        }
      }
    }

    // Attack whenever you can
    if (rc.isWeaponReady()) {
      if (rc.canAttackLocation(bestEnemy.location)) {
        broadcastingAttack(rc, bestEnemy);
      }
    }
  }
예제 #9
0
 /**
  * Repairs the first-sensed neutral robot, if rc's core is ready
  *
  * @param rc must be an archon
  * @throws GameActionException
  */
 private static boolean activateFirst(RobotController rc) throws GameActionException {
   boolean hasActed = false;
   RobotInfo[] nearbyNeutralRobots = rc.senseNearbyRobots(ONE_SQUARE_RADIUS, Team.NEUTRAL);
   if (nearbyNeutralRobots.length > 0) {
     rc.activate(nearbyNeutralRobots[0].location);
     hasActed = true;
   }
   return hasActed;
 }
예제 #10
0
 /**
  * Repairs the first-sensed, injured, allied robot
  *
  * @param rc must be an archon
  * @throws GameActionException
  */
 private static void repairFirst(RobotController rc) throws GameActionException {
   RobotInfo[] allies = rc.senseNearbyRobots(rc.getType().attackRadiusSquared, myTeam);
   for (int i = 0; i < allies.length; i++) {
     if (allies[i].health < allies[i].maxHealth
         && !allies[i].type.equals(RobotType.ARCHON)) { // can't repair other archons
       rc.repair(allies[i].location);
       break;
     }
   }
 }
예제 #11
0
 @Override
 public boolean runInner(RobotController rc) throws GameActionException {
   if (rc.getRoundNum() == Common.enrollment) {
     target = new Target(Common.enemyBase);
     target.weights.put(Target.TargetType.ZOMBIE_ATTACK, Target.TargetType.Level.INACTIVE);
     Common.models.addFirst(target);
   }
   move(rc);
   attack(rc, rc.senseNearbyRobots(Common.sightRadius, Common.enemyTeam));
   return false;
 }
예제 #12
0
  protected void gatherMapInfo() throws GameActionException {
    // rc.setIndicatorString(0, "Sensing");
    RobotInfo[] enemyRobotsInRange =
        rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, Team.ZOMBIE);
    for (int n = 0; n < enemyRobotsInRange.length; n++) {
      if (enemyRobotsInRange[n].type == RobotType.ZOMBIEDEN) {
        memory.addMapInfo(
            enemyRobotsInRange[n].location,
            (int) enemyRobotsInRange[n].health,
            RobotConstants.mapTypes.ZOMBIE_DEN);
      }
    }

    RobotInfo[] neutralRobotsInRange =
        rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, Team.NEUTRAL);
    for (int n = 0; n < neutralRobotsInRange.length; n++) {
      memory.addNeutralRobotMapInfo(neutralRobotsInRange[n].location, neutralRobotsInRange[n]);
    }

    MapLocation[] partsLoc = rc.sensePartLocations(rc.getType().sensorRadiusSquared);
    for (int n = 0; n < partsLoc.length; n++) {
      memory.addMapInfo(
          partsLoc[n], (int) rc.senseParts(partsLoc[n]), RobotConstants.mapTypes.PARTS);
    }

    for (int x = -robotSenseRadius / (int) Math.sqrt(2) + rc.getLocation().x;
        x < robotSenseRadius / (int) Math.sqrt(2) + rc.getLocation().x;
        x++) {
      for (int y = -robotSenseRadius / (int) Math.sqrt(2) + rc.getLocation().y;
          y < robotSenseRadius / (int) Math.sqrt(2) + rc.getLocation().y;
          y++) {
        MapLocation underView = new MapLocation(x, y);
        if (rc.canSense(underView) && rc.onTheMap(underView)) {
          int rubbles = (int) rc.senseRubble(underView);
          if (rubbles > 0) {
            memory.addMapInfo(underView, rubbles, RobotConstants.mapTypes.RUBBLE);
          }
        }
      }
    }
  }
예제 #13
0
 private static void moveAwayFromEnemies(RobotController rc) throws GameActionException {
   // TODO might want a different value for how far you sense enemies and
   // do a "center of mass" of enemies weighted by their attack values then
   // move away from that?
   RobotInfo[] enemies = rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, myTeam.opponent());
   for (int i = 0; i < enemies.length; i++) {
     if (rc.isCoreReady()) {
       Direction awayFrom = rc.getLocation().directionTo(enemies[0].location).opposite();
       moveTowards(rc, awayFrom);
     }
   }
 }
예제 #14
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);
       }
     }
   }
 }
예제 #15
0
 /*
  * Drones without supply head back to the HQ
  * Drones with supply head to the nearest unit without supply
  */
 private static void doSupply() {
   if (rc.getSupplyLevel() > 2000) {
     RobotInfo[] units = rc.senseNearbyRobots(Integer.MAX_VALUE, myTeam);
     for (RobotInfo r : units) {
       if (r.supplyLevel == 0 && r.type.needsSupply()) {
         tryMove(myLoc.directionTo(r.location), false);
         return;
       }
     }
   }
   tryMove(myLoc.directionTo(myHQ), false);
 }
예제 #16
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();
    }
  }
예제 #17
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();
        }
      }
    }
  }
예제 #18
0
  protected boolean simpleAttack() throws GameActionException {
    boolean attacked = false;
    if (rc.getType().canAttack()) {
      RobotInfo[] enemiesWithinRange =
          rc.senseNearbyRobots(rc.getType().attackRadiusSquared, enemyTeam);
      RobotInfo[] zombiesWithinRange =
          rc.senseNearbyRobots(rc.getType().attackRadiusSquared, Team.ZOMBIE);
      if (enemiesWithinRange.length > 0) {
        if (rc.isWeaponReady()) {
          rc.attackLocation(
              enemiesWithinRange[randall.nextInt(enemiesWithinRange.length)].location);
          attacked = true;
        }
      } else if (zombiesWithinRange.length > 0) {
        if (rc.isWeaponReady()) {
          rc.attackLocation(
              zombiesWithinRange[randall.nextInt(zombiesWithinRange.length)].location);
          attacked = true;
        }
      }
    }

    return attacked;
  }
예제 #19
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;
  }
예제 #20
0
 public static void bugAroundFriendly(RobotController rc) throws GameActionException {
   RobotInfo[] nearbyFriendlyRobots = rc.senseNearbyRobots(sightRadius, myTeam);
   if (nearbyFriendlyRobots.length > 0) {
     RobotInfo nearestFriend = null;
     for (RobotInfo r : nearbyFriendlyRobots) {
       if (r.type == RobotType.ARCHON) {
         nearestFriend = r;
       }
     }
     if (nearestFriend != null && !nearestFriend.location.equals(storedDestination)
         || bugging == null) {
       bugging = new Bugging(rc, nearestFriend.location);
       storedDestination = nearestFriend.location;
     }
     if (rc.isCoreReady()) { // don't want to get too close to archon
       bugging.move();
     }
   }
 }
예제 #21
0
 private static boolean archonIsTooClose(RobotController rc) {
   boolean tooClose = false;
   int archonReserveDistance =
       (int) (Math.sqrt(rc.getRobotCount()) * 1.4); // @Hope make this more finessed
   List<RobotInfo> robots = Arrays.asList(rc.senseNearbyRobots(archonReserveDistance + 1, myTeam));
   List<RobotInfo> archons = new ArrayList<>();
   for (RobotInfo robot : robots) {
     if (robot.type == RobotType.ARCHON) {
       archons.add(robot);
     }
   }
   MapLocation myLocation = rc.getLocation();
   for (RobotInfo archon : archons) {
     if (!tooClose && myLocation.distanceSquaredTo(archon.location) < archonReserveDistance) {
       tooClose = true;
       break;
     }
   }
   return tooClose;
 }
예제 #22
0
  // moves to parts/neutral robots in sight radius
  // returns true if there were parts/neutral robots to go to; else returns false
  public static boolean getToParts(RobotController rc) throws Exception {
    if (rc.isCoreReady()) {
      MapLocation goTo = null;
      MapLocation myLoc = rc.getLocation();
      int sightRadius = rc.getType().sensorRadiusSquared;
      MapLocation[] squaresInSight =
          MapLocation.getAllMapLocationsWithinRadiusSq(rc.getLocation(), sightRadius);
      RobotInfo[] nearbyNeutralRobots = rc.senseNearbyRobots(sightRadius, Team.NEUTRAL);

      // goes to closest parts/neutral robot
      if (nearbyNeutralRobots.length > 0) {
        goTo = nearbyNeutralRobots[0].location;
        for (RobotInfo n : nearbyNeutralRobots) {
          if (myLoc.distanceSquaredTo(n.location) < myLoc.distanceSquaredTo(goTo)) {
            goTo = n.location;
          }
        }
      }
      for (MapLocation sq : squaresInSight) {
        if ((rc.senseParts(sq) > 0) && (goTo != null)) {
          if (myLoc.distanceSquaredTo(sq) < myLoc.distanceSquaredTo(goTo)) {
            goTo = sq;
          }
        }
      }
      if (goTo != null) {
        MapLocation curLoc = rc.getLocation();
        Direction dirToGo = curLoc.directionTo(goTo);
        if (rc.canMove(dirToGo)) {
          rc.move(dirToGo);
          return true;
        } else {
          return false;
        }
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
예제 #23
0
  /**
   * Code to run every turn.
   *
   * @param rc
   */
  static void runBefore(RobotController rc) throws GameActionException {
    // -2 for build signals
    Signals.maxMessages = GameConstants.MESSAGE_SIGNALS_PER_TURN - 2;
    read = Signals.readSignals(rc);
    sent = 0;
    int turn = rc.getRoundNum();

    switch (turn - enrollment) {
      case 0:
        if (targetType != null && Signals.targetsSize > 0) {
          models.addFirst(new Target(targetType, Signals.targets[0]));
        }
        break;
      case 1:
        for (int i = 0; i < sqrt.length; ++i) sqrt[i] = Math.sqrt(i);
        break;
      case 2:
        // Sense rubble a little after construction
        // TODO: change to 3(?) to avoid overlapping with action
        senseRubble(rc);
        break;
      default:
        break;
    }

    if (canMessageSignal) {
      sendRadius = 2 * sightRadius;
      sendBoundariesLow = false;
      sendBoundariesHigh = false;
      senseParts(rc);
    }

    updateMap(rc);
    if (turn > 5) {
      robotInfos = rc.senseNearbyRobots();
      for (RobotInfo info : robotInfos) {
        addInfo(info);
      }
    }
  }
예제 #24
0
  // This method will attack the weakest enemy in sight
  static boolean attackWeakest() {
    RobotInfo[] targets = rc.senseNearbyRobots(attackRange, enemyTeam);
    if (targets.length == 0) return false;

    // Find enemy with lowest health - pick units that can damage us as a preference
    RobotInfo weakest = targets[0];
    for (RobotInfo e : targets) {
      if ((!canDamage(weakest.type) && canDamage(e.type))
          || (canDamage(weakest.type) == canDamage(e.type) && e.health < weakest.health)) {
        weakest = e;
      }
    }

    try {
      rc.attackLocation(weakest.location);
    } catch (GameActionException e) {
      System.out.println("Attack exception");
      // e.printStackTrace();
    }

    return true;
  }
예제 #25
0
  // Supply our units
  // Getting supply to the buildings producing units is cool
  private static void doTransfer() {
    double supply = rc.getSupplyLevel();
    double supplyToKeep = myType.supplyUpkeep * 10; // 10 turns worth of supply
    if (myType == RobotType.COMMANDER) supplyToKeep *= 10;
    if (supply < supplyToKeep) return;

    RobotInfo[] robots = rc.senseNearbyRobots(GameConstants.SUPPLY_TRANSFER_RADIUS_SQUARED, myTeam);
    // Pass to first neighbour with half the supply we have
    RobotInfo target = null;

    // Pick the nearest ally with the least supply
    for (RobotInfo r : robots) {
      // Never pass supply to buildings that can't spawn or to the HQ
      if (r.type == RobotType.HQ
          || r.type == RobotType.TOWER
          || r.type == RobotType.SUPPLYDEPOT
          || r.type == RobotType.HANDWASHSTATION) continue;

      // Drone will only pass to units with 0 supply
      if (myType == RobotType.DRONE && r.supplyLevel > 0) continue;

      if (target == null || r.supplyLevel < target.supplyLevel) target = r;

      if (Clock.getBytecodesLeft() < 600) break;
    }

    double toTransfer = supply - supplyToKeep;
    if (target == null || supply < target.supplyLevel * 2.0) return;

    // Keep half of what we have available unless we are the HQ
    if (target.type != RobotType.HQ) toTransfer /= 2.0;
    try {
      rc.transferSupplies((int) toTransfer, target.location);
    } catch (GameActionException e) {
      System.out.println("Supply exception");
      // e.printStackTrace();
    }
  }
예제 #26
0
  public void run(final RobotController robotController) throws GameActionException {

    final MapInfoModule mapInfoModule = new MapInfoModule();

    final CombatModule combatModule = new CombatModule();
    final CommunicationModule communicationModule = new CommunicationModule(mapInfoModule);
    final DirectionModule directionModule = new DirectionModule(robotController.getID());
    final MovementModule movementModule = new MovementModule();
    final RubbleModule rubbleModule = new RubbleModule();

    final Team currentTeam = robotController.getTeam();
    int turnsStuck = 0;

    while (true) {

      RobotType type = robotController.getType();
      MapLocation currentLocation = robotController.getLocation();

      // update communication

      communicationModule.processIncomingSignals(robotController);

      // let's verify existing information

      communicationModule.verifyCommunicationsInformation(robotController, null, false);

      if (type == RobotType.TTM) {

        // MOVE

        // let's get the best assignment

        CommunicationModuleSignal objectiveSignal = null;
        int closestObjectiveLocationDistance = Integer.MAX_VALUE;

        final Enumeration<CommunicationModuleSignal> zombieDenCommunicationModuleSignals =
            communicationModule.zombieDens.elements();
        while (zombieDenCommunicationModuleSignals.hasMoreElements()) {

          final CommunicationModuleSignal signal =
              zombieDenCommunicationModuleSignals.nextElement();
          final int distance = signal.location.distanceSquaredTo(currentLocation);
          if (distance < closestObjectiveLocationDistance) {

            objectiveSignal = signal;
            closestObjectiveLocationDistance = distance;
          }
        }

        final Enumeration<CommunicationModuleSignal> enemyArchonCommunicationModuleSignals =
            communicationModule.enemyArchons.elements();
        while (enemyArchonCommunicationModuleSignals.hasMoreElements()) {

          final CommunicationModuleSignal signal =
              enemyArchonCommunicationModuleSignals.nextElement();
          final int distance =
              signal.location.distanceSquaredTo(currentLocation)
                  * 6; // multiplying by 6 to prioritize the dens
          if (distance < closestObjectiveLocationDistance) {

            objectiveSignal = signal;
            closestObjectiveLocationDistance = distance;
          }
        }

        final Enumeration<CommunicationModuleSignal> enemyTurretCommunicationModuleSignals =
            communicationModule.enemyTurrets.elements();
        while (enemyTurretCommunicationModuleSignals.hasMoreElements()) {

          final CommunicationModuleSignal signal =
              enemyTurretCommunicationModuleSignals.nextElement();
          final int distance = signal.location.distanceSquaredTo(currentLocation) * 20;
          if (distance < closestObjectiveLocationDistance) {

            objectiveSignal = signal;
            closestObjectiveLocationDistance = distance;
          }
        }

        boolean shouldMove = true;
        Direction desiredMovementDirection = null;
        Direction targetRubbleClearanceDirection = null;

        // check to make sure we are safe

        final RobotInfo[] enemies =
            robotController.senseHostileRobots(
                currentLocation, robotController.getType().sensorRadiusSquared);

        if (robotController.isCoreReady() && enemies.length > 0) {

          final Direction fleeDirection =
              directionModule.averageDirectionTowardDangerousRobotsAndOuterBounds(
                  robotController, enemies);
          if (fleeDirection != null) {

            final Direction fleeMovementDirection =
                directionModule.recommendedMovementDirectionForDirection(
                    fleeDirection.opposite(), robotController, false);
            if (fleeMovementDirection != null) {

              robotController.move(fleeMovementDirection);
              currentLocation = robotController.getLocation();
              robotController.setIndicatorString(
                  1, fleeDirection.name() + " " + fleeMovementDirection.name());
            }
          }
        }

        // check if there are nearby signals

        if (desiredMovementDirection == null) {

          int closestSignalDistance = Integer.MAX_VALUE;
          MapLocation closestSignalLocation = null;

          final ArrayList<Signal> notifications = communicationModule.notifications;
          for (int i = 0; i < notifications.size(); i++) {

            final Signal signal = notifications.get(i);
            final int distance = currentLocation.distanceSquaredTo(signal.getLocation());
            if (distance < closestSignalDistance) {

              closestSignalDistance = distance;
              closestSignalLocation = signal.getLocation();
            }
          }
          if (closestSignalLocation != null) {

            desiredMovementDirection = currentLocation.directionTo(closestSignalLocation);
          }
        }

        // now let's try move toward an assignment

        if (robotController.isCoreReady()
            && communicationModule.initialInformationReceived
            && shouldMove) {

          // check if we have an objective

          if (desiredMovementDirection == null) {

            if (objectiveSignal != null) {

              final MapLocation objectiveLocation = objectiveSignal.location;
              if (objectiveLocation.distanceSquaredTo(currentLocation) >= 8) {

                desiredMovementDirection = currentLocation.directionTo(objectiveLocation);
              }
            }
          }

          // try move towards archon starting positions

          if (desiredMovementDirection == null) {

            int closestArchonDistance = Integer.MAX_VALUE;
            MapLocation closestArchonLocation = null;

            final MapLocation[] archonLocations =
                robotController.getInitialArchonLocations(robotController.getTeam().opponent());
            for (int i = 0; i < archonLocations.length; i++) {

              final MapLocation location = archonLocations[i];
              final int distance = currentLocation.distanceSquaredTo(location);
              if (distance < closestArchonDistance) {

                closestArchonDistance = distance;
                closestArchonLocation = location;
              }
            }
            if (closestArchonLocation != null) {

              desiredMovementDirection = currentLocation.directionTo(closestArchonLocation);
            }
          }

          // process movement

          if (desiredMovementDirection != null) {

            final Direction recommendedMovementDirection =
                directionModule.recommendedMovementDirectionForDirection(
                    desiredMovementDirection, robotController, false);
            final MapLocation recommendedMovementLocation =
                recommendedMovementDirection != null
                    ? currentLocation.add(recommendedMovementDirection)
                    : null;
            if (recommendedMovementDirection != null
                && !movementModule.isMovementLocationRepetitive(
                    recommendedMovementLocation, robotController)) {

              robotController.move(recommendedMovementDirection);
              movementModule.addMovementLocation(recommendedMovementLocation, robotController);
              currentLocation = robotController.getLocation();
              turnsStuck = 0;
            }
          }
        }

        // unpack if we're safe

        RobotInfo[] nearbyTeammates = robotController.senseNearbyRobots(8, currentTeam);
        RobotInfo[] nearbySoldiers =
            combatModule.robotsOfTypesFromRobots(
                nearbyTeammates, new RobotType[] {RobotType.SOLDIER});

        if (nearbySoldiers.length > 2) {

          robotController.unpack();
        }

      } else {

        // ATTACK

        final RobotInfo[] enemies =
            robotController.senseHostileRobots(
                currentLocation, robotController.getType().attackRadiusSquared);

        RobotInfo bestEnemy = this.getBestEnemyToAttackFromEnemies(robotController, enemies);

        // handle attacking

        if (bestEnemy != null) {

          if (robotController.isWeaponReady()) {

            // we can attack the enemy

            robotController.attackLocation(bestEnemy.location);
            if (bestEnemy.type != RobotType.ZOMBIEDEN) {

              communicationModule.broadcastSignal(
                  robotController,
                  CommunicationModule.maximumFreeBroadcastRangeForRobotType(
                      robotController.getType()));
            }
          }
        }

        // pack if we aren't near soldiers

        RobotInfo[] nearbyTeammates =
            robotController.senseNearbyRobots(type.sensorRadiusSquared, currentTeam);
        RobotInfo[] nearbySoldiers =
            combatModule.robotsOfTypesFromRobots(
                nearbyTeammates, new RobotType[] {RobotType.SOLDIER});

        if (nearbySoldiers.length < 3) {

          robotController.pack();
        }
      }

      Clock.yield();
    }
  }
예제 #27
0
  public static void run(RobotController rc) {
    Random rand = new Random(rc.getID());
    Team myTeam = rc.getTeam();
    Team enemyTeam = myTeam.opponent();
    int numFriendly = 0;
    RobotInfo[] adjNeutralRobots = rc.senseNearbyRobots(2, Team.NEUTRAL);
    // if useTurrets = true, then use turret strategy
    boolean useTurrets = false;

    try {
      // Any code here gets executed exactly once at the beginning of the game.
      RobotInfo[] nearbyArchons =
          rc.senseNearbyRobots(RobotType.ARCHON.sensorRadiusSquared, rc.getTeam());
      if (nearbyArchons.length >= 2) {
        useTurrets = true;
      }
      // rc.setIndicatorString(1, "newString");
    } catch (Exception e) {
      // Throwing an uncaught exception makes the robot die, so we need to catch exceptions.
      // Caught exceptions will result in a bytecode penalty.
      System.out.println(e.getMessage());
      e.printStackTrace();
    }

    while (true) {
      // This is a loop to prevent the run() method from returning. Because of the Clock.yield()
      // at the end of it, the loop will iterate once per game round.
      try {
        if (useTurrets) {
          boolean escape = false;
          //					if (rc.isCoreReady()) {
          //						int numAdjTurrets = 0;
          //						for (RobotInfo f : friendlyAdjacent) {
          //							if (f.type == RobotType.TURRET) {
          //								numAdjTurrets++;
          //							}
          //						}
          //						if (numAdjTurrets < 3) {
          //							escape = Movement.moveAwayFromEnemy(rc);
          //						}
          //					}
          //					if (rc.isCoreReady()) {
          //						escape = Movement.moveAwayFromEnemy(rc);
          //					}
          if (!escape) {
            if (adjNeutralRobots.length > 0) {
              // if there is a neutral robot adjacent, activate it or wait until there's no core
              // delay
              if (rc.isCoreReady()) {
                rc.activate(adjNeutralRobots[0].location);
              }
            }
            // careful- moving to parts might get into enemy turret range
            if (Movement.getToAdjParts(rc)) {
            } else {
              boolean toheal = false;
              // repair a nearby friendly robot
              if (rc.isWeaponReady()) {
                RobotInfo[] friendlyWithinRange = rc.senseNearbyRobots(24, myTeam);
                numFriendly = friendlyWithinRange.length;
                if (friendlyWithinRange.length > 0) {
                  RobotInfo toRepair = friendlyWithinRange[0];
                  for (RobotInfo r : friendlyWithinRange) {
                    if ((r.health < toRepair.health)
                        && (r.type != RobotType.ARCHON)
                        && (r.maxHealth - r.health > 1)) {
                      toRepair = r;
                    }
                  }
                  if ((toRepair.maxHealth - toRepair.health > 1)
                      && (toRepair.type != RobotType.ARCHON)) {
                    toheal = true;
                    rc.repair(toRepair.location);
                  }
                }
              }
              if (toheal == false && rc.isCoreReady()) {
                // did not heal any robots

                // sense all the hostile robots within the archon's radius
                MapLocation myLoc = rc.getLocation();
                RobotInfo[] hostileWithinRange =
                    rc.senseHostileRobots(myLoc, RobotType.ARCHON.sensorRadiusSquared);
                RobotInfo closestRobot = null;
                int closestDistance = 0;
                // get the furthest robot from the scout
                for (RobotInfo r : hostileWithinRange) {
                  if (r.location.distanceSquaredTo(myLoc) > closestDistance) {
                    closestRobot = r;
                    closestDistance = r.location.distanceSquaredTo(myLoc);
                  }
                }
                // if there is such an enemy, signal it to range 8
                if (closestRobot != null) {
                  try {
                    // this signaling is only effective against non turret enemies
                    rc.broadcastMessageSignal(closestRobot.location.x, closestRobot.location.y, 8);
                  } catch (GameActionException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }

                int turnNum = rc.getRoundNum();
                int numVeryCloseScouts = 0;
                int numNearbyTurrets = 0;
                RobotInfo[] friendlyNearby =
                    rc.senseNearbyRobots(RobotType.ARCHON.sensorRadiusSquared, myTeam);
                for (RobotInfo f : friendlyNearby) {
                  if (f.type == RobotType.TURRET) {
                    numNearbyTurrets++;
                  }
                }
                // for sensing if there are guards within range 24
                RobotInfo[] friendlyClose = rc.senseNearbyRobots(24, myTeam);
                int numNearbyGuards = 0;
                for (RobotInfo f : friendlyClose) {
                  if (f.type == RobotType.GUARD) {
                    numNearbyGuards++;
                  }
                }
                // check for scouts; how close should they be????
                RobotInfo[] friendlyVeryClose = rc.senseNearbyRobots(15, myTeam);
                for (RobotInfo f : friendlyClose) {
                  if (f.type == RobotType.SCOUT) {
                    numVeryCloseScouts++;
                  }
                }
                if (rc.hasBuildRequirements(RobotType.GUARD)
                    && rc.isCoreReady()
                    && numNearbyGuards < 1) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                  for (int i = 0; i < 8; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.GUARD)) {
                      rc.build(dirToBuild, RobotType.GUARD);
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                // if there are <1 turrets next to archon, build asap
                if (rc.hasBuildRequirements(RobotType.TURRET)
                    && rc.isCoreReady()
                    && numNearbyTurrets < 1) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(4) * 2];
                  for (int i = 0; i < 4; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.TURRET)) {
                      rc.build(dirToBuild, RobotType.TURRET);
                      turretCount++;
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                // if there are <1 scout next to archon and 1 turret, build scout asap
                if (rc.hasBuildRequirements(RobotType.SCOUT)
                    && rc.isCoreReady()
                    && numNearbyTurrets > 0
                    && numVeryCloseScouts == 0
                    && turnNum < 400) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                  for (int i = 0; i < 8; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.SCOUT)) {
                      rc.build(dirToBuild, RobotType.SCOUT);
                      scoutCount++;
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                // build turret every 100 turns until turn 400
                //								if (turnNum > 1 && turnNum < 400) {
                //									if (turnNum % 100 == 85 && rc.isCoreReady()) {
                //										Direction dirToBuild = RobotPlayer.directions[rand.nextInt(4)*2];
                //										for (int i = 0; i < 4; i++) {
                //											// If possible, build in this direction
                //											if (rc.canBuild(dirToBuild, RobotType.TURRET)) {
                //												rc.build(dirToBuild, RobotType.TURRET);
                //												turretCount++;
                //												break;
                //											} else {
                //												// Rotate the direction to try
                //												dirToBuild = dirToBuild.rotateLeft();
                //												dirToBuild = dirToBuild.rotateLeft();
                //											}
                //										}
                //									}
                //								}
                else {
                  // Check if this ARCHON's core is ready
                  if (rc.isCoreReady()) {
                    boolean built = false;
                    RobotType typeToBuild = RobotType.TURRET;
                    if (scoutCount < turretCount / 5) {
                      typeToBuild = RobotType.SCOUT;
                    }
                    // never build scouts after a certain turn
                    if (turnNum < 1500) {
                      typeToBuild = RobotType.TURRET;
                    }
                    // Check for sufficient parts
                    if (rc.hasBuildRequirements(typeToBuild)) {
                      // Choose a random direction to try to build in; NESW for turrets; all 8 for
                      // scouts
                      if (typeToBuild.equals(RobotType.TURRET)) {
                        Direction dirToBuild = RobotPlayer.directions[rand.nextInt(4) * 2];
                        for (int i = 0; i < 4; i++) {
                          // If possible, build in this direction
                          if (rc.canBuild(dirToBuild, RobotType.TURRET)) {
                            rc.build(dirToBuild, RobotType.TURRET);
                            turretCount++;
                            break;
                          } else {
                            // Rotate the direction to try
                            dirToBuild = dirToBuild.rotateLeft();
                            dirToBuild = dirToBuild.rotateLeft();
                          }
                        }
                      } else {
                        Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                        for (int i = 0; i < 8; i++) {
                          // If possible, build in this direction
                          if (rc.canBuild(dirToBuild, RobotType.SCOUT)) {
                            rc.build(dirToBuild, RobotType.SCOUT);
                            scoutCount++;
                            break;
                          } else {
                            // Rotate the direction to try
                            dirToBuild = dirToBuild.rotateLeft();
                          }
                        }
                      }
                    }
                    // only move around if there are resources
                    if ((!built)
                        && rc.hasBuildRequirements(RobotType.TURRET)
                        && (rc.isCoreReady())) {
                      // don't move into enemy turret range if scout sends signal about it
                      Set<Direction> dangerousDirs = new HashSet<>();
                      Signal currentSignal = rc.readSignal();
                      while (currentSignal != null) {
                        int messageX = currentSignal.getMessage()[0];
                        int messageY = currentSignal.getMessage()[1];
                        // if signal message > 80000, then the message is signaling a turret
                        // location
                        if (messageX > 80000) {
                          messageX = messageX - 100000;
                          messageY = messageY - 100000;
                          MapLocation enemyTurretLoc = new MapLocation(messageX, messageY);
                          Direction dirToEnemyTurret = myLoc.directionTo(enemyTurretLoc);
                          Direction dirToEnemyTurretL =
                              myLoc.directionTo(enemyTurretLoc).rotateLeft();
                          Direction dirToEnemyTurretR =
                              myLoc.directionTo(enemyTurretLoc).rotateRight();
                          if (myLoc.add(dirToEnemyTurret).distanceSquaredTo(enemyTurretLoc) <= 48) {
                            dangerousDirs.add(dirToEnemyTurret);
                          }
                          if (myLoc.add(dirToEnemyTurretL).distanceSquaredTo(enemyTurretLoc)
                              <= 48) {
                            dangerousDirs.add(dirToEnemyTurretL);
                          }
                          if (myLoc.add(dirToEnemyTurretR).distanceSquaredTo(enemyTurretLoc)
                              <= 48) {
                            dangerousDirs.add(dirToEnemyTurretR);
                          }
                        }
                        currentSignal = rc.readSignal();
                      }

                      Direction dirToMove = RobotPlayer.directions[(rand.nextInt(4) * 2) + 1];
                      for (int i = 0; i < 4; i++) {
                        if (rc.canMove(dirToMove) && !dangerousDirs.contains(dirToMove)) {
                          rc.move(dirToMove);
                          break;
                        } else {
                          dirToMove = dirToMove.rotateLeft();
                          dirToMove = dirToMove.rotateLeft();
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        } else { // use soldiers
          boolean escape = false;
          if (rc.isCoreReady()) {
            escape = Movement.moveAwayFromEnemy(rc);
          }
          if (!escape) {
            if (adjNeutralRobots.length > 0) {
              // if there is a neutral robot adjacent, activate it or wait until there's no core
              // delay
              if (rc.isCoreReady()) {
                rc.activate(adjNeutralRobots[0].location);
              }
            }
            if (Movement.getToAdjParts(rc)) {
            } else {
              boolean toheal = false;
              // repair a nearby friendly robot
              if (rc.isWeaponReady()) {
                RobotInfo[] friendlyWithinRange = rc.senseNearbyRobots(24, myTeam);
                numFriendly = friendlyWithinRange.length;
                if (friendlyWithinRange.length > 0) {
                  RobotInfo toRepair = friendlyWithinRange[0];
                  for (RobotInfo r : friendlyWithinRange) {
                    if ((r.health < toRepair.health)
                        && (r.type != RobotType.ARCHON)
                        && (r.maxHealth - r.health > 1)) {
                      toRepair = r;
                    }
                  }
                  if ((toRepair.maxHealth - toRepair.health > 1)
                      && (toRepair.type != RobotType.ARCHON)) {
                    toheal = true;
                    rc.repair(toRepair.location);
                  }
                }
              }
              if (toheal == false) {
                // for sensing if there are guards within range 24
                RobotInfo[] friendlyClose = rc.senseNearbyRobots(24, myTeam);
                int numNearbyGuards = 0;
                for (RobotInfo f : friendlyClose) {
                  if (f.type == RobotType.GUARD) {
                    numNearbyGuards++;
                  }
                }

                boolean built = false;
                int turnNum = rc.getRoundNum();
                if (rc.hasBuildRequirements(RobotType.SCOUT)
                    && rc.isCoreReady()
                    && turnNum > 1
                    && turnNum % 150 >= 0
                    && turnNum % 150 <= 19
                    && turnNum < 900) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                  for (int i = 0; i < 8; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.SCOUT)) {
                      rc.build(dirToBuild, RobotType.SCOUT);
                      built = true;
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                if (rc.hasBuildRequirements(RobotType.GUARD)
                    && rc.isCoreReady()
                    && !built
                    && numNearbyGuards < 1) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                  for (int i = 0; i < 8; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.GUARD)) {
                      rc.build(dirToBuild, RobotType.GUARD);
                      built = true;
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                if (rc.hasBuildRequirements(RobotType.SOLDIER) && rc.isCoreReady() && !built) {
                  Direction dirToBuild = RobotPlayer.directions[rand.nextInt(8)];
                  for (int i = 0; i < 8; i++) {
                    // If possible, build in this direction
                    if (rc.canBuild(dirToBuild, RobotType.SOLDIER)) {
                      rc.build(dirToBuild, RobotType.SOLDIER);
                      built = true;
                      break;
                    } else {
                      // Rotate the direction to try
                      dirToBuild = dirToBuild.rotateLeft();
                    }
                  }
                }
                // if archon has nothing to do, tell soldiers to come to it's location
                /*if (rc.getRoundNum() > 500 && rc.isCoreReady() && rc.isWeaponReady()) {
                	rc.broadcastMessageSignal(-100, 0, 70 * 70);
                }*/
              }
            }
          }
        }
        Clock.yield();
      } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
      }
    }
  }
예제 #28
0
  public static void run() throws GameActionException {
    rc = RobotPlayer.rc;
    rand = new Random(rc.getID());

    // build scouts right away
    buildRobot(RobotType.SCOUT);

    while (true) {
      /*
       * INPUT
       */
      if (rc.getLocation().equals(goal)) {
        goal = null; // you made it to the goal
        past10Locations =
            new ArrayList<MapLocation>(); // delete the slug trail after you reach your goal
      }

      // sense locations around you
      nearbyMapLocations =
          MapLocation.getAllMapLocationsWithinRadiusSq(
              rc.getLocation(), rc.getType().sensorRadiusSquared);

      // parts locations
      nearbyPartsLocations = rc.sensePartLocations(RobotType.ARCHON.sensorRadiusSquared);

      // find the nearest mapLocation with the most parts
      double maxParts = 0;
      MapLocation nearbyLocationWithMostParts = null;
      for (MapLocation loc : nearbyPartsLocations) {
        // add to locationsWithParts arraylist
        if (locationsWithParts.contains(loc) == false) {
          locationsWithParts.add(loc);
        }

        // find the location with the most parts
        double partsAtLoc = rc.senseParts(loc);
        if (partsAtLoc > maxParts) {
          maxParts = partsAtLoc;
          nearbyLocationWithMostParts = loc;
        }
      }

      // read signals
      Signal[] signals = rc.emptySignalQueue();
      for (Signal signal : signals) {
        // check if the signal has parts at the location
        int[] message = signal.getMessage();
        if (message != null && message[0] == Utility.PARTS_CODE) {
          // add that location to the locationsWithParts arraylist
          locationsWithParts.add(signal.getLocation());
        }
      }

      // sense robots
      MapLocation myLoc = rc.getLocation();
      robots = rc.senseNearbyRobots();
      foes = new ArrayList<RobotInfo>();
      foesWithinAttackRange = new ArrayList<RobotInfo>();
      for (RobotInfo robot : robots) {
        if (robot.team == Team.ZOMBIE
            || robot.team == rc.getTeam().opponent()) // if the robot is a foe
        {
          foes.add(robot);

          if (myLoc.distanceSquaredTo(robot.location) < robot.type.attackRadiusSquared) {
            foesWithinAttackRange.add(robot);
          }
        }
      }
      int nearbyFoes = foes.size();
      int nearbyFoesInAttackRange = foesWithinAttackRange.size();

      /*//check stats
      double health = rc.getHealth();
      int infectedTurns = rc.getInfectedTurns();
      int robotsAlive = rc.getRobotCount();
      */

      /*
       * OUPUT
       */

      // what to do
      if (nearbyFoes == 0) // if there are no foes in sight
      {
        if (rc.getTeamParts() >= RobotType.TURRET.partCost) // build if you can
        {
          buildRobots();
        } else {
          if (maxParts > 0 && goal == null) // if there are parts nearby
          {
            // make that the goal
            goal = nearbyLocationWithMostParts;
          } else if (goal == null) // if there aren't and there is no goal
          {
            // build something or find new parts
            // 80% build, 20% new parts
            if (locationsWithParts.size() > 0 && rand.nextFloat() > .8) {
              goal = locationsWithParts.get(0);
              locationsWithParts.remove(0);
              goalIsASafeLocation = false;
            }
            // calculate the next goal - maybe a new parts location you got via signal
          } else if (goal != null) // if there is a goal, move there
          {
            moveToLocation(goal);
          }
        }
      } else // there are foes nearby
      {
        // message for help!
        if (Math.random() < probSignal) {
          rc.broadcastSignal(archonInTroubleSignalRadiusSquared);
        }

        if (nearbyFoesInAttackRange > 0) {
          goal = findSaferLocation();
          rc.setIndicatorString(0, "" + goal.x + " " + goal.y);
          goalIsASafeLocation = true;
          moveToLocation(goal);
        }
      }

      Clock.yield();
    }
  }
예제 #29
0
  public static void run(RobotController rc) {
    int myAttackRange = 0;
    Random rand = new Random(rc.getID());
    Team myTeam = rc.getTeam();
    Team enemyTeam = myTeam.opponent();

    try {
      // Any code here gets executed exactly once at the beginning of the game.
      myAttackRange = rc.getType().attackRadiusSquared;
    } catch (Exception e) {
      // Throwing an uncaught exception makes the robot die, so we need to catch exceptions.
      // Caught exceptions will result in a bytecode penalty.
      System.out.println(e.getMessage());
      e.printStackTrace();
    }

    while (true) {
      // This is a loop to prevent the run() method from returning. Because of the Clock.yield()
      // at the end of it, the loop will iterate once per game round.
      try {
        MapLocation myLoc = rc.getLocation();
        // If this robot type can attack, check for enemies within range and attack one
        // guards only attack ZOMBIES
        RobotInfo[] enemiesWithinRange =
            rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, Team.ZOMBIE);
        RobotInfo[] friendliesWithinRange =
            rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, myTeam);
        int closestArchonDist = 60;
        MapLocation closestArchonLoc = null;
        for (RobotInfo f : friendliesWithinRange) {
          if (f.type == RobotType.ARCHON) {
            MapLocation curArchonLoc = f.location;
            if (myLoc.distanceSquaredTo(curArchonLoc) < closestArchonDist) {
              closestArchonDist = myLoc.distanceSquaredTo(curArchonLoc);
              closestArchonLoc = curArchonLoc;
            }
          }
        }

        if (closestArchonLoc != null) {
          if (enemiesWithinRange.length > 0) {
            RobotInfo nearestEnemyToArchon = enemiesWithinRange[0];
            int nearestEnemyToArchonDist =
                nearestEnemyToArchon.location.distanceSquaredTo(closestArchonLoc);
            for (RobotInfo e : enemiesWithinRange) {
              if (e.location.distanceSquaredTo(closestArchonLoc) < nearestEnemyToArchonDist) {
                nearestEnemyToArchonDist = e.location.distanceSquaredTo(closestArchonLoc);
                nearestEnemyToArchon = e;
              }
            }
            // only attack/move towards if it's within 24 range of the archon
            if (nearestEnemyToArchonDist <= 24) {
              // Check if weapon is ready
              if (rc.isWeaponReady() && rc.canAttackLocation(nearestEnemyToArchon.location)) {
                rc.attackLocation(nearestEnemyToArchon.location);
              } else { // otherwise try to move towards the enemy
                if (rc.isCoreReady()) {
                  // try to move towards enemy
                  Direction dirToMove = myLoc.directionTo(nearestEnemyToArchon.location);
                  if (rc.canMove(dirToMove)) {
                    rc.move(dirToMove);
                  } else if (rc.canMove(dirToMove.rotateLeft())) {
                    rc.move(dirToMove.rotateLeft());
                  } else if (rc.canMove(dirToMove.rotateRight())) {
                    rc.move(dirToMove.rotateRight());
                  }
                }
              }
            }
          } else { // if no enemies, it should try to circle nearest archon
            if (rc.isCoreReady()) {
              Direction dirToMove = myLoc.directionTo(closestArchonLoc);
              if (rc.canMove(dirToMove)) {
                rc.move(dirToMove);
              } else if (rc.canMove(dirToMove.rotateLeft())) {
                rc.move(dirToMove.rotateLeft());
              } else if (rc.canMove(dirToMove.rotateRight())) {
                rc.move(dirToMove.rotateRight());
              }
            }
          }
        } else {
          rc.setIndicatorString(1, "no archon");
          // if no archons nearby, move randomly and attack
          if (enemiesWithinRange.length > 0) {
            RobotInfo nearestEnemy = enemiesWithinRange[0];
            int nearestEnemyDist = nearestEnemy.location.distanceSquaredTo(myLoc);
            for (RobotInfo e : enemiesWithinRange) {
              if (e.location.distanceSquaredTo(myLoc) < nearestEnemyDist) {
                nearestEnemyDist = e.location.distanceSquaredTo(myLoc);
                nearestEnemy = e;
              }
            }
            if (rc.isWeaponReady() && rc.canAttackLocation(nearestEnemy.location)) {
              rc.attackLocation(nearestEnemy.location);
            } else { // otherwise try to move towards the enemy
              if (rc.isCoreReady()) {
                // try to move towards enemy
                Direction dirToMove = myLoc.directionTo(nearestEnemy.location);
                if (rc.canMove(dirToMove)) {
                  rc.move(dirToMove);
                } else if (rc.canMove(dirToMove.rotateLeft())) {
                  rc.move(dirToMove.rotateLeft());
                } else if (rc.canMove(dirToMove.rotateRight())) {
                  rc.move(dirToMove.rotateRight());
                }
              }
            }
          } else if (rc.isCoreReady()) {
            Direction dirToMove = RobotPlayer.directions[(rand.nextInt(8))];
            for (int i = 0; i < 8; i++) {
              if (rc.canMove(dirToMove)) {
                rc.move(dirToMove);
                break;
              } else {
                dirToMove = dirToMove.rotateLeft();
              }
            }
          }
        }
        Clock.yield();
      } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
      }
    }
  }
예제 #30
0
  public static void run(RobotController rc) {
    sightRadius = RobotType.SOLDIER.sensorRadiusSquared;
    attackRadius = RobotType.SOLDIER.attackRadiusSquared;
    myTeam = rc.getTeam();
    enemyTeam = myTeam.opponent();
    while (true) {
      try {
        numEnemySoldiers = 0;
        totalEnemySoldierHealth = 0;
        myLoc = rc.getLocation();
        nearbyAllies = rc.senseNearbyRobots(sightRadius, myTeam);
        nearbyEnemies = rc.senseHostileRobots(myLoc, sightRadius);
        newArchonLoc = null;

        // clear bad locations
        resetLocations(rc);
        // read messages and get destination
        readMessages(rc);
        // heal if need (and set the archon destination to go to)
        setRetreatingStatus(rc, nearbyEnemies);

        // Remove turret locations that you can see are not there.
        // Does NOT remove turret locations due to broadcasts. Already done in read messages.
        removeTurretLocations(rc);

        if (newArchonLoc != null) {
          nearestArchonLocation = newArchonLoc;
        }

        rc.setIndicatorString(2, "Round: " + rc.getRoundNum() + ", rushing: " + rush);
        // Reset rushing if turns since rush is > 20 and see no more enemies.
        if (rush && myLoc.distanceSquaredTo(rushLocation) <= 100) turnsSinceRush++;
        if (turnsSinceRush > 20) {
          if (rc.senseNearbyRobots(sightRadius, enemyTeam).length == 0) {
            turnsSinceRush = 0;
            rush = false;
          }
        }

        // When rushing, be mad aggressive.
        if (rush) {
          rushMicro(rc, nearbyEnemies);
        }
        // When retreating, retreat
        else if (healing) {
          if (rc.isCoreReady()) {
            if (nearestArchonLocation != null) {
              if (myLoc.distanceSquaredTo(nearestArchonLocation) > 13) {
                bugging.enemyAvoidMove(nearbyEnemies);
                // Get away from archons that are not too close together.
              } else if (myLoc.distanceSquaredTo(nearestArchonLocation) <= 2) {
                Direction radialDir = nearestArchonLocation.directionTo(myLoc);
                Direction awayDir = Movement.getBestMoveableDirection(radialDir, rc, 2);
                if (awayDir != Direction.NONE) {
                  rc.move(awayDir);
                }
              }
            }
          }
          // Make sure to attack people even when retreating.
          // Prioritize the closest enemy. Then the closest zombie.
          if (rc.isWeaponReady()) {
            // Attack the closest enemy. If there is not one, then attack the closest zombie
            int closestDist = 10000;
            RobotInfo target = null;
            for (RobotInfo hostile : nearbyEnemies) {
              int dist = myLoc.distanceSquaredTo(hostile.location);
              if (rc.canAttackLocation(hostile.location)) {
                // There is already is a target
                if (target != null) {
                  if (target.team == enemyTeam) {
                    // Target is already enemy, so prioritize the closest
                    if (hostile.team == enemyTeam) {
                      if (dist < closestDist) {
                        target = hostile;
                        closestDist = dist;
                      }
                    } // If hostile is not an enemy, not worth considering.
                  } else {
                    // Target is not on enemy team, so hostile is best choice!
                    if (hostile.team == enemyTeam) {
                      target = hostile;
                      closestDist = dist;
                      // Both are zombies, so just pick the closest.
                    } else {
                      if (dist < closestDist) {
                        target = hostile;
                        closestDist = dist;
                      }
                    }
                  }
                  // Set a target when there is not one.
                } else {
                  target = hostile;
                  closestDist = dist;
                }
              }
            }
            // We know that if there is a target, we can attack it.
            if (target != null) {
              rc.attackLocation(target.location);
            }
          }
        }

        // When viper infected and will die from the infection, do special micro
        else if (isViperInfected(rc)
            && (rc.getHealth() < rc.getViperInfectedTurns() * 2 || rc.getRoundNum() > 2100)) {
          viperInfectedMicro(rc);
        }

        // if there are enemies in range, we should focus on attack and micro
        else if (nearbyEnemies.length > 0) {
          if (shouldLure(rc, nearbyEnemies, nearbyAllies)) luringMicro(rc);
          else micro(rc);
        } else { // otherwise, we should always be moving somewhere
          moveSoldier(rc);
        }

        Clock.yield();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }