示例#1
0
  private boolean spawn() throws GameActionException {

    Direction dir = rc.getLocation().directionTo(rc.senseEnemyHQLocation());

    // Need to do this first so the termination check works
    if (rc.canMove(dir)) {
      rc.spawn(dir);
      return true;
    }
    // Spawn as close to the desired direction as possible
    Direction dirLeft = dir;
    Direction dirRight = dir;

    do {
      dirLeft = dirLeft.rotateLeft();
      if (rc.canMove(dirLeft)) {
        rc.spawn(dirLeft);
        return true;
      }

      dirRight = dirRight.rotateRight();
      if (rc.canMove(dirRight)) {
        rc.spawn(dirRight);
        return true;
      }

    } while (dirRight != dirLeft);

    return false;
  }
示例#2
0
  private boolean isOpen(
      MapLocation currentLoc,
      Direction currentDir,
      Direction nextDir,
      Direction desDir,
      boolean cw) {
    if (desDir == Direction.OMNI) {
      return true;
    }

    if (!isTraversable(currentLoc.add(currentDir))) return false;

    if (cw) {
      while (currentDir != nextDir) {
        if (currentDir == desDir) return true;
        currentDir = currentDir.rotateRight();
      }
    } else {
      while (currentDir != nextDir) {
        if (currentDir == desDir) return true;
        currentDir = currentDir.rotateLeft();
      }
    }
    return (nextDir == desDir);
  }
示例#3
0
 private static void doMinerMove() {
   // If there is an available adjacent tile with twice as much ore we are better off moving
   Direction startDir = directions[rand.nextInt(directions.length)];
   Direction d = startDir;
   Direction best = Direction.NONE;
   double mostOre = rc.senseOre(myLoc) * 2; // Only move if there is twice as much ore
   boolean done = false;
   while (!done) {
     if (rc.canMove(d)) {
       MapLocation adj = rc.getLocation().add(d);
       double ore = rc.senseOre(adj);
       if ((ore > mostOre
               || (ore == mostOre
                   && ore > 0
                   && adj.distanceSquaredTo(myHQ) > myLoc.distanceSquaredTo(myHQ)))
           && !threats.isThreatened(adj)) {
         mostOre = rc.senseOre(adj);
         best = d;
       }
     }
     d = d.rotateRight();
     done = (d == startDir);
   }
   if (best != Direction.NONE) {
     rc.setIndicatorString(2, "Mining - better ore " + d);
     try {
       rc.move(best);
     } catch (GameActionException e) {
       System.out.println("Miner move exception");
       // e.printStackTrace();
     }
   }
 }
示例#4
0
  private MapLocation traceNext(MapLocation currentLoc, Direction faceDir, boolean cw) {

    // Put isTraversable first so that the second while loop will rotate the
    // direction to walkable position
    // Try code reuse in the future

    int step = 0;

    if (cw) {
      while (isTraversable(currentLoc.add(faceDir)) && step < 8) {
        faceDir = faceDir.rotateRight();
        step++;
      }
      step = 0;
      while (!isTraversable(currentLoc.add(faceDir)) && step < 8) {
        faceDir = faceDir.rotateLeft();
        step++;
      }
    } else {
      while (isTraversable(currentLoc.add(faceDir)) && step < 8) {
        faceDir = faceDir.rotateLeft();
        step++;
      }
      step = 0;
      while (!isTraversable(currentLoc.add(faceDir)) && step < 8) {
        faceDir = faceDir.rotateRight();
        step++;
      }
    }

    return currentLoc.add(faceDir);
  }
示例#5
0
  private boolean moveToPath() throws GameActionException {
    if (dstar == null) {
      dstar = new DStar(outPath, distances, currentLocation);
    }

    if (!dstar.arrived(currentLocation)) {
      dstar.compute(7000);
    }

    if (!RC.isActive()) return true;

    Direction dir = Direction.NORTH, best = null;
    int min = Integer.MAX_VALUE;
    for (int i = 0; i < 8; i++) {

      int d = RC.canMove(dir) ? dstar.getDistance(currentLocation.add(dir)) : Integer.MAX_VALUE;
      if (d < min) {
        min = d;
        best = dir;
      }
      dir = dir.rotateRight();
    }

    if (best != null && move(best)) {
      RC.setIndicatorString(1, "Moving to outPath");
      return true;
    } else {
      return false;
    }
  }
