예제 #1
0
  @Override
  public void run() throws GameActionException {
    // try to heal nearby robots
    RobotInfo[] nearbyAllies = rc.senseNearbyRobots(2, myTeam);
    RobotInfo friendWithLowestHP = Utility.getRobotWithLowestHP(nearbyAllies);
    if (rc.isCoreReady() && friendWithLowestHP != null) {
      if (friendWithLowestHP.type != RobotType.ARCHON) {
        rc.repair(friendWithLowestHP.location);
      }
    }
    if (goalLocation != null) {

      if (rc.canSense(goalLocation)) {
        goalLocation = null;
      }
      if (Utility.getClosestRound(zss) - rc.getRoundNum() > 50 && rc.getTeamParts() > 200) {
        tryToBuild();
      } else if (rc.isCoreReady() && goalLocation != null) {
        BugNav.goTo(goalLocation);
      }
    }

    // try to activate neutral units
    MapLocation closestNeutral = Utility.closestLocation(neutralBotLocations, rc.getLocation());
    if (closestNeutral != null) {
      rc.setIndicatorString(2, "Finding Neutal");
      if (rc.canSense(closestNeutral)
          && (rc.senseRobotAtLocation(closestNeutral) == null
              || rc.senseRobotAtLocation(closestNeutral).team != Team.NEUTRAL)) {
        neutralBotLocations.remove(closestNeutral);
      } else if (rc.getLocation().distanceSquaredTo(closestNeutral) < 2) {
        if (rc.isCoreReady()) {
          rc.activate(closestNeutral);
          neutralBotLocations.remove(closestNeutral);
        }
      } else if (rc.isCoreReady() && rc.canMove(rc.getLocation().directionTo(closestNeutral))) {
        tryToMove(rc.getLocation().directionTo(closestNeutral));
      }
    }

    RobotInfo[] enemies =
        rc.senseHostileRobots(rc.getLocation(), RobotType.ARCHON.sensorRadiusSquared);
    if (enemies.length > 3) {
      tryToRetreat(enemies);
    }

    tryToBuild();
    if (enemies.length > 0) {
      tryToRetreat(enemies);
      suppressSignals = true;
      return;
    } else {
      defaultBehavior();
    }
    suppressSignals = false;
  }
예제 #2
0
 public void tryToBuild() throws GameActionException {
   // try to build a robot
   Direction dl = randomDirection();
   if (rc.getRoundNum() % 400 < 20 && rc.canBuild(dl, RobotType.SCOUT) && rc.isCoreReady()) {
     rc.build(dl, RobotType.SCOUT);
   }
   double prob = random.nextDouble();
   int index = 0;
   RobotType robot;
   if (Utility.getClosestRound(zss) < 30) {
     while (prob > probabilitiesZ[index]) {
       index++;
     }
     robot = buildRobotTypes[index];
   } else {
     while (prob > probabilities[index]) {
       index++;
     }
     robot = buildRobotTypes[index];
   }
   for (Direction d : Direction.values()) {
     if (rc.canBuild(d, robot)) {
       if (rc.isCoreReady()) {
         rc.build(d, robot);
         int newid = rc.senseRobotAtLocation(rc.getLocation().add(d)).ID;
         MessageSignal teamFirstDirective = new MessageSignal(rc);
         if (leaderLocation != null) {
           teamFirstDirective.setCommand(leaderLocation, MessageSignal.CommandType.MOVE);
         }
         teamFirstDirective.send(2);
       }
     }
   }
   return;
 }
예제 #3
0
  // find a safe location
  public static MapLocation findSaferLocation() // move to far spot in direction with fewest enemies
      {
    MapLocation currentLocation = rc.getLocation();
    ArrayList<Direction> directions = Utility.arrayListOfDirections();

    /*
    ArrayList<Integer> enemiesInEachDirection = new ArrayList<Integer>(10);
    //initialize the enemiesInEachDirection arraylist
    for(int i = 0; i < 10; i++)
    {
    	enemiesInEachDirection.add(0);
    }

    for(RobotInfo foe : foes)
    {
    	Direction dirToFoe = currentLocation.directionTo(foe.location);
    	int index = directions.indexOf(dirToFoe);
    	int numberOfFoesInDirection = enemiesInEachDirection.get(index);
    	enemiesInEachDirection.set(index, numberOfFoesInDirection++);
    }

    int leastEnemies = 1000000;
    int directionWithLeastEnemies = 0;
    for(int i = 0; i<enemiesInEachDirection.size(); i++)
    {
    	int numberOfEnemies = enemiesInEachDirection.get(i);
    	if(numberOfEnemies < leastEnemies)
    	{
    		directionWithLeastEnemies = i;
    		leastEnemies = numberOfEnemies;
    	}
    }

    Direction direction = directions.get(directionWithLeastEnemies);//the direction with the fewest enemies
     */

    // find if foes are within attack range
    RobotInfo[] foes = rc.senseHostileRobots(rc.getLocation(), RobotType.SCOUT.sensorRadiusSquared);
    ArrayList<RobotInfo> nearAttackRange = new ArrayList<RobotInfo>();

    for (RobotInfo foe : foes) {
      RobotType type = foe.type;
      if (type != RobotType.ARCHON
          && type != RobotType.ZOMBIEDEN
          && type != RobotType.SCOUT) // only want enemies who can attack
      {
        // if you're close to the attack range
        if (currentLocation.distanceSquaredTo(foe.location) < foe.type.attackRadiusSquared + 4) {
          nearAttackRange.add(foe);
        }
      }
    }

    // get average loc of hostiles
    // could also just run away from the closest hostile
    // neither one of those would have you go up or down if you have enemies directly to
    // your left and right
    int n_hostiles = 0;
    int x_sum = 0;
    int y_sum = 0;
    if (nearAttackRange.size() > 0) {
      for (RobotInfo robot : nearAttackRange) {
        n_hostiles++;
        MapLocation robotLoc = robot.location;
        x_sum += robotLoc.x;
        y_sum += robotLoc.y;
      }
      int x = x_sum / n_hostiles;
      int y = y_sum / n_hostiles;
      MapLocation hostileLoc = new MapLocation(x, y);
      Direction dirToMove = hostileLoc.directionTo(rc.getLocation());
      MapLocation locationToGoTo =
          currentLocation.add(dirToMove, (int) Math.sqrt(RobotType.ARCHON.sensorRadiusSquared));
      return locationToGoTo;
    }

    /* OTHER WAY TO DO IT
    //get the average direction to them
    //ArrayList<Direction> listOfDirections = Utility.arrayListOfDirections();
    int averageDirection = 0;
    for(RobotInfo foe : nearAttackRange)
    {
    	averageDirection += directions.indexOf(currentLocation.directionTo(foe.location));
    }
    if(nearAttackRange.size() > 0)
    {
    	averageDirection /= nearAttackRange.size();
    	Direction directionToEnemies = directions.get(averageDirection);

    	//move in that direction as far as you can see
    	MapLocation locationToGoTo = currentLocation.add(directionToEnemies.opposite(), (int)Math.sqrt(RobotType.ARCHON.sensorRadiusSquared));
    	return locationToGoTo;
    }
    */

    else {
      return rc.getLocation();
    }
  }