Ejemplo n.º 1
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();
   }
 }
Ejemplo n.º 2
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));
      }
    }
  }
Ejemplo n.º 3
0
  // All combat units (Soldiers, Bashers, Tanks, Drones, Launchers, Commander)
  private static void runCombat() {
    while (true) {
      threats.update();
      myLoc = rc.getLocation();

      // Move if we can and want to
      if (rc.isCoreReady()) {
        boolean ignoreThreat = overwhelms();

        if (!ignoreThreat && shouldRetreat()) {
          if (rc.isWeaponReady() && myType.loadingDelay == 0) attackWeakest();
          doRetreatMove(); // Pull back if in range of the enemy guns
        } else {
          boolean engaged = false;
          if (rc.isCoreReady() && inCombat(4)) engaged = doCloseWithEnemyMove(ignoreThreat);
          if (rc.isCoreReady()
              && !engaged) // Close with enemy might not do a move if the enemy is a drone out of
                           // reach
          doAdvanceMove();
        }
      }

      // Attack if there is an enemy in sight
      if (myType == RobotType.LAUNCHER) doLaunch();
      else if (rc.isWeaponReady()) attackWeakest();

      doTransfer();

      rc.yield();
    }
  }
Ejemplo n.º 4
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();
   }
 }
Ejemplo n.º 5
0
 private static void moveSoldier(RobotController rc) throws GameActionException {
   // if we have a real current destination
   rc.setIndicatorString(1, "moving somewhere " + currentDestination + rc.getRoundNum());
   if (currentDestination != null) {
     // if bugging is never initialized or we are switching destinations, reinitialize bugging
     if (!currentDestination.equals(storedDestination) || bugging == null) {
       bugging = new Bugging(rc, currentDestination);
       storedDestination = currentDestination;
     }
     // if we are trying to move towards a turret, stay out of range
     if (rc.isCoreReady()) {
       if (currentDestination.equals(nearestTurretLocation)) {
         bugging.turretAvoidMove(turretLocations);
       } else
       // if core is ready, then try to move towards destination
       if (nearestTurretLocation != null) {
         bugging.turretAvoidMove(turretLocations);
       } else {
         bugging.move();
       }
     }
   } else if (nearestArchonLocation
       != null) { // we don't actually have a destination, so we want to try to move towards the
                  // closest archon
     rc.setIndicatorString(
         0, "moving to nearest archon " + nearestArchonLocation + rc.getRoundNum());
     if (!nearestArchonLocation.equals(storedDestination)) {
       bugging = new Bugging(rc, nearestArchonLocation);
       storedDestination = nearestArchonLocation;
     }
     // if core is ready, try to move
     if (rc.isCoreReady() && bugging != null) {
       if (nearestTurretLocation != null) {
         bugging.turretAvoidMove(turretLocations);
       } else if (nearestArchonLocation.equals(bugging.destination)
           && myLoc.distanceSquaredTo(nearestArchonLocation)
               > 13) { // if soldier is far, move towards archon
         bugging.move();
       } else if (nearestArchonLocation.equals(bugging.destination)
           && myLoc.distanceSquaredTo(nearestArchonLocation)
               < 13) { // if soldier is too close, move towards archon
         // try to move away from nearest archon
         if (rc.canMove(nearestArchonLocation.directionTo(myLoc))) {
           rc.move(nearestArchonLocation.directionTo(myLoc));
         }
       }
     }
   } else { // if we literally have nowhere to go
     rc.setIndicatorString(1, "bugging around friendly " + rc.getRoundNum());
     bugAroundFriendly(rc);
   }
 }
Ejemplo n.º 6
0
 private static void broadcastRecordedEnemy(RobotController rc, RobotInfo enemy)
     throws GameActionException {
   if (enemy.type == RobotType.ARCHON && rc.isCoreReady()) {
     Message.sendMessageGivenDelay(rc, enemy.location, Message.ENEMYARCHONLOC, 0.25);
   } else if (enemy.team == Team.ZOMBIE
       && enemy.type != RobotType.RANGEDZOMBIE
       && rc.isCoreReady()) {
     Message.sendMessageGivenDelay(rc, enemy.location, Message.ZOMBIE, 0.25);
   } else if (enemy.type == RobotType.TURRET && rc.isCoreReady()) {
     Message.sendMessageGivenDelay(rc, enemy.location, Message.TURRET, 0.25);
   } else if (rc.isCoreReady()) {
     Message.sendMessageGivenDelay(rc, enemy.location, Message.ENEMY, 0.25);
   }
 }
