/**
  * @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);
     }
   }
 }
  public static void HqCommand() throws GameActionException {
    if (rc.getType() == RobotType.HQ) {
      //			if (rc.isActive()) {
      // Spawn a soldier

      int[] directionOffSets = {0, 1, -1, 2, -2};

      //			    Team mineSpawn = rc.senseMine(rc.getLocation().add(spawnDir));
      Direction dir =
          rc.getLocation().directionTo(rc.senseEnemyHQLocation()); // this does not work!
      Direction spawnDir = dir;
      // spawn robots in the direction of the enemy
      if (rc.senseMine(rc.getLocation().add(dir)) != null) {
        lookForDir:
        for (int d : directionOffSets) {
          spawnDir = Direction.values()[(dir.ordinal() + d + 8) % 8];
          if (rc.canMove(spawnDir) && rc.senseMine(rc.getLocation().add(spawnDir)) != null) {
            rc.spawn(Direction.SOUTH);
            rc.spawn(spawnDir);
            break lookForDir;
          }
        }
      }

      if (rc.canMove(dir)) {
        rc.spawn(dir);
      }
      //			}
    }
  }
 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);
     }
   }
 }
  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;
   }
 }
Exemple #6
0
 private static void moveOrDefuse(Direction dir) throws GameActionException {
   MapLocation ahead = rc.getLocation().add(dir);
   if (rc.senseMine(ahead) != null) {
     rc.defuseMine(ahead);
   } else {
     rc.move(dir);
   }
 }
  public void progressMove(MapLocation whereToGo, Boolean inBattle) throws GameActionException {
    MapLocation currentLocation = rc.getLocation();
    int dist = currentLocation.distanceSquaredTo(whereToGo);

    if (dist > 0 && rc.isActive()) {
      Direction toTarget = currentLocation.directionTo(whereToGo);
      int[] directionOffsets = {-2, 2, -1, 1, 0};
      Direction potentialDirectionMovement; // direction of where we are going to move
      MapLocation newLocation;

      int offset;
      for (int i = 5; --i >= 0; ) {
        offset = directionOffsets[i];
        potentialDirectionMovement = Direction.values()[(toTarget.ordinal() + offset + 8) % 8];
        newLocation = rc.getLocation().add(potentialDirectionMovement);
        Team mineAtPotentialNewLocation = rc.senseMine(newLocation);
        if (rc.canMove(potentialDirectionMovement)
            && this.shouldMakeMoveRand(newLocation, currentLocation)
            && (mineAtPotentialNewLocation == myTeam || mineAtPotentialNewLocation == null)) {
          rc.move(potentialDirectionMovement);
          // this.previousFour[lastIndex] = currentLocation;
          // lastIndex = (lastIndex + 1)%4;
          try {
            this.mapIntDistribution[newLocation.x][newLocation.y]++;
          } catch (Exception e) {
            this.mapIntDistribution[newLocation.x][newLocation.y] = 1;
          }
          rc.setIndicatorString(0, Arrays.toString(this.previousFour));
          rc.setIndicatorString(1, "locationBeforeMove: " + currentLocation);
          rc.setIndicatorString(2, "to Target Direction: " + toTarget.toString());
          return;
        }
      }
      for (int i = 5; --i >= 0; ) {
        offset = directionOffsets[i];
        potentialDirectionMovement = Direction.values()[(toTarget.ordinal() + offset + 8) % 8];
        if (rc.canMove(potentialDirectionMovement) && !inBattle) {
          newLocation = currentLocation.add(toTarget);
          this.defuseFirstorThenMove(potentialDirectionMovement);
          // this.previousFour[lastIndex] = currentLocation;
          // lastIndex = (lastIndex + 1)%4;
          try {
            this.mapIntDistribution[newLocation.x][newLocation.y]++;
          } catch (Exception e) {
            this.mapIntDistribution[newLocation.x][newLocation.y] = 1;
          }
          rc.setIndicatorString(0, Arrays.toString(this.previousFour));
          rc.setIndicatorString(1, "locationBeforeMove: " + currentLocation);
          rc.setIndicatorString(2, "to Target Direction: " + toTarget.toString());
          return;
        }
      }
    }
  }
 /**
  * helper fcn to see what direction to actually go given a desired direction
  *
  * @param rc
  * @param dir
  * @return
  */
 private static Direction getSpawnDirection(RobotController rc, Direction dir) {
   Direction canMoveDirection = null;
   int desiredDirOffset = dir.ordinal();
   int[] dirOffsets = new int[] {0, 1, -1, 2, -2, 3, -3, 4};
   for (int dirOffset : dirOffsets) {
     Direction currentDirection = Direction.values()[(desiredDirOffset + dirOffset + 8) % 8];
     if (rc.canMove(currentDirection)) {
       if (canMoveDirection == null) {
         canMoveDirection = currentDirection;
       }
       Team mineTeam = rc.senseMine(rc.getLocation().add(currentDirection));
       if (mineTeam == null || mineTeam == rc.getTeam()) {
         // If there's no mine here or the mine is an allied mine, we can spawn here
         return currentDirection;
       }
     }
   }
   // Otherwise, let's just spawn in the desired direction, and make sure to clear out a path later
   return canMoveDirection;
 }
  public static void goAwayFromHQEscapeMines(MapLocation location) throws GameActionException {
    MapLocation currentLocation = rc.getLocation();
    // Find the closest space that doesn't have mines
    for (int i = -3; i <= 3; i++) {
      for (int j = -3; j <= 3; j++) {
        // ignore squares at corners (vision only 14 squared distance)
        if (!((i == -3 || i == 3) && (j == -3 || j == 3))) {
          MapLocation iterLocation = new MapLocation(i + currentLocation.x, j + currentLocation.y);
          Team mineTeam = rc.senseMine(iterLocation);
          if (mineTeam == null) {
            // go to that square
            safeLocationAwayFromHQMines = iterLocation;
            goToLocationDontDefuseOrAvoidMines(iterLocation);
          }
        }
      }
    }

    Direction dir = rc.getLocation().directionTo(location).opposite();
    if (dir != Direction.OMNI) {
      goDirectionAndDontDefuseOrAvoidMines(dir);
    }
  }
  public AI act(RobotController rc) throws Exception {
    Direction d;

    // Check the panic channel.  If we're told to hold, then set
    //  destination to what the channel says and do so.
    if (Clock.getRoundNum() % 15 == 1) {
      if ((panic = radio.read(rc, RadioModule.CHANNEL_PANIC)) != 0) {
        if (panic == 0xFADCAD) {
          nav.setDestination(rc, rc.senseEnemyHQLocation());
        } else {
          target = new MapLocation(panic >>> 7, panic & 0x7F);
          nav.setDestination(rc, target);
        }
      }
    }

    // If there are enemies to fight, fight! Otherwise,
    // continue towards the enemy base
    if (rc.isActive()) {
      if ((d = fight.fightClosestRobot(rc)) == Direction.OMNI) {
        // If we're still holding, let's lay down some mines
        if (panic != 0xFADCAD
            && rc.getLocation().distanceSquaredTo(target) < MINE_DIST
            && rc.senseMine(rc.getLocation()) == null) {
          rc.layMine();
          return this;
        } else {
          d = nav.moveFlock(rc, 2);
        }
      }

      moveSafe(rc, d);
    }

    // Keep the same ai for next round
    return this;
  }
 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();
   }
 }
