/**
  * @param whereToGo
  * @throws GameActionException The original/old version of progressMove.
  */
 @SuppressWarnings("unused")
 private void progressMoveOld(MapLocation whereToGo) throws GameActionException {
   rc.setIndicatorString(1, "Swarm target: " + whereToGo.toString());
   int dist = rc.getLocation().distanceSquaredTo(whereToGo);
   if (dist > 0 && rc.isActive()) {
     Direction toTarget = rc.getLocation().directionTo(whereToGo);
     int[] directionOffsets = {0, 1, -1, 2, -2};
     Direction move;
     MapLocation ahead;
     for (int offset : directionOffsets) {
       move = Direction.values()[(toTarget.ordinal() + offset + 8) % 8];
       ahead = rc.getLocation().add(move);
       Team mine = rc.senseMine(ahead);
       int move_num = move.ordinal();
       if (rc.canMove(move)
           && (mine == rc.getTeam() || mine == null)
           && move_num != (previousMove + 4) % 8) {
         previousMove = move_num;
         rc.move(move);
         return;
       }
     }
     previousMove = -1;
     if (rc.canMove(toTarget) || rc.senseMine(rc.getLocation()) == rc.getTeam()) {
       moveOrDefuse(toTarget);
     }
   }
 }
Exemple #2
0
  public static void fire(RobotController rc) {
    int radius;

    try {
      if (rc.getType() == RobotType.HQ) {
        radius = 15;
        Robot[] enemies = rc.senseNearbyGameObjects(Robot.class, radius, rc.getTeam().opponent());
        Direction[] dirs = Direction.values();
        Robot target = null;
        int maxValue = 0;

        for (int k = 0; k < enemies.length; k++) {
          MapLocation loc = rc.senseRobotInfo(enemies[k]).location;
          int value = 2;
          for (int a = 0; a < 8; a++) {
            try {
              if (rc.senseObjectAtLocation(loc.add(dirs[a])).getTeam() == rc.getTeam().opponent()) {
                value++;
              } else if (rc.senseObjectAtLocation(loc.add(dirs[a])).getTeam() == rc.getTeam()) {
                value--;
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          }

          rc.setIndicatorString(0, "" + value);

          if (value > maxValue) {
            maxValue = value;
            target = enemies[k];
          }
        }

        if (target != null) {
          rc.attackSquare(rc.senseRobotInfo(target).location);
        }

      } else {
        radius = 10;
        Robot[] enemies = rc.senseNearbyGameObjects(Robot.class, radius, rc.getTeam().opponent());
        Robot target = null;

        for (int k = 0; k < enemies.length; k++) {
          if (target == null) {
            target = enemies[k];
          } else if (rc.senseRobotInfo(enemies[k]).health < rc.senseRobotInfo(target).health) {
            target = enemies[k];
          }
        }

        if (target != null) {
          rc.attackSquare(rc.senseRobotInfo(target).location);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemple #3
0
  public static boolean turnNuke(RobotController rc) {
    boolean nuke = false;

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

    if (nearByEnemies.length == 0) {

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

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

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

      int[] damage = new int[8];

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

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

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

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

      if (largest > 1) {
        // Nuke nuker = new Nuke(rc, nearBySpots[index]);
        // nuker.run();
        return true;
      } else {
        return false;
      }
    }
    return nuke;
  }
  private static void goToLocation(MapLocation whereToGo) throws GameActionException {

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

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

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

      lookForDir:
      for (int d : directionOffSets) {
        curDir = Direction.values()[(dir.ordinal() + d + 8) % 8];
        if (rc.canMove(curDir)) {
          break lookForDir;
        }
      }
      Team mine = rc.senseMine(rc.getLocation().add(curDir));
      if (mine != null && mine != rc.getTeam()) {
        rc.defuseMine(rc.getLocation().add(curDir));
      } else {
        rc.move(curDir);
        rc.setIndicatorString(0, "Last direction moved: " + dir.toString());
      }
    }
  }
Exemple #5
0
  public static boolean doWeNeedGenerator() throws GameActionException {
    if (rc.readBroadcast(Constants.campChannel) == Constants.campGenInProduction) return false;
    if (Clock.getRoundNum() - allInRound < 80) return false;
    if (rc.readBroadcast(Constants.commandChannel) == Constants.commandRally
        && rc.getTeamPower() > powerThreshold) return false;

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

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

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

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

    if ((40 + (10 * gencount) - (1.6 * soldiercount) - (1 * othercount)) * decay < 1) {
      return true;
    }
    return false;
  }
Exemple #6
0
  private static void shallWeAllIn() throws GameActionException {
    if (rc.senseEnemyNukeHalfDone() && Clock.getRoundNum() < 300) {
      rc.broadcast(Constants.attackChannel, Constants.attackAllIn);
      return;
    }

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

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

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

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

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

    if (massedRobos > massedAmountNeeded) // if we should all in...
    {
      rc.broadcast(Constants.attackChannel, Constants.attackAllIn);
      allInRound = Clock.getRoundNum();
    }
  }
  protected MapLocation[] findEnemy() throws GameActionException {
    ArrayList<MapLocation> enemyLocations = new ArrayList<MapLocation>();

    ArrayList<Robot> allRobots = new ArrayList<Robot>();
    Robot[] airRobots = myRC.senseNearbyAirRobots();
    Robot[] groundRobots = myRC.senseNearbyGroundRobots();
    allRobots.addAll(Arrays.asList(airRobots));
    allRobots.addAll(Arrays.asList(groundRobots));

    for (Robot robot : allRobots) {
      try {
        RobotInfo info = myRC.senseRobotInfo(robot);

        if (!myRC.getTeam().equals(info.team)) {
          int distance = myRC.getLocation().distanceSquaredTo(info.location);

          if (distance < enemyDistance) {
            enemyDistance = distance;
          }

          enemyLocations.add(info.location);
        }
      } catch (GameActionException e) {
      }
    }

    MapLocation[] retLocations = new MapLocation[enemyLocations.size()];
    retLocations = enemyLocations.toArray(retLocations);

    return retLocations;
  }
  public static void run(RobotController theRC) {
    rc = theRC;

    // These don't change so get them once and use the local variable (performance)
    myType = rc.getType();
    myTeam = rc.getTeam();
    enemyTeam = myTeam.opponent();
    myHQ = rc.senseHQLocation();
    myLoc = rc.getLocation();
    senseRange = myType.sensorRadiusSquared;
    attackRange = myType.attackRadiusSquared;
    maxRounds = rc.getRoundLimit();

    if (myType == RobotType.MISSILE) runMissile();

    if (myType.canMove()) {
      bfs = new Bfs(rc); // We need to check the breadth first search results to move optimally
    }
    threats = new Threats(rc);

    if (myType == RobotType.HQ) runHQ();
    else if (myType == RobotType.TOWER) runTower();
    else if (myType.isBuilding) runBuilding();
    else if (myType.canBuild()) runBeaver();
    else if (myType.canMine()) runMiner(); // Includes Beavers
    else if (myType == RobotType.DRONE) runDrone();
    else if (myType.canAttack() || myType == RobotType.LAUNCHER) runCombat();
    else runOther();
  }
 /**
  * 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();
     }
   }
 }
Exemple #10
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();
   }
 }
Exemple #11
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();
   }
 }
  private MapLocation getAverageEnemyArchonLocation(final RobotController robotController) {

    if (this.averageEnemyArchonLocation == null) {

      MapLocation[] enemyArchonLocations =
          robotController.getInitialArchonLocations(robotController.getTeam().opponent());
      if (enemyArchonLocations.length == 0) {

        return null;
      }

      int totalX = 0;
      int totalY = 0;
      for (int i = 0; i < enemyArchonLocations.length; i++) {

        totalX += enemyArchonLocations[i].x;
        totalY += enemyArchonLocations[i].y;
      }

      this.averageEnemyArchonLocation =
          new MapLocation(
              totalX / enemyArchonLocations.length, totalY / enemyArchonLocations.length);
    }
    return this.averageEnemyArchonLocation;
  }
 /**
  * helper fcn to compute if location contains a bad bomb
  *
  * @param rc
  * @param loc
  * @return
  */
 private static boolean badBomb(MapLocation loc) {
   Team isBomb = rc.senseMine(loc);
   if (isBomb == null || isBomb == rc.getTeam()) {
     return false;
   } else {
     return true;
   }
 }
  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);
      }
    }
  }
Exemple #15
0
 static void init(RobotController rc) {
   int roundLimit = rc.getRoundLimit();
   Common.rc = rc;
   rand = new Random(rc.getID());
   id = rc.getID();
   myTeam = rc.getTeam();
   enemyTeam = myTeam.opponent();
   history = new MapLocation[roundLimit];
   robotType = rc.getType();
   enrollment = rc.getRoundNum();
   if (robotType != RobotType.ARCHON) birthday = enrollment - robotType.buildTurns - BUILD_LAG;
   hometown = rc.getLocation();
   sightRadius = robotType.sensorRadiusSquared;
   straightSight = (int) Math.sqrt(sightRadius);
   canMessageSignal = robotType.canMessageSignal();
   Signals.buildTarget = new MapLocation[roundLimit];
   Signals.buildStrategy = new SignalStrategy[roundLimit];
   try {
     addInfo(rc.senseRobot(id));
     myArchonHometowns = rc.getInitialArchonLocations(myTeam);
     enemyArchonHometowns = rc.getInitialArchonLocations(enemyTeam);
     int coordinates[] = new int[MAP_MAX];
     int x = 0;
     int y = 0;
     for (int i = enemyArchonHometowns.length - 1; i >= 0; --i) {
       MapLocation loc = enemyArchonHometowns[i];
       twiceCenterX += loc.x;
       twiceCenterY += loc.y;
       coordinates[loc.y] *= MAP_MAX;
       coordinates[loc.y] += loc.x + 1;
     }
     for (int i = 0; i < myArchonHometowns.length; ++i) {
       MapLocation loc = myArchonHometowns[i];
       twiceCenterX += loc.x;
       twiceCenterY += loc.y;
       x += loc.x;
       y += loc.y;
     }
     twiceCenterX /= myArchonHometowns.length;
     twiceCenterY /= myArchonHometowns.length;
     x /= myArchonHometowns.length;
     y /= myArchonHometowns.length;
     for (int i = 0; i < myArchonHometowns.length; ++i) {
       MapLocation loc = myArchonHometowns[i];
       int xCoord = coordinates[loc.y] - 1;
       coordinates[loc.y] /= MAP_MAX;
       if (loc.x != twiceCenterX - xCoord) rotation = true;
     }
     Archon.center = new MapLocation(x, y);
     myBase = new MapLocation(twiceCenterX / 2, twiceCenterY / 2).directionTo(Archon.center);
     enemyBase = myBase.opposite();
   } catch (Exception e) {
     System.out.println(e.getMessage());
     e.printStackTrace();
   }
 }
 private void moveOrDefuse(Direction dir) throws GameActionException {
   MapLocation ahead = rc.getLocation().add(dir);
   if (rc.canMove(dir) && rc.senseMine(ahead) != null && rc.senseMine(ahead) != rc.getTeam()) {
     rc.defuseMine(ahead);
   } else {
     if (rc.canMove(dir)) {
       rc.move(dir);
     }
   }
 }
Exemple #17
0
  public static void soldierCode(RobotController myRC) throws GameActionException {
    rc = myRC;
    rallyPoint = findRallyPoint();
    while (true) {
      try {
        // returns all enemy robots within our sight range (aka that we can actually fight right now
        // or very soon)
        Robot[] closeEnemyRobots =
            rc.senseNearbyGameObjects(Robot.class, rc.getLocation(), 14, rc.getTeam().opponent());

        // returns all enemy robots reasonably close to us (aka that we should move toward and
        // potentially assist our allies in fighting)
        Robot[] enemyRobots = rc.senseNearbyGameObjects(Robot.class, 63, rc.getTeam().opponent());

        if (closeEnemyRobots.length == 0 && enemyRobots.length == 0) // no enemies are nearby
        {
          int command = HQCommand();
          switch (command) {
            case Constants.commandExpand:
              expand();
              break;
            case Constants.commandRally:
              rally();
              break;
            case Constants.commandEnemyNukeHalfDone:
              rally();
            case Constants.commandBuildIndividual: // TODO- implement this
              break;
          }
        } else {

          // enemy spotted
          localscan = false;
          MapLocation closestEnemy = findClosestRobot(enemyRobots);
          goToLocation(closestEnemy);
        }
      } catch (Exception e) {
        System.out.println("Soldier Exception");
        e.printStackTrace();
      }
      rc.yield();
    }
  }
Exemple #18
0
  public Robot(RobotController rc) {
    this.rc = rc;
    rand = new Random(rc.getID());
    team = rc.getTeam();
    enemy = team.opponent();
    currentLocation = rc.getLocation();

    RobotType type = rc.getType();
    senseRadius = type.sensorRadiusSquared;
    attackRadius = type.attackRadiusSquared;
  }
  public static void init(RobotController the_rc) {
    rc = the_rc;

    friendly = rc.getTeam();
    enemy = friendly.opponent();
    neutral = Team.NEUTRAL;
    zombie = Team.ZOMBIE;

    current_location = rc.getLocation();

    my_type = rc.getType();
    byte_code_limiter = my_type.bytecodeLimit;
  }
Exemple #20
0
  protected static void init(RobotController theRC) throws GameActionException {
    rc = theRC;
    us = rc.getTeam();
    them = us.opponent();

    ourHQ = rc.senseHQLocation();
    theirHQ = rc.senseEnemyHQLocation();

    mapWidth = rc.getMapWidth();
    mapHeight = rc.getMapHeight();

    FastRandom.init();
    MessageBoard.init(theRC);
    Bfs.init(theRC);
  }
Exemple #21
0
  private static int getNumberOfAlliedRobosAfterMe() throws GameActionException {
    int retval = 0;
    int myID = rc.getRobot().getID();

    Robot[] robos =
        rc.senseNearbyGameObjects(Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam());

    for (Robot r : robos) {
      if (r.getID() > myID) {
        ++retval;
      }
    }

    return retval;
  }
Exemple #22
0
  private static void expand() throws GameActionException {
    // rallyPoint = findClosestLocation(rc.senseAllEncampmentSquares());
    if (!localscan) {
      rallyPoint = findClosestEmptyCamp();
    }
    if (rc.getLocation().distanceSquaredTo(rallyPoint)
        < 1) // if we are at the location of the rally point
    {
      if (!localscan) {
        rallyPoint = findFurthestLocalCamp();
        localscan = true;
      }
    }
    if (rc.getLocation().distanceSquaredTo(rallyPoint)
        < 1) // if we are at the location of the rally point
    {

      if (rc.isActive()) // if we are allowed to capture
      {
        if (rc.senseCaptureCost() + 1.8 * getNumberOfAlliedRobosAfterMe()
            < rc.getTeamPower()) // if we have enough power to capture
        {
          int readIn = rc.readBroadcast(Constants.campChannel);
          if (readIn == Constants.campGen) {
            rc.broadcast(Constants.campChannel, Constants.campGenInProduction);
            rc.captureEncampment(RobotType.GENERATOR);
          } else if (readIn == Constants.campGenInProduction) {
            rc.captureEncampment(RobotType.SUPPLIER);
          } else if (readIn == Constants.campSupplier) {
            rc.captureEncampment(RobotType.SUPPLIER);
          } else // TODO: transmissions may be being scrambled, for now just make supplier
          {
            rc.captureEncampment(RobotType.SUPPLIER);
          }
        }
      }
    } else if (rc.senseNearbyGameObjects(Robot.class, rallyPoint, 0, rc.getTeam()).length
        > 0) // if there is an allied robot on our rally point
    {
      rallyPoint = findClosestEmptyCamp();
      if (rallyPoint == null) {
        rallyPoint = findRallyPoint();
      }
      goToLocation(rallyPoint);
    } else {
      goToLocation(rallyPoint);
    }
  }
Exemple #23
0
 private static MapLocation findClosestEmptyCamp() throws GameActionException {
   MapLocation[] locArray = rc.senseEncampmentSquares(rc.getLocation(), 1000000, Team.NEUTRAL);
   int closestDist = 1000000;
   MapLocation me = rc.getLocation();
   MapLocation closestLocation = null;
   for (int i = 0; i < locArray.length; i++) {
     MapLocation aLocation = locArray[i];
     int dist = aLocation.distanceSquaredTo(me);
     if (dist < closestDist
         && rc.senseNearbyGameObjects(Robot.class, aLocation, 0, rc.getTeam()).length < 1) {
       closestDist = dist;
       closestLocation = aLocation;
     }
   }
   return closestLocation;
 }
Exemple #24
0
  private static MapLocation findFurthestLocalCamp() throws GameActionException {
    MapLocation result = null;
    MapLocation me = rc.getLocation();
    MapLocation[] locArray = rc.senseEncampmentSquares(me, localScanRange, Team.NEUTRAL);
    int furthestDist = -1;

    for (int i = 0; i < locArray.length; i++) {
      MapLocation aLocation = locArray[i];
      int dist = aLocation.distanceSquaredTo(me);
      if (dist > furthestDist
          && rc.senseNearbyGameObjects(Robot.class, aLocation, 0, rc.getTeam()).length < 1) {
        furthestDist = dist;
        result = aLocation;
      }
    }
    return result;
  }
  private static void runSoldier() throws GameActionException {
    // follow orders from HQ
    // Direction towardEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
    // BasicPathing.tryToMove(towardEnemy, true, rc, directionalLooks, allDirections);//was
    // Direction.SOUTH_EAST

    Robot[] enemyRobots = rc.senseNearbyGameObjects(Robot.class, 10000, rc.getTeam().opponent());
    if (enemyRobots.length > 0) { // if there are enemies
      rc.setIndicatorString(0, "There are enemies");
      MapLocation[] robotLocations = new MapLocation[enemyRobots.length];
      for (int i = 0; i < enemyRobots.length; i++) {
        Robot anEnemy = enemyRobots[i];
        RobotInfo anEnemyInfo = rc.senseRobotInfo(anEnemy);
        robotLocations[i] = anEnemyInfo.location;
      }
      MapLocation closestEnemyLoc = VectorFunctions.findClosest(robotLocations, rc.getLocation());
      if (closestEnemyLoc.distanceSquaredTo(rc.getLocation())
          < rc.getType().attackRadiusMaxSquared) {
        rc.setIndicatorString(1, "trying to shoot");
        if (rc.isActive()) {
          rc.attackSquare(closestEnemyLoc);
        }
      } else {
        rc.setIndicatorString(1, "trying to go closer");
        Direction towardClosest = rc.getLocation().directionTo(closestEnemyLoc);
        simpleMove(towardClosest);
      }
    } else {

      if (path.size() == 0) {
        MapLocation goal = getRandomLocation();
        path =
            BreadthFirst.pathTo(
                VectorFunctions.mldivide(rc.getLocation(), bigBoxSize),
                VectorFunctions.mldivide(rc.senseEnemyHQLocation(), bigBoxSize),
                100000);
      }
      // follow breadthFirst path
      Direction bdir = BreadthFirst.getNextDirection(path, bigBoxSize);
      BasicPathing.tryToMove(bdir, true, rc, directionalLooks, allDirections);
    }
    // Direction towardEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
    // simpleMove(towardEnemy);

  }
Exemple #26
0
 public static void expandIndividual() throws GameActionException {
   MapLocation expandLocation =
       new MapLocation(
           rc.readBroadcast(Constants.singleExpandXChannel),
           rc.readBroadcast(Constants.singleExpandYChannel));
   rc.broadcast(Constants.commandChannel, Constants.commandRally);
   while (true) {
     if (rc.getLocation().distanceSquaredTo(expandLocation)
         < 1) // if we are at the location of the rally point
     {
       if (rc.isActive()) // if we are allowed to capture
       {
         if (rc.senseCaptureCost() + 1.8 * getNumberOfAlliedRobosAfterMe()
             < rc.getTeamPower()) // if we have enough power to capture
         {
           int readIn = rc.readBroadcast(Constants.campChannel);
           if (readIn == Constants.campGen) {
             rc.broadcast(Constants.campChannel, Constants.campGenInProduction);
             rc.captureEncampment(RobotType.GENERATOR);
           } else if (readIn == Constants.campGenInProduction) {
             rc.captureEncampment(RobotType.SUPPLIER);
           } else if (readIn == Constants.campSupplier) {
             rc.captureEncampment(RobotType.SUPPLIER);
           } else // TODO: transmissions may be being scrambled, for now just make supplier
           {
             rc.captureEncampment(RobotType.SUPPLIER);
           }
           break;
         }
       }
     } else if (rc.senseNearbyGameObjects(Robot.class, expandLocation, 0, rc.getTeam()).length
         > 0) // if there is an allied robot on our rally point
     {
       expandLocation = findClosestEmptyCamp();
       if (expandLocation == null) {
         expandLocation = findRallyPoint();
       }
       goToLocation(expandLocation);
     } else {
       goToLocation(expandLocation);
     }
     rc.yield();
   }
 }
  public static void run(RobotController myRC) {
    rc = myRC;
    barracks = findBarracks();
    while (true) {
      try {
        if (rc.getType() == RobotType.SOLDIER) {
          Robot[] enemyRobots =
              rc.senseNearbyGameObjects(
                  Robot.class, 50000, rc.getTeam().opponent()); // list of enemy robots
          if (enemyRobots.length == 0) {
            Clock.getRoundNum(); // gets the round number
            if (Clock.getRoundNum() < 250) {
              goToLocation(
                  barracks); // if you are before round 250 travel to the "barracks" or meeting
                             // place.
            } else {
              goToLocation(rc.senseEnemyHQLocation());
            }
          } else { // else attack the closest enemy
            int closestDist = 50000;
            MapLocation closestEnemy = null;
            for (int i = 0; i < enemyRobots.length; i++) {
              Robot enemyBot = enemyRobots[i];
              RobotInfo arobotInfo = rc.senseRobotInfo(enemyBot);
              int dist = arobotInfo.location.distanceSquaredTo(rc.getLocation());
              if (dist < closestDist) {
                closestDist = dist;
                closestEnemy = arobotInfo.location;
              }
            }
            goToLocation(closestEnemy);
          }
        } else {
          HqCommand();
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
      rc.yield(); // end turn
    }
  }
Exemple #28
0
 /** @param rc */
 public static void run(RobotController rc) {
   rand = new Random(rc.getID());
   myTeam = rc.getTeam();
   while (true) {
     if (rc.getType() == RobotType.ARCHON) {
       archon(rc);
     } else if (rc.getType() == RobotType.SCOUT) {
       scout(rc);
     } else if (rc.getType().equals(RobotType.TURRET)) {
       turret(rc);
     } else if (rc.getType().equals(RobotType.TTM)) {
       ttm(rc);
     } else if (rc.getType() == RobotType.SOLDIER) {
       soldier(rc);
     } else if (rc.getType() == RobotType.GUARD) {
       guard(rc);
     } else if (rc.getType() == RobotType.VIPER) {
       viper(rc);
     }
   }
 }
  private MapLocation getAverageFriendlyArchonLocation(final RobotController robotController) {

    if (this.averageFriendlyArchonLocation == null) {

      int totalX = 0;
      int totalY = 0;
      MapLocation[] friendlyArchonLocations =
          robotController.getInitialArchonLocations(robotController.getTeam());

      for (int i = 0; i < friendlyArchonLocations.length; i++) {

        totalX += friendlyArchonLocations[i].x;
        totalY += friendlyArchonLocations[i].y;
      }

      this.averageFriendlyArchonLocation =
          new MapLocation(
              totalX / friendlyArchonLocations.length, totalY / friendlyArchonLocations.length);
    }
    return this.averageFriendlyArchonLocation;
  }
Exemple #30
0
  protected void transferEnergon() throws GameActionException {
    for (Robot robot : myRC.senseNearbyGroundRobots()) {
      try {
        RobotInfo robotInfo = myRC.senseRobotInfo(robot);

        if (robotInfo.team == myRC.getTeam()) {
          MapLocation robotLocation = robotInfo.location;

          if (myRC.getLocation().isAdjacentTo(robotLocation))
            myRC.transferEnergon(
                Math.max(
                    0,
                    Math.min(
                        robotInfo.maxEnergon - robotInfo.eventualEnergon,
                        myRC.getEnergonLevel() / 2)),
                robotLocation,
                RobotLevel.ON_GROUND);
        }
      } catch (GameActionException e) {

      }
    }
  }