Ejemplo n.º 7
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));
   }
 }
Ejemplo n.º 8
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());
     }
   }
 }
Ejemplo n.º 9
0
  protected boolean tryBuild(RobotType robotType, Direction initialDirection)
      throws GameActionException {
    if (!rc.isCoreReady()) {
      return false;
    }

    if (rc.getTeamParts() < robotType.partCost) {
      return false;
    }

    int startingPosition = getDirectionNumber(initialDirection);
    if (startingPosition < 0) {
      startingPosition = 0;
    }

    int[] d = {0, 1, 7, 2, 6, 3, 5, 4};
    for (int i = 0; i < 8; i++) {
      Direction direction = directions[(startingPosition + d[i]) % 8];
      if (rc.canBuild(direction, robotType)) {
        rc.build(direction, robotType);
        return true;
      }
    }

    return false;
  }
Ejemplo n.º 10
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;
   }
 }
Ejemplo n.º 11
0
  private static void archonMicro(RobotController rc, RobotInfo enemyArchon)
      throws GameActionException {
    if (rc.isCoreReady()) {
      int dist = myLoc.distanceSquaredTo(enemyArchon.location);
      // When not adjacent to the archon, walk/mine through to him.
      if (dist > 2) {
        Direction desired = myLoc.directionTo(enemyArchon.location);
        Direction dir = Movement.getBestMoveableDirection(desired, rc, 2);
        if (dir != Direction.NONE) {
          rc.move(dir);
        } else if (shouldMine(rc, desired)) {
          rc.clearRubble(desired);
        } else if (shouldMine(rc, desired.rotateLeft())) {
          rc.clearRubble(desired.rotateLeft());
        } else if (shouldMine(rc, desired.rotateRight())) {
          rc.clearRubble(desired.rotateRight());
        }
      }
      // When adjacent to archon, rotate to the left/right when possible.
      else {
        Direction dir = myLoc.directionTo(enemyArchon.location);
        if (rc.canMove(dir.rotateLeft())) {
          rc.move(dir.rotateLeft());
        } else if (rc.canMove(dir.rotateRight())) {
          rc.move(dir.rotateRight());
        }
      }
    }

    if (rc.isWeaponReady()) {
      if (rc.canAttackLocation(enemyArchon.location)) {
        rc.attackLocation(enemyArchon.location);
      }
    }
  }
Ejemplo n.º 12
0
  // Drones
  private static void runDrone() {
    moveDir = Direction.NORTH;
    droneMoveCurrent = 1;
    droneMoveMax = 2;
    patrolClockwise = true;
    droneCentred = false; // We haven't made it to the centre of our spiral yet

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

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

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

      doTransfer();

      rc.yield();
    }
  }
Ejemplo n.º 13
0
  // move in a given direction
  public static void moveInDirection(Direction d) throws GameActionException {
    MapLocation m = rc.getLocation().add(d);

    if (rc.senseRubble(m) < tooMuchRubble
        || Math.random() < probClearRubbleAnyways) // if it's less than 20, just move there
    {
      if (rc.isCoreReady() && rc.canMove(d)) {
        rc.move(d);
      }
    } else // clear it
    {
      if (rc.isCoreReady()) {
        rc.clearRubble(d);
      }
    }
  }
Ejemplo n.º 14
0
  /**
   * Attempts to build a robot of the given type in a random direction (attempts all directions).
   * Only attempts building if rc has no core delay and has more parts than the threshold.
   *
   * @param rc RobotController from which to build
   * @param buildType type of robot to build
   * @return true if buildType is built else false
   * @throws GameActionException
   */
  private static boolean tryToBuild(RobotController rc, RobotType buildType)
      throws GameActionException {
    if (rc.isCoreReady()) {
      Direction buildDir = getRandomDirection();
      for (int i = 0; i < 8; i++) {
        if (rc.canBuild(buildDir, buildType)) {
          rc.build(buildDir, buildType);
          rc.broadcastMessageSignal(SENDING_MODE, currentMode, ONE_SQUARE_RADIUS);

          if (!turtleCorner.equals(LOCATION_NONE)) {
            rc.broadcastMessageSignal(SENDING_TURTLE_X, turtleCorner.x, ONE_SQUARE_RADIUS);
            rc.broadcastMessageSignal(SENDING_TURTLE_Y, turtleCorner.y, ONE_SQUARE_RADIUS);
          }

          if (buildType.equals(RobotType.SCOUT)) {
            for (MapLocation scoutKitingLoc : SCOUT_KITING_LOCATIONS) {
              rc.broadcastMessageSignal(
                  SENDING_SCOUT_KITING_LOCATION_X, scoutKitingLoc.x, ONE_SQUARE_RADIUS);
              rc.broadcastMessageSignal(
                  SENDING_SCOUT_KITING_LOCATION_Y, scoutKitingLoc.y, ONE_SQUARE_RADIUS);
            }
          }
          return true;
        }
        buildDir = buildDir.rotateRight(); // try all directions clockwise
      }
    }
    return false;
  }