Exemple #12
0
 public static boolean isEnemyMine(MapLocation loc) {
   return isEnemyMine(RC.senseMine(loc));
 }
 private static boolean hasBadMine(MapLocation location) {
   Team bombTeam = rc.senseMine(location);
   return !(bombTeam == null || bombTeam == rc.getTeam());
 }
  public static void run(RobotController rc) {
    try {
      switch (rc.getType()) {
        case HQ:
          while (true) {

            if (rc.isActive()) {
              Direction dir =
                  rc.getLocation()
                      .directionTo(
                          rc.senseEnemyHQLocation()); // Get the direction to the enemy Base
              MapLocation spawnLocation =
                  rc.getLocation().add(dir); // Get me the next adjacent location in that direction

              // Check to see if there's a mine OR another robot at that location
              while (rc.senseMine(spawnLocation) != null
                  || rc.senseObjectAtLocation(spawnLocation) != null) {
                dir = dir.rotateLeft(); // If so, rotate until we find a direction with no mines
                spawnLocation = rc.getLocation().add(dir);
              }

              rc.spawn(dir); // Spawn a robot in that direction!!
            }

            rc.yield();
          }

        case SOLDIER:
          while (true) {

            if (rc.isActive()) {}

            rc.yield();
          }
        case ARTILLERY:
          while (true) {

            if (rc.isActive()) {}

            rc.yield();
          }

        case GENERATOR:
          while (true) {

            if (rc.isActive()) {}

            rc.yield();
          }

        case MEDBAY:
          while (true) {

            if (rc.isActive()) {}

            rc.yield();
          }

        case SHIELDS:
          while (true) {

            if (rc.isActive()) {}

            rc.yield();
          }

        case SUPPLIER:
          while (true) {

            if (rc.isActive()) {}

            rc.yield();
          }

        default:
          break;
      }
    } catch (Exception e) {
      rc.breakpoint();
      e.printStackTrace();
      // run(rc);
    }
  }
 protected boolean mineHazard(MapLocation location) {
   Team mine = rc.senseMine(location);
   return (mine == Team.NEUTRAL || mine == myTeam.opponent());
 }
Exemple #16
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();
    }
  }