示例#6
0
 private static void shootRandomly() throws GameActionException {
   if (rc.getRoundNum() > 500) {
     Direction trueAway = alpha.directionTo(here);
     Direction away = trueAway;
     MapLocation enemyLocation = here;
     int count = 0;
     while (count < 4 || rc.canAttackLocation(enemyLocation.add(away))) {
       enemyLocation = enemyLocation.add(away);
       away =
           (new Direction[] {
                 trueAway,
                 trueAway.rotateLeft(),
                 trueAway.rotateRight(),
                 trueAway.rotateLeft().rotateLeft(),
                 trueAway.rotateRight().rotateRight()
               })
               [rand.nextInt(5)];
       count++;
       if (rc.canSenseLocation(enemyLocation) && !rc.onTheMap(enemyLocation)) {
         return;
       }
     }
     if (rc.canAttackLocation(enemyLocation)) {
       rc.attackLocation(enemyLocation);
       return;
     }
   }
 }
  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);
      }
      //			}
    }
  }
示例#8
0
  // In this function the HQ spawns a soldier ideally toward the enemy base but in any direction
  // otherwise
  public static void SpawnSoldiers(RobotController rc) {
    try {
      if (rc.isActive() && rc.getType() == RobotType.HQ) {
        Direction toEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
        if (rc.senseObjectAtLocation(rc.getLocation().add(toEnemy)) == null) {
        } else {
          for (int i = 0; i < 7; i++) {
            toEnemy = toEnemy.rotateLeft();

            if (rc.senseObjectAtLocation(rc.getLocation().add(toEnemy)) == null) {
              i = 47;
            } else if (i == 6) {
              toEnemy = Direction.NONE;
            }
          }
        }

        if (toEnemy != Direction.NONE) {
          if (rc.isActive()) {
            if (rc.getType() == RobotType.HQ) {
              rc.spawn(toEnemy);
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Utility Exception");
    }
  }
示例#9
0
  /**
   * Attempts to build a robot of the given type in a random direction (attempts all directions).
   * Only attempts building if rc has no core delay and has more parts than the threshold.
   *
   * @param rc RobotController from which to build
   * @param buildType type of robot to build
   * @return true if buildType is built else false
   * @throws GameActionException
   */
  private static boolean tryToBuild(RobotController rc, RobotType buildType)
      throws GameActionException {
    if (rc.isCoreReady()) {
      Direction buildDir = getRandomDirection();
      for (int i = 0; i < 8; i++) {
        if (rc.canBuild(buildDir, buildType)) {
          rc.build(buildDir, buildType);
          rc.broadcastMessageSignal(SENDING_MODE, currentMode, ONE_SQUARE_RADIUS);

          if (!turtleCorner.equals(LOCATION_NONE)) {
            rc.broadcastMessageSignal(SENDING_TURTLE_X, turtleCorner.x, ONE_SQUARE_RADIUS);
            rc.broadcastMessageSignal(SENDING_TURTLE_Y, turtleCorner.y, ONE_SQUARE_RADIUS);
          }

          if (buildType.equals(RobotType.SCOUT)) {
            for (MapLocation scoutKitingLoc : SCOUT_KITING_LOCATIONS) {
              rc.broadcastMessageSignal(
                  SENDING_SCOUT_KITING_LOCATION_X, scoutKitingLoc.x, ONE_SQUARE_RADIUS);
              rc.broadcastMessageSignal(
                  SENDING_SCOUT_KITING_LOCATION_Y, scoutKitingLoc.y, ONE_SQUARE_RADIUS);
            }
          }
          return true;
        }
        buildDir = buildDir.rotateRight(); // try all directions clockwise
      }
    }
    return false;
  }
  public static void go_towards_destination() throws GameActionException {
    if (!rc.isCoreReady()) return;

    if (destination == null || destination.equals(current_location)) {
      dig(destination);
      return;
    }

    combat_mode = false;

    if (life_insurance_policy == Safety.KITE) combat_mode = true;

    // TODO alter try directions so we use non-diagonal if possible.
    Direction direction_to_head = current_location.directionTo(destination);
    for (int offset : (combat_mode ? combat_directions : try_directions)) {
      Direction try_to_walk = Direction.values()[(direction_to_head.ordinal() + offset + 8) % 8];
      if (rc.canMove(try_to_walk)) {
        if (life_insurance_policy.says_this_move_will_shorten_your_life(
            current_location.add(try_to_walk))) continue;
        previous_location = current_location;
        if (rc.canMove(try_to_walk)) {
          rc.move(try_to_walk);
        } else {
          System.out.println("Running over byte limit");
        }
        return;
      }
    }
    dig(destination);
  }
示例#11
0
  private static void archonMicro(RobotController rc, RobotInfo enemyArchon)
      throws GameActionException {
    if (rc.isCoreReady()) {
      int dist = myLoc.distanceSquaredTo(enemyArchon.location);
      // When not adjacent to the archon, walk/mine through to him.
      if (dist > 2) {
        Direction desired = myLoc.directionTo(enemyArchon.location);
        Direction dir = Movement.getBestMoveableDirection(desired, rc, 2);
        if (dir != Direction.NONE) {
          rc.move(dir);
        } else if (shouldMine(rc, desired)) {
          rc.clearRubble(desired);
        } else if (shouldMine(rc, desired.rotateLeft())) {
          rc.clearRubble(desired.rotateLeft());
        } else if (shouldMine(rc, desired.rotateRight())) {
          rc.clearRubble(desired.rotateRight());
        }
      }
      // When adjacent to archon, rotate to the left/right when possible.
      else {
        Direction dir = myLoc.directionTo(enemyArchon.location);
        if (rc.canMove(dir.rotateLeft())) {
          rc.move(dir.rotateLeft());
        } else if (rc.canMove(dir.rotateRight())) {
          rc.move(dir.rotateRight());
        }
      }
    }

    if (rc.isWeaponReady()) {
      if (rc.canAttackLocation(enemyArchon.location)) {
        rc.attackLocation(enemyArchon.location);
      }
    }
  }
示例#12
0
  public static void moveCloserFavorNoMines() throws GameActionException {
    Direction dir = rc.getLocation().directionTo(destination);
    double distance = rc.getLocation().distanceSquaredTo(destination);
    double currDist;
    if (rc.canMove(dir) && !hasBadMine(rc.getLocation().add(dir))) {
      rc.move(dir);
    } else {
      Direction bestDir = dir;
      Direction currentDir = dir;
      for (int directionOffset : directionOffsets) {
        if (directionOffset != 0) {
          currentDir = Direction.values()[(dir.ordinal() + directionOffset + 8) % 8];
          if (rc.canMove(currentDir) && !hasBadMine(rc.getLocation().add(currentDir))) {
            currDist = rc.getLocation().add(currentDir).distanceSquaredTo(destination);
            if (currDist < distance) {
              distance = currDist;
              bestDir = currentDir;
            }
          }
        }
      }

      NavSystem.moveOrDefuse(bestDir);
    }
  }
 /**
  * @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 int evalDirection(
      MapLocation currentLocation,
      Direction dir,
      MapLocation goal,
      Direction dirToGoal,
      int currentMovesToGoal) {
    boolean hasDefusion = rc.hasUpgrade(Upgrade.DEFUSION);
    MapLocation square = currentLocation.add(dir);

    int directionPenalty;
    int dirDiff = Math.abs(dir.ordinal() - dirToGoal.ordinal());
    if (dirDiff <= 2) {
      directionPenalty = this.movesAway(square, goal) - currentMovesToGoal;
    } else {
      directionPenalty = hasDefusion ? 5 : 12;
    }
    int minePenalty;
    if (hasDefusion) {
      minePenalty = this.mineHazard(square) ? 5 : 0;
    } else {
      minePenalty = this.mineHazard(square) ? 12 : 0;
    }
    int visitPenalty = 2 * this.mapIntDistribution[square.x][square.y] * (hasDefusion ? 5 : 12);
    return directionPenalty + minePenalty + visitPenalty;
  }
示例#15
0
  public static boolean goToLocation(MapLocation whereToGo, boolean defuseMines)
      throws GameActionException {
    int dist = mRC.getLocation().distanceSquaredTo(whereToGo);
    // TODO if its an hq and stuff is in the way you gotta kill it
    if (mRC.isActive() && dist > 0) {
      Direction dir = mRC.getLocation().directionTo(whereToGo);
      for (int d : Constants.testDirOrderFrontSide) {
        Direction lookingAtCurrently = Direction.values()[(dir.ordinal() + d + NUM_DIR) % NUM_DIR];
        MapLocation newLoc = mRC.getLocation().add(lookingAtCurrently);
        Team mineOwner = mRC.senseMine(newLoc);
        boolean shouldDefuseEnemyMine = Math.random() < CHANCE_OF_DEFUSING_ENEMY_MINE;
        if (mRC.canMove(lookingAtCurrently)
            && (defuseMines || !isMineDir(mRC.getLocation(), lookingAtCurrently, true))) {

          if (mineOwner != null && mineOwner != mRC.getTeam()) {
            mRC.defuseMine(newLoc);
          } else {
            mRC.move(lookingAtCurrently);
          }
          return true;
        } else if (mRC.canMove(lookingAtCurrently)
            && isMineDir(mRC.getLocation(), lookingAtCurrently, true)
            && mineOwner == mRC.getTeam().opponent()
            && shouldDefuseEnemyMine) {
          mRC.defuseMine(newLoc);
          return true;
        }
      }
    }
    return false;
  }
  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());
      }
    }
  }
示例#17
0
 /**
  * Goes through a list of adjacent locations. If a wall is detected, robot tries to move away from
  * it.
  *
  * @param rc
  * @throws GameActionException
  */
 private static void moveAwayFromWalls(RobotController rc) throws GameActionException {
   MapLocation myLocation = rc.getLocation();
   for (Direction dir : DIRECTIONS) {
     if (!rc.onTheMap(myLocation.add(dir)) && rc.isCoreReady()) {
       moveTowards(rc, dir.opposite());
     }
   }
 }
示例#18
0
  public static void goToGoal(
      Direction movingDirection, boolean greaterAttackForce, int numAllAllies)
      throws GameActionException {

    // forwardish(randomDirection());
    if (RobotPlayer.soldierLeader) {
      RobotPlayer.rc.setIndicatorString(2, "I am a leader about to move");
      if (numAllAllies > 7 && greaterAttackForce) {
        RobotPlayer.rc.setIndicatorString(2, "I am a leader with a strong force");
        forwardish(movingDirection);
      } else if (greaterAttackForce) {
        // TODO what to do with small groups?
        RobotPlayer.rc.setIndicatorString(2, "I am a leader with a  larger force");
        if (RobotPlayer.rc.getRoundNum() % 8 == 0) forwardish(movingDirection);
      } else {
        RobotPlayer.rc.setIndicatorString(2, "greater attack force? " + greaterAttackForce);
        if (RobotPlayer.rc.getRoundNum() % 5 == 0) {
          RobotPlayer.movingDirection = movingDirection.rotateRight();
          forwardish(RobotPlayer.movingDirection);
        }
      }

    } else if (RobotPlayer.rc.getType() == RobotType.SOLDIER) {
      if (greaterAttackForce || RobotPlayer.haveLeader) {
        forwardish(movingDirection); // keep going where we are going
      } else {
        forwardish(
            movingDirection
                .rotateRight()); // wiat for leader, turn (should i go in random direction?)
      }
    } else if (RobotPlayer.rc.getType() == RobotType.GUARD) {
      if (greaterAttackForce || RobotPlayer.haveLeader) {
        forwardish(movingDirection); // keep going where we are going
      } else {
        forwardish(
            movingDirection
                .rotateRight()); // wiat for leader, turn (should i go in random direction?)
      }
    }
    // else {
    //
    //			if (greaterAttackForce){
    //				forwardish(movingDirection);//keep going where we are going
    //			}
    //
    //			forwardish(randomDirection());//wiat for leader, go in random direction
    ////			forwardish(movingDirection);
    //		}
    //		//			else if(RobotPlayer.haveLeader){
    //		//
    //		//		}else{
    //
    //
    //
    //		//}

  }
示例#19
0
 public static Direction[] bestDir(Direction dir) {
   Direction[] bestDir = {
     dir,
     dir.rotateLeft(),
     dir.rotateRight(),
     dir.rotateLeft().rotateLeft(),
     dir.rotateRight().rotateRight()
   };
   return bestDir;
 }
示例#20
0
 protected void forwardish(Direction ahead) throws GameActionException {
   // System.out.println(ahead);
   for (int i : RobotConstants.posDirs) {
     Direction candidateDir = Direction.values()[(ahead.ordinal() + i + 8) % 8];
     if (rc.canMove(candidateDir)) {
       rc.move(candidateDir);
       break;
     }
   }
 }
示例#21
0
 public static void spawnRobot() throws GameActionException {
   Direction tempDir = null;
   for (int i = 0; i < NUM_DIR; ++i) {
     tempDir = Direction.values()[(enHQDir.ordinal() + i + NUM_DIR) % NUM_DIR];
     if (mRC.canMove(tempDir)) {
       mRC.spawn(tempDir);
       break;
     }
   }
 }
示例#22
0
  public Direction Bug(MapLocation s, MapLocation t, int tolerance) {

    // arrive the destination
    if (s.distanceSquaredTo(t) <= tolerance) {
      reset();
      return Direction.OMNI;
    }

    Direction nextDir;
    Direction faceDir = controllers.myRC.getDirection();

    // if target is not traversable, back-tracing the destination
    while (!isTraversable(t)) {
      nextDir = s.directionTo(t);
      t = t.subtract(nextDir);

      // beside the source
      if (s.distanceSquaredTo(t) <= tolerance) {
        reset();
        return Direction.OMNI;
      }
    }

    modifiedDes = t;

    Direction desDir = s.directionTo(t);
    MapLocation nextLoc;

    if (isTracing) {

      Direction startTracingDir =
          isCW ? faceDir.rotateRight().rotateRight() : faceDir.rotateLeft().rotateLeft();
      nextLoc = traceNext(s, startTracingDir, isCW);
      nextDir = s.directionTo(nextLoc);

      // The way is open
      if (isOpen(s, faceDir, nextDir, desDir, isCW) && isTraversable(s.add(desDir))) {
        isTracing = false;
        return desDir;
      }

      return nextDir;

    } else {
      if (isTraversable(s.add(desDir))) {
        return desDir;
      } else {
        isTracing = true;
        isCW = betterTracingWay(s, t);
        nextLoc = traceNext(s, desDir, isCW);

        return s.directionTo(nextLoc);
      }
    }
  }
示例#23
0
 public static Direction getBestMoveableDirection(Direction dir, RobotController rc, int fan) {
   int ordinal = dir.ordinal();
   for (int i = 0; i < 2 * fan + 1; i++) {
     int disp = ((i % 2) * 2 - 1) * (i + 1) / 2;
     Direction testDir = Direction.values()[mod8(ordinal + disp)];
     if (rc.canMove(testDir)) {
       return testDir;
     }
   }
   return Direction.NONE;
 }
 private Direction getSpawnDir() {
   Direction directDir = this.getDirectSpawnDir();
   int[] spawningOffsets = {0, 1, -1, 2, -2, 3, -3, 4};
   for (int offset : spawningOffsets) {
     Direction potentialSpawnDir = Direction.values()[(directDir.ordinal() + offset + 8) % 8];
     MapLocation potentialSpawnLocation = this.currentLocation.add(potentialSpawnDir);
     if (rc.canMove(potentialSpawnDir) && !this.mineHazard(potentialSpawnLocation)) {
       return potentialSpawnDir;
     }
   }
   return null;
 }
示例#25
0
  private static void runMissile() {
    int lastTurn = Clock.getRoundNum() + GameConstants.MISSILE_LIFESPAN;
    int[] damageRange = {0, 8, 15, 24, 35, 48};
    MapLocation target = null;
    boolean targetMoves = true;

    while (true) {
      myLoc = rc.getLocation();
      int turns = lastTurn - Clock.getRoundNum();

      if (targetMoves) { // Re-acquire the target's location
        RobotInfo[] inRange = rc.senseNearbyRobots(damageRange[turns], enemyTeam);
        if (inRange.length > 0) { // No units to target
          target = inRange[0].location;
          targetMoves = inRange[0].type.canMove();
          rc.setIndicatorString(0, "Missile targetting " + inRange[0].type + "@" + target);
        } else {
          targetMoves = false; // Pick a tower or the HQ
          MapLocation[] enemyTowers = rc.senseEnemyTowerLocations();
          for (MapLocation t : enemyTowers) {
            if (myLoc.distanceSquaredTo(t) <= damageRange[turns]) {
              target = t;
              rc.setIndicatorString(0, "Missile targetting Tower @" + target);
              break;
            }
          }
          if (target == null) {
            target = rc.senseEnemyHQLocation();
            rc.setIndicatorString(0, "Missile targetting HQ @" + target);
          }
        }
      }

      try {
        if (target != null) {
          if (myLoc.distanceSquaredTo(target) <= GameConstants.MISSILE_RADIUS_SQUARED) rc.explode();
          else {
            Direction d = myLoc.directionTo(target);
            if (rc.canMove(d)) rc.move(d);
            else if (rc.canMove(d.rotateLeft())) rc.move(d.rotateLeft());
            else if (rc.canMove(d.rotateRight())) rc.move(d.rotateRight());
          }
        }
      } catch (GameActionException e) {
        System.out.println("Missile exception");
        // e.printStackTrace();
      }
      rc.yield();
    }
  }
  public static void clear_rubble() throws GameActionException {
    if (!rc.isCoreReady()) return;
    if (Scanner.can_see_targets()) return;
    if (Scanner.there_is_hidden_enemy()) return;

    Direction direction_to_clear = current_location.directionTo(destination);

    if (direction_to_clear == Direction.NONE || direction_to_clear == Direction.OMNI) return;

    if (rc.senseRubble(current_location.add(direction_to_clear)) < 1) return;

    rc.clearRubble(direction_to_clear);
    rc.setIndicatorString(1, "Clearing: " + direction_to_clear.toString());
  }
示例#27
0
 public static void goDirectionAndDontDefuseOrAvoidMines(Direction dir)
     throws GameActionException {
   if (rc.isActive()) {
     Direction lookingAtCurrently = dir;
     lookAround:
     for (int d : directionOffsets) {
       lookingAtCurrently = Direction.values()[(dir.ordinal() + d + 8) % 8];
       if (rc.isActive() && rc.canMove(lookingAtCurrently)) {
         rc.move(lookingAtCurrently);
         break lookAround;
       }
     }
   }
 }
示例#28
0
文件: Mover.java 项目: jalman/armada
  /**
   * Try to move.
   *
   * @param sneak:
   * @return
   */
  public void execute(int sneak) {
    // int bc = Clock.getBytecodesLeft();
    // RC.setIndicatorString(1, "my x = " + Integer.toString(RC.getLocation().x) + ", my y = " +
    // Integer.toString(RC.getLocation().y)
    // + "x = " + Integer.toString(dest.x) + ", y = " + Integer.toString(dest.y));
    // RC.setIndicatorString(2, Clock.getRoundNum() + " | dest = " + dest + ", navtype = " +
    // navType);

    if (arrived()) return;

    if (RC.isActive()) {
      Direction d;
      d = navAlg.getNextDir();
      if (d != null && d != Direction.NONE && d != Direction.OMNI) {
        if (RC.canMove(d)) {
          try {
            switch (sneak) {
              case SNEAK:
                // RC.setIndicatorString(2, dest.x + ", " + dest.y + ": sneak");
                RC.sneak(d);
                break;
              case RUN:
                // RC.setIndicatorString(2, dest.x + ", " + dest.y + ": run");
                RC.move(d);
                break;
              case PUSH_HOME:
                // RC.setIndicatorString(2, dest.x + ", " + dest.y + ": push_home");
                Direction awayFromHome = currentLocation.directionTo(ALLY_HQ).opposite();
                if (d == awayFromHome
                    || d == awayFromHome.rotateLeft()
                    || d == awayFromHome.rotateRight()) {
                  RC.sneak(d);
                } else {
                  RC.move(d);
                }
                break;
              default:
                break;
            }
          } catch (GameActionException e) {
            e.printStackTrace();
          }
        } else if (currentLocation.distanceSquaredTo(dest) <= 2) {
          setTarget(currentLocation);
        }
      }
    }
    // System.out.println("Bytecodes used by Mover.execute() = " +
    // Integer.toString(bc-Clock.getBytecodesLeft()));
  }
示例#29
0
 /////////////////////////////////////////////////////////////
 // moveAway()
 //
 private static boolean moveAway(MapLocation center) throws GameActionException {
   while (!rc.isCoreReady()) {
     Clock.yield();
   }
   Direction dir = center.directionTo(rc.getLocation());
   int c = 0;
   while (!rc.canMove(dir)) {
     dir = dir.rotateRight();
     c++;
     if (c >= 4) return false;
   }
   rc.move(dir);
   return true;
 }
示例#30
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;
  }