Ejemplo n.º 15
0
  // Beavers
  private static void runBeaver() {
    strategy = new BuildStrategy(rc);
    rand = new Random(rc.getID());

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

      if (rc.isCoreReady()) {
        RobotType build = strategy.getBuildOrder();
        if (build != null) tryBuild(rc.getLocation().directionTo(threats.enemyHQ), build);
      }

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

      double ore = rc.senseOre(rc.getLocation());

      // Move if we can and want to
      if (rc.isCoreReady()) {
        boolean ignoreThreat = overwhelms();

        if (!ignoreThreat && shouldRetreat()) {
          doRetreatMove(); // Pull back if in range of the enemy guns
        } else {
          doMinerMove();
          if (ore == 0 && rc.isCoreReady()) { // We didn't find ore nearby
            doSearchMove();
          }
        }
      }

      // Mine if possible
      if (rc.isCoreReady() && ore > 0) {
        try {
          rc.mine();
        } catch (GameActionException e) {
          System.out.println("Mining Exception");
          // e.printStackTrace();
        }
      }

      doTransfer();

      rc.yield();
    }
  }
Ejemplo n.º 16
0
 private static void leadZombiesToEnemy(RobotController rc) throws GameActionException {
   // TODO stop anti-kiting
   if (rc.isCoreReady()) {
     if (rc.canMove(Direction.SOUTH_WEST)) {
       rc.move(Direction.SOUTH_WEST);
     }
   }
 }
Ejemplo n.º 17
0
 /**
  * Goes through a list of adjacent locations. If a wall is detected, robot tries to move away from
  * it.
  *
  * @param rc
  * @throws GameActionException
  */
 private static void moveAwayFromWalls(RobotController rc) throws GameActionException {
   MapLocation myLocation = rc.getLocation();
   for (Direction dir : DIRECTIONS) {
     if (!rc.onTheMap(myLocation.add(dir)) && rc.isCoreReady()) {
       moveTowards(rc, dir.opposite());
     }
   }
 }
Ejemplo n.º 18
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);
      }
    }
  }
Ejemplo n.º 19
0
  // move to a maplocation
  public static void moveToLocation(MapLocation m) throws GameActionException {
    MapLocation currentLoc = rc.getLocation();
    Direction directionToM = currentLoc.directionTo(m);
    Direction actualDirectionToMove = directionToM;

    // deal with the slug trail - trim it to size
    if (past10Locations.size() > 10) {
      while (past10Locations.size() > 10) {
        past10Locations.remove(past10Locations.size() - 1);
      }
    }
    past10Locations.add(currentLoc);

    MapLocation locationToMoveTo = currentLoc.add(directionToM);

    if (canMoveThere(
        actualDirectionToMove,
        locationToMoveTo)) // make sure it's not part of the slug trail and it's not blocked by
                           // rubble and you can move there
    {
      moveInDirection(actualDirectionToMove);
    } else {
      // first, check if you should remove rubble. only if the surrounding squares are empty
      // boolean shouldRemoveRubble = false;
      int directionsWithRubble = 0;
      for (Direction d : Direction.values()) {
        MapLocation added = goal.add(d);
        boolean isFullOfRubble = rc.senseRubble(added) > 50;
        if (isFullOfRubble) {
          directionsWithRubble++;
        }
      }
      if (directionsWithRubble > 2) // if it's surrounded then dig
      {
        if (rc.isCoreReady()) {
          if (actualDirectionToMove.equals(Direction.OMNI) == false) {
            rc.clearRubble(actualDirectionToMove);
          }
        }
      } else // if not, path around it
      {
        Direction right = actualDirectionToMove.rotateRight();
        MapLocation rightLoc = currentLoc.add(right);

        while (right.equals(actualDirectionToMove) == false) {
          if (canMoveThere(right, rightLoc)) {
            moveInDirection(right);
            right = actualDirectionToMove;
          } else {
            right = right.rotateRight();
            rightLoc = currentLoc.add(right);
          }
        }
      }
    }
  }
