예제 #1
0
 public void go() throws GameActionException {
   if (rc.senseParts(rc.getLocation()) > 5) {
     signalSendb.foundSomeParts(70);
   }
   moveb.visit(rc.getLocation());
   if (attackb.canChertAttack()) attackb.chertAttack();
   else {
     moveb.move(moveb.randomDirectionHasNotVisited());
   }
   reset();
 }
예제 #2
0
 /**
  * Archons automatically collect parts on their current location. This method checks for nearby
  * parts within a radius squared distance of 9 and moves towards the nearest parts.
  *
  * @param rc must be archon
  * @return whether parts were collected
  * @throws GameActionException
  */
 private static void collectParts(RobotController rc) throws GameActionException {
   int lowestDistanceIndex = 0;
   MapLocation myLocation = rc.getLocation();
   MapLocation[] parts = rc.sensePartLocations(PART_COLLECTION_RADIUS_SQUARED);
   for (int i = 0; i < parts.length; i++) {
     if (myLocation.distanceSquaredTo(parts[i])
             < myLocation.distanceSquaredTo(parts[lowestDistanceIndex])
         && rc.senseRubble(parts[lowestDistanceIndex]) < 200) {
       lowestDistanceIndex = i;
     }
     if (myLocation.distanceSquaredTo(parts[i])
         == myLocation.distanceSquaredTo(parts[lowestDistanceIndex])) {
       lowestDistanceIndex =
           rc.senseParts(parts[i]) > rc.senseParts(parts[lowestDistanceIndex])
               ? i
               : lowestDistanceIndex;
     }
   }
   if (rc.isCoreReady() && parts.length > 0 && rc.senseRubble(parts[lowestDistanceIndex]) < 200) {
     moveTowards(rc, myLocation.directionTo(parts[lowestDistanceIndex]));
   }
 }
예제 #3
0
 static void senseParts(RobotController rc) throws GameActionException {
   int roundNum = rc.getRoundNum();
   for (MapLocation loc : rc.sensePartLocations(sightRadius)) {
     if (mapParts[loc.x % MAP_MOD][loc.y % MAP_MOD] == 0) {
       double parts = rc.senseParts(loc);
       if (parts >= PART_KEEP_THRESH) partLocations[partLocationsSize++] = loc;
       mapParts[loc.x % MAP_MOD][loc.y % MAP_MOD] = parts;
     }
     partsTimes[loc.x % MAP_MOD][loc.y % MAP_MOD] = roundNum;
   }
   // if(robotType == RobotType.ARCHON && rand.nextInt(1) == 0) {
   // // cull list
   // ListIterator<MapLocation> it = partLocations.listIterator();
   // while(it.hasNext()) {
   // MapLocation loc = it.next();
   // if(rc.canSense(loc) && rc.senseParts(loc) == 0) it.remove();
   // }
   // }
 }
예제 #4
0
  public static void run() throws GameActionException {
    rc = RobotPlayer.rc;
    rand = new Random(rc.getID());

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

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

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

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

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

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

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

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

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

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

      /*
       * OUPUT
       */

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

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

      Clock.yield();
    }
  }