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

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

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

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

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

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

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

    // Go to right place
    if (curr.distanceSquaredTo(target) > 7) {
      // System.out.println(target + " target " + allies.length + "ally length");
      Move.moveTo(rc, target);
    }
  }
Example #6
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;
  }
Example #7
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();
    }
  }
Example #8
0
  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();
  }
 public AttackStrategy(RobotController rc, Random rand) throws GameActionException {
   this.rc = rc;
   this.ENEMY = rc.getTeam().opponent();
   this.INFO = rc.senseRobotInfo(rc.getRobot());
   this.rand = rand;
   wanderingDirection = null;
 }
Example #11
0
 private static void turret(RobotController rc) {
   // do one time things here
   turtleCorner = turtleCorner == null ? LOCATION_NONE : turtleCorner;
   try {
     RobotInfo[] friendlyRobots =
         rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam());
     if (rc.getHealth() <= 3 && rc.isInfected() && friendlyRobots.length > 0) {
       rc.disintegrate();
     }
     turretAttack(rc);
     processFighterSignals(rc);
     if ((archonIsTooClose(rc) || isAdjacentToWall(rc))
         && rc.getType() == RobotType.TURRET
         && rc.isCoreReady()) {
       rc.pack();
     }
     if (turtleCorner != LOCATION_NONE && rc.isCoreReady() && rc.getType() == RobotType.TURRET) {
       int minCornerRadius = (20 + (rc.getRobotCount() / 10));
       if (rc.getLocation().distanceSquaredTo(turtleCorner) < minCornerRadius) {
         rc.pack();
       }
     }
     rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
     rc.setIndicatorString(1, "I am a turret");
     // if (turtleCorner.equals(LOCATION_NONE)) tryToLocateCorner(rc);
     Clock.yield();
   } catch (GameActionException e) {
     e.printStackTrace();
   }
 }
Example #12
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();
     }
   }
 }
Example #13
0
  // returns true if the robot moved away
  public static boolean moveAwayFromEnemy(RobotController rc) throws GameActionException {
    Team myTeam = rc.getTeam();
    int mySightRange = rc.getType().sensorRadiusSquared;
    MapLocation myLoc = rc.getLocation();
    RobotInfo[] hostiles = rc.senseHostileRobots(myLoc, mySightRange);

    MapLocation closestEnemy = null;
    int closestEnemyDist = 60;
    for (RobotInfo e : hostiles) {
      MapLocation curEnemyLoc = e.location;
      int curDist = myLoc.distanceSquaredTo(curEnemyLoc);
      if (curDist < closestEnemyDist) {
        closestEnemyDist = curDist;
        closestEnemy = e.location;
      }
    }
    if (closestEnemy == null) {
      return false;
    } else {
      Direction dir = getBestMoveableDirection(closestEnemy.directionTo(myLoc), rc, 4);
      if (dir != Direction.NONE) {
        rc.move(dir);
        return true;
      } else {
        return false;
      }
    }
  }
  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;
  }
  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());
      }
    }
  }
 /**
  * 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;
   }
 }
Example #17
0
 public static void rangedDefuseMine() throws GameActionException {
   if (rc.hasUpgrade(Upgrade.DEFUSION)) {
     MapLocation[] mines = rc.senseMineLocations(rc.getLocation(), 14, rc.getTeam().opponent());
     if (mines.length > 0 && rc.isActive()) {
       rc.defuseMine(mines[0]);
     }
   }
 }
Example #18
0
  private static boolean reactiveRush(RobotController rc) throws GameActionException {
    // TODO if we are losing in an economy based game
    int ally = rc.sensePastrLocations(rc.getTeam()).length;
    int enemy = rc.sensePastrLocations(rc.getTeam().opponent()).length;

    if (rush) {
      return true;
    } else if (enemy > ally) {
      //			System.out.println("REACTIVE RUSH");
      return true;
    } else if (rc.readBroadcast(Util.failedPastr) > 0) {
      //			System.out.println("REACTIVE RUSH 1");
      return true;
    }

    return false;
  }
Example #19
0
  private static void kamikaze(RobotController rc) throws GameActionException {

    Team enemy = rc.getTeam().opponent();
    MapLocation[] enemyPASTRs = rc.sensePastrLocations(enemy);

    if (enemyPASTRs.length > 0) Move.moveTo(rc, enemyPASTRs[0]);
    else Move.moveTo(rc, rc.senseEnemyHQLocation());
  }
  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);
      }
    }
  }
Example #21
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);
     }
   }
 }
Example #23
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();
    }
  }
Example #24
0
  public void run() {
    while (true) {
      try {
        Robot[] enemies = rc.senseNearbyGameObjects(Robot.class, 35, rc.getTeam().opponent());

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

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

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

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

        }
      } catch (Exception e) {
      }
      rc.yield();
    }
  }
Example #25
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;
  }
Example #26
0
 public RobotRunner(RobotController rcin) {
   this.rc = rcin;
   randall = new Random(rc.getID());
   myTeam = rc.getTeam();
   enemyTeam = myTeam.opponent();
   eden = rc.getInitialArchonLocations(myTeam)[0];
   memory = new Information(); // Everybody has a brain
   robotSenseRadius = (int) Math.sqrt(rc.getType().sensorRadiusSquared);
   marco = new Move();
   enigma = new MessageHash();
 }
Example #27
0
  static void checkIfBackupNeeded(RobotController rc) throws GameActionException {

    int soldierSenseRad = (int) RobotType.SOLDIER.sensorRadiusSquared;

    Robot[] allies = rc.senseNearbyGameObjects(Robot.class, soldierSenseRad, rc.getTeam());
    Robot[] enemies =
        rc.senseNearbyGameObjects(Robot.class, soldierSenseRad, rc.getTeam().opponent());

    // System.out.println(allies.length + " " + enemies.length);

    boolean outnumbered = false;
    if (enemies.length == 0) outnumbered = false;
    else if ((double) allies.length / enemies.length <= 1.5) outnumbered = true;

    if (outnumbered && rc.readBroadcast(Channels.backupChannel) == 0) {
      int squad = rc.readBroadcast(rc.getRobot().getID());
      rc.broadcast(
          Channels.backupChannel, Channels.backupEncoding(rc.getLocation(), squad, enemies.length));
      System.out.println("COWBOY sending help call");
    }
  }
Example #28
0
  static void runDefender(RobotController rc, int squad) throws GameActionException {
    Team team = rc.getTeam();
    Team enemy = team.opponent();

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

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

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

    // Create a PASTR/NT if not already there

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

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

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

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

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

    // If there is a pastr and noisetower, don't block them!
    if (PASTRstatus == 1 && NTstatus == 1) {
      if (enemyRobots.length == 0 && rc.senseCowsAtLocation(rc.getLocation()) > 30) {
        Move.tryToSneak(rc);
      }
    }
  }
  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;
  }
Example #30
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);
  }