예제 #1
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();
    }
  }
예제 #2
0
파일: HQ.java 프로젝트: TeamYOLO/BC2013
  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;
  }
예제 #3
0
파일: HQ.java 프로젝트: TeamYOLO/BC2013
  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();
    }
  }
예제 #4
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;
  }
예제 #5
0
 public static boolean containsNoiseTower(Robot[] robots, RobotController rc)
     throws GameActionException {
   for (int i = robots.length; i-- > 0; ) {
     if (rc.senseRobotInfo(robots[i]).type == RobotType.NOISETOWER) return true;
   }
   return false;
 }
예제 #6
0
 public static boolean containsConstructingRobotOrNoiseTower(Robot[] robots, RobotController rc)
     throws GameActionException {
   for (int i = robots.length; i-- > 0; ) {
     RobotInfo info = rc.senseRobotInfo(robots[i]);
     if (info.type == RobotType.NOISETOWER || info.isConstructing) return true;
   }
   return false;
 }
예제 #7
0
 public static boolean containsNonConstructingSoldier(Robot[] robots, RobotController rc)
     throws GameActionException {
   for (int i = robots.length; i-- > 0; ) {
     RobotInfo info = rc.senseRobotInfo(robots[i]);
     if (info.type == RobotType.SOLDIER && !info.isConstructing) return true;
   }
   return false;
 }
예제 #8
0
 public static RobotInfo[] senseAllInfos(Robot[] bots, RobotController rc)
     throws GameActionException {
   RobotInfo[] ret = new RobotInfo[bots.length];
   for (int i = bots.length; i-- > 0; ) {
     ret[i] = rc.senseRobotInfo(bots[i]);
   }
   return ret;
 }
예제 #9
0
 public static int countNonConstructingSoldiers(Robot[] robots, RobotController rc)
     throws GameActionException {
   int ret = 0;
   for (int i = robots.length; i-- > 0; ) {
     RobotInfo info = rc.senseRobotInfo(robots[i]);
     if (info.type == RobotType.SOLDIER && !info.isConstructing) ret++;
   }
   return ret;
 }
예제 #10
0
 private static MapLocation findClosestRobot(Robot[] enemyRobots) throws GameActionException {
   int closestDist = 1000000;
   MapLocation closestEnemy = null;
   for (int i = 0; i < enemyRobots.length; i++) {
     Robot arobot = enemyRobots[i];
     RobotInfo arobotInfo = rc.senseRobotInfo(arobot);
     int dist = arobotInfo.location.distanceSquaredTo(rc.getLocation());
     if (dist < closestDist) {
       closestDist = dist;
       closestEnemy = arobotInfo.location;
     }
   }
   return closestEnemy;
 }
  public Direction fleeWeighted(Robot[] en) throws GameActionException {
    Robot[] allies = sensor.getBots(Sensor.SENSE_RANGE_ALLIES);
    int yDir = 0;
    int xDir = 0;
    int numEnemies = en.length;
    int numAllies = allies.length;

    for (Robot e : en) {
      MapLocation eLoc = rc.senseRobotInfo(e).location;
      xDir -= eLoc.x;
      yDir -= eLoc.y;
    }
    for (Robot a : allies) {
      MapLocation aLoc = rc.senseRobotInfo(a).location;
      xDir += aLoc.x;
      yDir += aLoc.y;
    }
    xDir += numEnemies * cur.x - numAllies * cur.x;
    yDir += numEnemies * cur.y - numAllies * cur.y;

    Direction desired = cur.directionTo(cur.add(xDir, yDir));

    return m.smartMove(desired);
  }
예제 #12
0
 public static MapLocation closestNonConstructingSoldier(
     Robot[] robots, MapLocation here, RobotController rc) throws GameActionException {
   MapLocation ret = null;
   int bestDistSq = 999999;
   for (int i = robots.length; i-- > 0; ) {
     RobotInfo info = rc.senseRobotInfo(robots[i]);
     if (info.type != RobotType.SOLDIER || info.isConstructing) continue;
     MapLocation loc = info.location;
     int distSq = loc.distanceSquaredTo(here);
     if (distSq < bestDistSq) {
       bestDistSq = distSq;
       ret = loc;
     }
   }
   return ret;
 }
예제 #13
0
  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);

  }
예제 #14
0
  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
    }
  }
예제 #15
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) {

      }
    }
  }