Ejemplo n.º 20
0
 // build a robot of a given type
 public static void buildRobot(RobotType type) throws GameActionException {
   if (rc.isCoreReady() && rc.hasBuildRequirements(type)) {
     Direction[] values = Direction.values();
     for (Direction dir : values) {
       if (rc.canBuild(dir, type)) {
         rc.build(dir, type);
         return;
       }
     }
   }
 }
Ejemplo n.º 21
0
 static void move(RobotController rc) throws GameActionException {
   int rand = Common.rand.nextInt(9);
   Direction dir;
   if (rand == 8 && last != null) dir = last;
   else dir = Common.DIRECTIONS[rand];
   dir = Common.findPathDirection(rc, dir);
   if (rc.isCoreReady() && rc.canMove(dir)) {
     Common.move(rc, dir);
     last = dir;
   }
 }
Ejemplo n.º 22
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);
       }
     }
   }
 }
Ejemplo n.º 23
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);
     }
   }
 }
Ejemplo n.º 24
0
 /*
  * If there are no good moves we should stay and fight
  */
 private static void doRetreatMove() {
   try {
     if (myType == RobotType.COMMANDER
         && rc.hasLearnedSkill(CommanderSkillType.FLASH)
         && rc.getFlashCooldown() == 0) flashTowards(myHQ, true);
     Direction d = myLoc.directionTo(myHQ);
     rc.setIndicatorString(2, "Threatened - retreating towards HQ " + d);
     if (rc.isCoreReady()) tryMove(d, false);
   } catch (GameActionException e) {
     System.out.println("Retreat exception");
     // e.printStackTrace();
   }
 }
Ejemplo n.º 25
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));
   }
 }
Ejemplo n.º 26
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;
 }
Ejemplo n.º 27
0
  public static void clear_rubble() throws GameActionException {
    if (!rc.isCoreReady()) return;
    if (Scanner.can_see_targets()) return;
    if (Scanner.there_is_hidden_enemy()) return;

    Direction direction_to_clear = current_location.directionTo(destination);

    if (direction_to_clear == Direction.NONE || direction_to_clear == Direction.OMNI) return;

    if (rc.senseRubble(current_location.add(direction_to_clear)) < 1) return;

    rc.clearRubble(direction_to_clear);
    rc.setIndicatorString(1, "Clearing: " + direction_to_clear.toString());
  }
Ejemplo n.º 28
0
  /**
   * Checks if rc can move in direction dir (runs isCoreReady and canMove). If so, moves. If not,
   * moves rc in any of the four directions nearest dir, if possible.
   *
   * @param rc
   * @param dir
   * @return true if rc moves else false
   * @throws GameActionException
   */
  private static void moveTowards(RobotController rc, Direction dir) throws GameActionException {
    if (rc.isCoreReady() && !dir.equals(Direction.OMNI) && !dir.equals(Direction.NONE)) {
      Direction[] moveRight = {
        dir,
        dir.rotateRight(),
        dir.rotateLeft(),
        dir.rotateRight().rotateRight(),
        dir.rotateLeft().rotateLeft()
      };
      Direction[] moveLeft = {
        dir,
        dir.rotateLeft(),
        dir.rotateRight(),
        dir.rotateLeft().rotateLeft(),
        dir.rotateRight().rotateRight()
      };
      Direction[] nearDirections =
          Math.random() >= .5
              ? moveRight
              : moveLeft; // 50% chance robot tries to move to right first

      for (Direction nearDir : nearDirections) {
        if (rc.canMove(nearDir) && rc.isCoreReady()) {
          rc.move(nearDir);
        }
      }
      if (rc.getType() != RobotType.TTM
          && rc.getType() != RobotType.TTM) // these types can't clear rubble
      {
        if (rc.isCoreReady()
            && rc.onTheMap(rc.getLocation().add(dir))
            && rc.senseRubble(rc.getLocation().add(dir)) > RUBBLE_LOWER_CLEAR_THRESHOLD) {
          clearRubble(rc);
        }
      }
    }
  }
Ejemplo n.º 29
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);
     }
   }
 }
Ejemplo n.º 30
0
  // Factories and supply depots
  private static void runBuilding() { // Most builds spawn units
    if (myType.canSpawn()) strategy = new BuildStrategy(rc);

    while (true) {
      if (rc.isCoreReady() && myType.canSpawn()) {
        threats.update();
        RobotType build = strategy.getBuildOrder();
        if (build != null) trySpawn(rc.getLocation().directionTo(threats.enemyHQ), build);
      }

      doTransfer();

      rc.yield();
    }
  }