Esempio n. 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();
    }
  }
Esempio n. 2
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;
  }
Esempio n. 3
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;
  }
Esempio n. 4
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();
    }
  }
Esempio n. 5
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();
    }
  }
Esempio n. 6
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;
  }
Esempio n. 7
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);
    }
  }
Esempio n. 8
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;
 }
Esempio n. 9
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;
  }
Esempio n. 10
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);

  }
Esempio n. 11
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
    }
  }
Esempio n. 13
0
 private static void rally() throws GameActionException {
   rallyPoint = findRallyPoint();
   // if we are fairly close to the rally point and we have the necessary soldier counts to make up
   // a wave, gogogogogo
   if (rc.getLocation().distanceSquaredTo(rallyPoint) < rallyRadius) {
     if (rc.readBroadcast(Constants.attackChannel) == Constants.attackAllIn) {
       while (true) {
         Robot[] closeEnemyRobots =
             rc.senseNearbyGameObjects(Robot.class, rc.getLocation(), 14, rc.getTeam().opponent());
         if (closeEnemyRobots.length == 0) {
           goToLocation(rc.senseEnemyHQLocation());
         } else {
           goToLocation(Util.findClosestRobot(rc, closeEnemyRobots));
         }
         rc.yield();
       }
     } else {
       goToLocation(rallyPoint);
     }
   } else {
     goToLocation(rallyPoint);
   }
 }
Esempio n. 14
0
  // this method will advance one square towards a target and try to avoid enemies as much as
  // possible
  public static void avoidEnemiesMove(RobotController rc, MapLocation target) {
    try {
      // first we will find all enemy bots near us
      GameObject[] nearByBots = rc.senseNearbyGameObjects(Robot.class, 15, rc.getTeam().opponent());
      Direction direction = rc.getLocation().directionTo(target);

      // if we don't see anything then lets head towards target
      if (nearByBots.length == 0) {
        // rc.setIndicatorString(2, "No enemies detected");
        // rc.setIndicatorString(1, "x: "+target.x + " y: " + target.y);
        direction = rc.getLocation().directionTo(target);
        if (rc.canMove(direction)) // &&
        // !rc.senseTerrainTile(rc.getLocation().add(direction).add(direction)).equals(TerrainTile.VOID))
        {
          if (rc.isActive()) {
            rc.move(direction);
          }
        } else {
          MapLocation target2 = rc.getLocation().add(direction);
          if (rc.senseTerrainTile(target2).equals(TerrainTile.VOID)) {
            int j = 0;
            while (rc.senseTerrainTile(target2).equals(TerrainTile.VOID)) {
              rc.setIndicatorString(0, "" + j);
              j++;

              target2 = target2.add(direction);
            }
            Utilities.MoveMapLocation(rc, target2, false);
          }
          /*
          int distanceRight = 0;
          int distanceLeft = 0;
             direction = direction.rotateRight();
             while (!rc.canMove(direction) && rc.senseTerrainTile(rc.getLocation().add(direction)).equals(TerrainTile.VOID))
             {
                 direction = direction.rotateRight();
             }
             if (rc.isActive())
             {
                 if (rc.canMove(direction))
                 {
                     rc.move(direction);
                 }
             }
             */
        }
      }
      // otherwise we need to avoid them
      else {
        rc.setIndicatorString(2, "Avoiding enemies");
        rc.setIndicatorString(1, "Numb of Enemies: " + nearByBots.length);
        // now we will calculate the distance form all 5 spots towards are target and the distance
        // from that spot to all enemies we can see
        // we will pick the one with the greatest distance
        int[] distancesToLocations = new int[5];

        for (int k = 0; k < distancesToLocations.length; k++) {
          distancesToLocations[k] = 0;
        }
        MapLocation spot;
        Direction newDir;

        // first we look 90 to our right
        newDir = direction.rotateRight().rotateRight();
        for (int j = 0; j < 5; j++) {
          if (rc.canMove(newDir)) {
            spot = rc.getLocation().add(newDir);
            for (int i = 0; i < nearByBots.length; i++) {
              // System.out.println("entering for loop");
              distancesToLocations[j] += spot.distanceSquaredTo(rc.senseLocationOf(nearByBots[i]));
            }
          } else {
            distancesToLocations[j] = -123;
          }
          // every time through the loop we look one further to the left
          newDir.rotateLeft();
        }

        int indexOfLargest = 0;
        int largest = distancesToLocations[0];
        for (int j = 1; j < distancesToLocations.length; j++) {
          if (largest < distancesToLocations[j]) {
            indexOfLargest = j;
            largest = distancesToLocations[j];
          }
        }

        // now we orientate newDir to the right spot
        newDir = direction.rotateRight().rotateRight();
        for (int i = 0; i <= indexOfLargest; i++) {
          newDir = newDir.rotateLeft();
        }

        while (!rc.isActive()) {
          rc.yield();
        }

        // now we can finally move
        if (rc.isActive()) {
          if (rc.canMove(newDir)) {
            rc.move(newDir);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 15
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();
      }
    }
  }
Esempio n. 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();
   }
 }