예제 #16
0
 public static void run(RobotController myRC) {
   rc = myRC;
   rallyPoint = findRallyPoint();
   while (true) {
     try {
       if (rc.getType() == RobotType.SOLDIER) {
         if (rc.senseEncampmentSquare(rc.getLocation())) {
           if (rc.getTeamPower() > 10 * (rc.senseAlliedEncampmentSquares().length + 10)) {
             rc.captureEncampment(RobotType.SUPPLIER);
           } else {
             rc.captureEncampment(RobotType.GENERATOR);
           }
         } else {
           Robot[] enemyRobots =
               rc.senseNearbyGameObjects(Robot.class, 100000, rc.getTeam().opponent());
           if (enemyRobots.length == 0
               || (enemyRobots.length == 1
                   && rc.senseRobotInfo(enemyRobots[0]).type
                       == RobotType.HQ)) { // no enemies nearby
             Robot[] alliedRobots = rc.senseNearbyGameObjects(Robot.class, 1000000, rc.getTeam());
             if (alliedRobots.length < 5 * (rc.senseAlliedEncampmentSquares().length) + 1) {
               if (Math.random() < 0.1 && alliedRobots.length < 20) {
                 if (rc.senseMine(rc.getLocation()) == null) {
                   rc.layMine();
                 }
               }
               goToLocation(rallyPoint);
             } else {
               goToLocation(rc.senseEnemyHQLocation());
             }
           } else { // someone spotted
             int closestDist = 100000;
             MapLocation closestEnemy = null;
             for (int i = 0; i < enemyRobots.length; i++) {
               Robot arobot = enemyRobots[i];
               RobotInfo arobotInfo = rc.senseRobotInfo(arobot);
               int dist = arobotInfo.location.distanceSquaredTo(rc.getLocation());
               if (dist < closestDist) {
                 closestDist = dist;
                 closestEnemy = arobotInfo.location;
               }
             }
             Robot[] nearbyAllies = rc.senseNearbyGameObjects(Robot.class, 64, rc.getTeam());
             if (nearbyAllies.length > 2.5 * enemyRobots.length) {
               if (closestDist > 4) {
                 goToLocation(closestEnemy);
               }
             }
             goToLocationAvoidMines(closestEnemy);
           }
         }
       } else {
         hqCode();
       }
     } catch (Exception e) {
       //				System.out.println("caught exception before it killed us:");
       //				e.printStackTrace();
     }
     rc.yield();
   }
 }
예제 #17
0
  public static void MoveMapLocation(RobotController rc, MapLocation target, boolean sneak) {
    MapLocation[] pastLocations = new MapLocation[10];
    int side = 45;
    Direction dir;
    Direction newDir;
    rand = new Random();
    // we initialize pastLocations to hold our current location 5 times
    for (int i = 0; i < pastLocations.length; i++) {
      pastLocations[i] = rc.getLocation();
    }

    // this method will run until we get to our target location
    while (!rc.getLocation().equals(target)) {
      // we put the try block inside of the while loop so an exception won't terminate the method
      try {
        dir = rc.getLocation().directionTo(target);
        newDir = Direction.NONE;

        // simple shoot at an enemy if we see one will need to be improved later
        Robot[] nearbyEnemies = rc.senseNearbyGameObjects(Robot.class, 10, rc.getTeam().opponent());
        if (nearbyEnemies.length > 0 && rc.senseRobotInfo((Robot) nearbyEnemies[0]).health < 201) {
          fire(rc);
        }
        // if we can move towards target and we haven't been on the square recently then lets move
        else if (rc.canMove(dir)
            && !MapLocationInArray(rc, rc.getLocation().add(dir), pastLocations)) {
          newDir = dir;
          // if we found a direction to move then we go to it
          if (newDir != Direction.NONE) {
            // now we decide if we are going to sneak or run
            if (sneak) {
              // another check to make sure we don't throw any exceptions
              if (rc.isActive() && rc.canMove(newDir)) {
                // System.out.println(newDir);
                rc.sneak(newDir);
              }
            } else {
              // another check to make sure we don't throw any exceptions
              if (rc.isActive() && rc.canMove(newDir)) {
                rc.move(newDir);
              }
            }
          }
          side = 45;
        } else {
          // if their is a robot blocking our way then we just move in a random direction
          if (rc.senseObjectAtLocation(rc.getLocation().add(dir)) != null) {
            // newDir = directions[rand.nextInt(8)];
            MoveDirection(rc, dir, sneak);
          } else {
            // rc.setIndicatorString(2, "Looking elswhere");
            Direction dir2 = dir;
            MapLocation right;
            MapLocation left;
            dir2 = (dir.rotateRight());
            while (!rc.canMove(dir2)) {
              dir2 = dir2.rotateRight();
            }
            right = rc.getLocation().add(dir2);

            dir2 = dir.rotateLeft();
            while (!rc.canMove(dir2)) {
              dir2 = dir2.rotateLeft();
            }

            left = rc.getLocation().add(dir2);

            // left seems better so lets go that way
            if (left.distanceSquaredTo(target) < right.distanceSquaredTo(target)) {
              side = 1;
            }
            // right seems better so lets try that way
            else {
              side = 0;
            }

            // we will go hugging one side of obstacle until we get back on our original line
            while (!dir2.equals(dir) && !rc.getLocation().equals(target)) // && rc.canMove(dir2))
            {
              try {
                if (rc.isActive()) {
                  // rc.setIndicatorString(1, "Trying to Avoid");
                  // rc.setIndicatorString(2, ""+side);
                  dir2 = rc.getLocation().directionTo(target);
                  if (rc.canMove(dir2)
                      && !MapLocationInArray(rc, rc.getLocation().add(dir2), pastLocations)) //  &&
                  // !rc.senseTerrainTile(rc.getLocation().add(dir2).add(dir2)).equals(TerrainTile.VOID))
                  {
                    // rc.setIndicatorString(0, "Going straight");
                  } else {
                    for (int i = 0; i < 4; i++) {
                      if (side == 1) {
                        dir2 = dir2.rotateLeft();
                      } else {
                        dir2 = dir2.rotateRight();
                      }
                      if (rc.senseTerrainTile(rc.getLocation().add(dir2))
                          .equals(TerrainTile.OFF_MAP)) {
                        dir2 = Direction.NONE;
                        i = 48;
                      } else if ((rc.canMove(dir2)
                          || (rc.senseObjectAtLocation(rc.getLocation().add(dir2))
                              != null))) // && !MapLocationInArray(rc, rc.getLocation().add(dir2),
                      // pastLocations))// &&
                      // !rc.senseTerrainTile(rc.getLocation().add(dir2).add(dir2)).equals(TerrainTile.VOID))
                      {
                        i = 48;
                      } else if (i == 3) {
                        dir2 = Direction.NONE;
                        // rc.setIndicatorString(1, "We failed to find a spot");
                      }
                    }
                  }

                  // if we can move
                  if (dir2 != Direction.NONE) {
                    if (rc.isActive()) {
                      if (rc.canMove(dir2)) {
                        if (sneak) {
                          rc.sneak(dir2);
                        } else {
                          rc.move(dir2);
                        }
                      } else {
                        MoveDirection(rc, dir2, sneak);
                      }
                    }
                  } else {
                    if (side == 1) {
                      side = 0;
                    } else {
                      side = 1;
                    }
                  }
                }
                // rc.setIndicatorString(0, "Dir: "+ dir +" Dir2: " + dir2);
              } catch (Exception e) {
                // tell the console we through an exception in utility object for debug purposes
                // System.out.println("Utility Exception");
                // System.out.println(e.toString());
                e.printStackTrace();
                rc.yield();
              }
              if (!rc.getLocation().equals(pastLocations[(pastLocations.length - 1)])) {
                for (int j = 0; j < (pastLocations.length - 1); j++) {
                  pastLocations[j] = pastLocations[j + 1];
                  // System.out.println(pastLocations[j]);
                }
                // stick current local into array
                pastLocations[(pastLocations.length - 1)] = rc.getLocation();
              }

              rc.yield();
            }
            // rc.setIndicatorString(1, "Not trying to Avoid");
          }
        }

        // now we  shift everything up one in pastLocations
        if (rc.getLocation() != pastLocations[(pastLocations.length - 1)]) {
          for (int j = 0; j < (pastLocations.length - 1); j++) {
            pastLocations[j] = pastLocations[j + 1];
            // System.out.println(pastLocations[j]);
          }
          // stick current local into array
          pastLocations[(pastLocations.length - 1)] = rc.getLocation();
        }

        rc.yield();
      } catch (Exception e) {
        // tell the console we through an exception in utility object for debug purposes
        System.out.println("Utility Exception");
        e.printStackTrace();
        // System.out.println(e.toString());
        rc.yield();
      }
    }
  }