Esempio n. 17
0
  public static void hqCode(RobotController myRC) throws GameActionException {
    rc = myRC;
    Direction defaultSpawnDir = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
    evaluateMap();
    while (true) {
      rc.broadcast(Constants.attackChannel, 0);
      enemyRobots =
          rc.senseNearbyGameObjects(
              Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam().opponent());

      if (expandOrRally()) {
        rc.broadcast(Constants.commandChannel, Constants.commandExpand);
        broadcastUpdatedBuildOrder();

        MapLocation rally = findRallyPoint();
        rc.broadcast(Constants.rallyXChannel, rally.x);
        rc.broadcast(Constants.rallyYChannel, rally.y);
      } else {
        MapLocation rally = findRallyPoint();
        rc.broadcast(Constants.rallyXChannel, rally.x);
        rc.broadcast(Constants.rallyYChannel, rally.y);
        rc.broadcast(Constants.commandChannel, Constants.commandRally);
      }

      if (rc.isActive()) {
        int readIn = rc.readBroadcast(Constants.campChannel);

        if (!doWeNeedGenerator()) {
          rc.broadcast(Constants.campChannel, Constants.campSupplier);

          // Spawn a soldier
          Team defaultScan = rc.senseMine(rc.getLocation().add(defaultSpawnDir));
          if (rc.canMove(defaultSpawnDir) && (defaultScan == null || defaultScan == rc.getTeam())) {
            rc.spawn(defaultSpawnDir);
          } else {
            for (Direction d : Direction.values()) // TODO: optimize secondary direction finding
            {
              if (d != Direction.OMNI && d != Direction.NONE) {
                Team scan = rc.senseMine(rc.getLocation().add(d));
                if (rc.canMove(d) && (scan == null || scan == rc.getTeam())) {
                  rc.spawn(d);
                  break;
                }
              }
            }
            if (rc.isActive()) {
              // if there are no valid spawn directions
              rc.researchUpgrade(Upgrade.NUKE);
            }
          }
        } else // we do need a generator
        {
          if (readIn == Constants.campSupplier
              || (readIn != Constants.campGenInProduction && readIn != Constants.campGen)) {
            rc.broadcast(Constants.campChannel, Constants.campGen);
          }
          if (!rc.hasUpgrade(Upgrade.FUSION)) {
            rc.researchUpgrade(Upgrade.FUSION);
          } else if (!rc.hasUpgrade(Upgrade.DEFUSION)) {
            rc.researchUpgrade(Upgrade.DEFUSION);
          } else {
            rc.researchUpgrade(Upgrade.NUKE);
          }
        }
      }

      if (Clock.getRoundNum() > 200) {
        if (rc.senseEnemyNukeHalfDone()) {
          rc.broadcast(Constants.commandChannel, Constants.commandEnemyNukeHalfDone);
          while (!rc.hasUpgrade(Upgrade.DEFUSION)) {
            if (rc.isActive()) {
              rc.researchUpgrade(Upgrade.DEFUSION);
            }
            rc.yield();
          }
          enemyRobots =
              rc.senseNearbyGameObjects(
                  Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam().opponent());
        }
      }
      shallWeAllIn();
      rc.yield();
    }
  }