예제 #1
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);
      }
    }
  }
예제 #2
0
  public static void enemyMicro(RobotController rc, RobotInfo bestEnemy)
      throws GameActionException {
    // Prioritize movement
    Direction d = myLoc.directionTo(bestEnemy.location);
    if (rc.isCoreReady()) {
      if (rc.getHealth() > (numEnemySoldiers + 1) * RobotType.SOLDIER.attackPower) {
        // If the enemy can be killed but we're not in range, move forward
        if (!rc.canAttackLocation(bestEnemy.location)
            && bestEnemy.health <= RobotType.SOLDIER.attackPower) {
          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());
          }
          // If not in range, see if we should move in by comparing soldier health
        } else {
          double totalOurSoldierHealth = 0;
          RobotInfo[] allies = rc.senseNearbyRobots(bestEnemy.location, 18, rc.getTeam());
          for (RobotInfo ally : allies) {
            if (ally.type == RobotType.SOLDIER) {
              if (ally.health > numEnemySoldiers * RobotType.SOLDIER.attackPower) {
                totalOurSoldierHealth += ally.health;
              }
            }
          }
          // If we feel that we are strong enough, rush in.
          if (totalOurSoldierHealth > totalEnemySoldierHealth) {
            if (!rc.canAttackLocation(bestEnemy.location)) {
              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());
              }
            }
          } else if (4 * totalOurSoldierHealth < 3 * totalEnemySoldierHealth) {
            if (rc.canMove(d.opposite())) {
              rc.move(d.opposite());
            } else if (rc.canMove(d.opposite().rotateLeft())) {
              rc.move(d.opposite().rotateLeft());
            } else if (rc.canMove(d.opposite().rotateRight())) {
              rc.move(d.opposite().rotateRight());
            }
          }
        }
      }
    }

    // Attack whenever you can
    if (rc.isWeaponReady()) {
      if (rc.canAttackLocation(bestEnemy.location)) {
        broadcastingAttack(rc, bestEnemy);
      }
    }
  }
예제 #3
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();
    }
  }
예제 #4
0
  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());
      }
    }
  }
 /**
  * @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);
     }
   }
 }
예제 #6
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();
     }
   }
 }
예제 #7
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);
    }
  }
예제 #8
0
  // returns true if the robot moved away
  public static boolean moveAwayFromEnemy(RobotController rc) throws GameActionException {
    Team myTeam = rc.getTeam();
    int mySightRange = rc.getType().sensorRadiusSquared;
    MapLocation myLoc = rc.getLocation();
    RobotInfo[] hostiles = rc.senseHostileRobots(myLoc, mySightRange);

    MapLocation closestEnemy = null;
    int closestEnemyDist = 60;
    for (RobotInfo e : hostiles) {
      MapLocation curEnemyLoc = e.location;
      int curDist = myLoc.distanceSquaredTo(curEnemyLoc);
      if (curDist < closestEnemyDist) {
        closestEnemyDist = curDist;
        closestEnemy = e.location;
      }
    }
    if (closestEnemy == null) {
      return false;
    } else {
      Direction dir = getBestMoveableDirection(closestEnemy.directionTo(myLoc), rc, 4);
      if (dir != Direction.NONE) {
        rc.move(dir);
        return true;
      } else {
        return false;
      }
    }
  }
예제 #9
0
 private static void leadZombiesToEnemy(RobotController rc) throws GameActionException {
   // TODO stop anti-kiting
   if (rc.isCoreReady()) {
     if (rc.canMove(Direction.SOUTH_WEST)) {
       rc.move(Direction.SOUTH_WEST);
     }
   }
 }
예제 #10
0
  /*
   * Head towards the nearest tile that we haven't sensed before
   * If there is a tie, pick the one nearest to the hq
   */
  private static void doPatrol() {
    if (!droneCentred) {
      // start point for the spiral is 2/5 of the way from our HQ to their HQ
      MapLocation centre =
          new MapLocation(
              (3 * myHQ.x + 2 * threats.enemyHQ.x) / 5, (3 * myHQ.y + 2 * threats.enemyHQ.y) / 5);
      if (threats.isThreatened(centre) || myLoc.distanceSquaredTo(centre) <= 2) droneCentred = true;
      else {
        moveDir = myLoc.directionTo(centre);
      }
    }

    if (droneCentred && --droneMoveCurrent <= 0) {
      if (patrolClockwise) moveDir = moveDir.rotateRight();
      else moveDir = moveDir.rotateLeft();
      if (!moveDir.isDiagonal()) droneMoveMax++;
      droneMoveCurrent = droneMoveMax;
    }

    while (true) {
      try {
        if (rc.canMove(moveDir) && !threats.isThreatened(myLoc.add(moveDir))) {
          rc.move(moveDir);
          break;
        } else if (rc.canMove(moveDir.rotateLeft())
            && !threats.isThreatened(myLoc.add(moveDir.rotateLeft()))) {
          rc.move(moveDir.rotateLeft());
          break;
        } else if (rc.canMove(moveDir.rotateRight())
            && !threats.isThreatened(myLoc.add(moveDir.rotateRight()))) {
          rc.move(moveDir.rotateRight());
          break;
        } else if (droneCentred) {
          moveDir = moveDir.opposite();
          patrolClockwise = !patrolClockwise;
          if (!moveDir.isDiagonal()) droneMoveMax++;
          droneMoveCurrent = droneMoveMax;
        } else {
          break;
        }
      } catch (GameActionException e) {
        System.out.println("Drone patrol exception");
        // e.printStackTrace();
      }
    }
  }
예제 #11
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);
   }
 }
예제 #12
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;
     }
   }
 }
 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);
     }
   }
 }
예제 #14
0
 private static void simpleMove(Direction chosenDirection) throws GameActionException {
   for (int directionalOffset : directionalLooks) {
     int forwardInt = chosenDirection.ordinal();
     Direction trialDir = allDirections[(forwardInt + directionalOffset + 8) % 8];
     if (rc.canMove(trialDir)) {
       rc.move(trialDir);
       break;
     }
   }
 }
예제 #15
0
  protected boolean trySafeMove(
      Direction direction, RobotInfo[] nearbyEnemies, RobotInfo[] nearbyZombies)
      throws GameActionException {
    MapLocation currentLocation = rc.getLocation();
    MapLocation next = currentLocation.add(direction);
    if (canMoveSafely(direction, next, nearbyEnemies, nearbyZombies)) {
      rc.move(direction);
      return true;
    }

    Direction left = direction.rotateLeft();
    next = currentLocation.add(left);
    if (canMoveSafely(left, next, nearbyEnemies, nearbyZombies)) {
      rc.move(left);
      return true;
    }

    Direction right = direction.rotateRight();
    next = currentLocation.add(right);
    if (canMoveSafely(right, next, nearbyEnemies, nearbyZombies)) {
      rc.move(right);
      return true;
    }

    for (int i = 0; i < 2; i++) {
      left = left.rotateLeft();
      next = currentLocation.add(left);
      if (canMoveSafely(left, next, nearbyEnemies, nearbyZombies)) {
        rc.move(left);
        return true;
      }

      right = right.rotateRight();
      next = currentLocation.add(right);
      if (canMoveSafely(right, next, nearbyEnemies, nearbyZombies)) {
        rc.move(right);
        return true;
      }
    }

    return false;
  }
  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;
        }
      }
    }
  }
예제 #17
0
 private static void moveSoldier(RobotController rc) throws GameActionException {
   // if we have a real current destination
   rc.setIndicatorString(1, "moving somewhere " + currentDestination + rc.getRoundNum());
   if (currentDestination != null) {
     // if bugging is never initialized or we are switching destinations, reinitialize bugging
     if (!currentDestination.equals(storedDestination) || bugging == null) {
       bugging = new Bugging(rc, currentDestination);
       storedDestination = currentDestination;
     }
     // if we are trying to move towards a turret, stay out of range
     if (rc.isCoreReady()) {
       if (currentDestination.equals(nearestTurretLocation)) {
         bugging.turretAvoidMove(turretLocations);
       } else
       // if core is ready, then try to move towards destination
       if (nearestTurretLocation != null) {
         bugging.turretAvoidMove(turretLocations);
       } else {
         bugging.move();
       }
     }
   } else if (nearestArchonLocation
       != null) { // we don't actually have a destination, so we want to try to move towards the
                  // closest archon
     rc.setIndicatorString(
         0, "moving to nearest archon " + nearestArchonLocation + rc.getRoundNum());
     if (!nearestArchonLocation.equals(storedDestination)) {
       bugging = new Bugging(rc, nearestArchonLocation);
       storedDestination = nearestArchonLocation;
     }
     // if core is ready, try to move
     if (rc.isCoreReady() && bugging != null) {
       if (nearestTurretLocation != null) {
         bugging.turretAvoidMove(turretLocations);
       } else if (nearestArchonLocation.equals(bugging.destination)
           && myLoc.distanceSquaredTo(nearestArchonLocation)
               > 13) { // if soldier is far, move towards archon
         bugging.move();
       } else if (nearestArchonLocation.equals(bugging.destination)
           && myLoc.distanceSquaredTo(nearestArchonLocation)
               < 13) { // if soldier is too close, move towards archon
         // try to move away from nearest archon
         if (rc.canMove(nearestArchonLocation.directionTo(myLoc))) {
           rc.move(nearestArchonLocation.directionTo(myLoc));
         }
       }
     }
   } else { // if we literally have nowhere to go
     rc.setIndicatorString(1, "bugging around friendly " + rc.getRoundNum());
     bugAroundFriendly(rc);
   }
 }
예제 #18
0
 public static boolean getToAdjParts(RobotController rc) throws GameActionException {
   if (rc.isCoreReady()) {
     MapLocation myLoc = rc.getLocation();
     MapLocation[] squaresAdj = MapLocation.getAllMapLocationsWithinRadiusSq(rc.getLocation(), 2);
     for (MapLocation sq : squaresAdj) {
       if ((rc.senseParts(sq) > 0) && (rc.canMove(myLoc.directionTo(sq)))) {
         rc.move(myLoc.directionTo(sq));
         return true;
       }
     }
   }
   return false;
 }
예제 #19
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;
       }
     }
   }
 }
예제 #20
0
 private static void goDirectionAvoidMines(Direction dir) throws GameActionException {
   int[] directionOffsets = {0, 1, -1, 2, -2};
   Direction lookingAtCurrently = dir;
   lookAround:
   for (int d : directionOffsets) {
     lookingAtCurrently = Direction.values()[(dir.ordinal() + d + 8) % 8];
     if (rc.canMove(lookingAtCurrently)) {
       if (!badBomb(rc.getLocation().add(lookingAtCurrently))) {
         rc.move(lookingAtCurrently);
         rc.setIndicatorString(0, "Last direction moved: " + lookingAtCurrently.toString());
       }
       break lookAround;
     }
   }
 }
예제 #21
0
  protected void tryMove(Direction direction) throws GameActionException {
    if (rc.canMove(direction)) {
      rc.move(direction);
      return;
    }

    Direction left = direction.rotateLeft();
    if (rc.canMove(left)) {
      rc.move(left);
      return;
    }

    Direction right = direction.rotateRight();
    if (rc.canMove(right)) {
      rc.move(right);
      return;
    }

    for (int i = 0; i < 2; i++) {
      left = left.rotateLeft();
      if (rc.canMove(left)) {
        rc.move(left);
        return;
      }

      right = right.rotateRight();
      if (rc.canMove(right)) {
        rc.move(right);
        return;
      }
    }

    if (rc.getType() != RobotType.TTM) {
      tryClearRubble(direction);
    }
  }
예제 #22
0
 public static boolean moveOrDefuse(Direction dir) throws GameActionException {
   if (rc.isActive()) {
     if (rc.canMove(dir)) {
       if (!hasBadMine(rc.getLocation().add(dir))) {
         rc.move(dir);
         return true;
       } else {
         rc.defuseMine(rc.getLocation().add(dir));
         return false;
       }
     }
     return false;
   }
   return false;
 }
예제 #23
0
  // move in a given direction
  public static void moveInDirection(Direction d) throws GameActionException {
    MapLocation m = rc.getLocation().add(d);

    if (rc.senseRubble(m) < tooMuchRubble
        || Math.random() < probClearRubbleAnyways) // if it's less than 20, just move there
    {
      if (rc.isCoreReady() && rc.canMove(d)) {
        rc.move(d);
      }
    } else // clear it
    {
      if (rc.isCoreReady()) {
        rc.clearRubble(d);
      }
    }
  }
 public void evalMove(MapLocation currentLocation, MapLocation whereToGo)
     throws GameActionException { // New pathing algorithm
   // SHOULD WE CONSIDER NOT MOVING??
   if (rc.isActive()) {
     try {
       this.mapIntDistribution[currentLocation.x][currentLocation.y] += 1;
     } catch (Exception e) {
       this.mapIntDistribution[currentLocation.x][currentLocation.y] = 1;
     }
     int[] dirOffsets = {0, 1, 2, 3, 4, 5, 6, 7};
     int bestScore = -1;
     Direction bestDir = null;
     for (int offset : dirOffsets) {
       Direction dir = Direction.values()[offset];
       if (rc.canMove(dir)) {
         int score =
             this.evalDirection(
                 currentLocation,
                 dir,
                 whereToGo,
                 currentLocation.directionTo(whereToGo),
                 this.movesAway(currentLocation, whereToGo));
         if (bestDir == null) {
           bestScore = score;
           bestDir = dir;
         } else if (score < bestScore) {
           bestScore = score;
           bestDir = dir;
         }
       }
     }
     if (bestDir != null) {
       rc.setIndicatorString(
           0,
           "Best score: "
               + bestScore
               + ", Direction to target: "
               + currentLocation.directionTo(whereToGo));
       MapLocation moveSquare = currentLocation.add(bestDir);
       if (this.mineHazard(moveSquare)) {
         rc.defuseMine(moveSquare);
       } else {
         rc.move(bestDir);
       }
     }
   }
 }
예제 #25
0
 public static void goDirectionAndDefuse(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)) {
         if (hasBadMine(rc.getLocation().add(lookingAtCurrently))) {
           rc.defuseMine(rc.getLocation().add(lookingAtCurrently));
         } else {
           rc.move(lookingAtCurrently);
         }
         break lookAround;
       }
     }
   }
 }
예제 #26
0
  /**
   * Moves rc in direction dir if possible, while attempting to stay out of attack range of hostile
   * robots.
   *
   * @param rc
   * @param dir
   * @throws GameActionException
   */
  private static void moveCautiously(RobotController rc, Direction dir) throws GameActionException {
    if (!rc.isCoreReady()) return;
    final MapLocation myLocation = rc.getLocation();
    final Map<MapLocation, Double> moveLocationsToWeights = new HashMap<>();
    for (MapLocation loc :
        MapLocation.getAllMapLocationsWithinRadiusSq(rc.getLocation(), ONE_SQUARE_RADIUS)) {
      if (loc.equals(rc.getLocation())) {
        continue;
      }
      if (!rc.canMove(myLocation.directionTo(loc))) {
        continue;
      }
      moveLocationsToWeights.put(loc, 1.);
    }

    if (moveLocationsToWeights.size() == 0) {
      return;
    }

    RobotInfo[] enemies = rc.senseHostileRobots(rc.getLocation(), -1);
    for (MapLocation loc : moveLocationsToWeights.keySet()) {
      for (RobotInfo enemy : enemies) {
        if (enemy.weaponDelay < 1
            && enemy.type.attackRadiusSquared >= enemy.location.distanceSquaredTo(loc)) {
          moveLocationsToWeights.put(loc, moveLocationsToWeights.get(loc) + enemy.attackPower);
        }
      }
      moveLocationsToWeights.put(
          loc,
          moveLocationsToWeights.get(loc)
              + distanceFromDirection(dir, myLocation.directionTo(loc)));
    }
    // TODO(remember, though, the enemies will get to move one more time before you do)
    MapLocation bestLocation = moveLocationsToWeights.keySet().iterator().next();
    Double lowestWeight = moveLocationsToWeights.get(bestLocation);
    for (MapLocation loc : moveLocationsToWeights.keySet()) {
      if (moveLocationsToWeights.get(loc) < lowestWeight) {
        lowestWeight = moveLocationsToWeights.get(loc);
        bestLocation = loc;
      }
    }
    rc.move(myLocation.directionTo(bestLocation));
  }
예제 #27
0
  // moves to parts/neutral robots in sight radius
  // returns true if there were parts/neutral robots to go to; else returns false
  public static boolean getToParts(RobotController rc) throws Exception {
    if (rc.isCoreReady()) {
      MapLocation goTo = null;
      MapLocation myLoc = rc.getLocation();
      int sightRadius = rc.getType().sensorRadiusSquared;
      MapLocation[] squaresInSight =
          MapLocation.getAllMapLocationsWithinRadiusSq(rc.getLocation(), sightRadius);
      RobotInfo[] nearbyNeutralRobots = rc.senseNearbyRobots(sightRadius, Team.NEUTRAL);

      // goes to closest parts/neutral robot
      if (nearbyNeutralRobots.length > 0) {
        goTo = nearbyNeutralRobots[0].location;
        for (RobotInfo n : nearbyNeutralRobots) {
          if (myLoc.distanceSquaredTo(n.location) < myLoc.distanceSquaredTo(goTo)) {
            goTo = n.location;
          }
        }
      }
      for (MapLocation sq : squaresInSight) {
        if ((rc.senseParts(sq) > 0) && (goTo != null)) {
          if (myLoc.distanceSquaredTo(sq) < myLoc.distanceSquaredTo(goTo)) {
            goTo = sq;
          }
        }
      }
      if (goTo != null) {
        MapLocation curLoc = rc.getLocation();
        Direction dirToGo = curLoc.directionTo(goTo);
        if (rc.canMove(dirToGo)) {
          rc.move(dirToGo);
          return true;
        } else {
          return false;
        }
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
예제 #28
0
  /*
   * Beavers and miners without ore do this
   */
  private static void doSearchMove() {
    // We keep moving in the direction we were going
    // When blocked we turn left or right depending on our unique ID

    rc.setIndicatorString(2, "Mining: No ore - searching");
    if (lastMove == null || rand.nextInt(10) == 1)
      lastMove = directions[rand.nextInt(directions.length)];

    Direction startDir = lastMove;
    while (!rc.canMove(lastMove) || threats.isThreatened(myLoc.add(lastMove))) {
      if (rc.getID() % 2 == 0) lastMove = lastMove.rotateLeft();
      else lastMove = lastMove.rotateRight();
      if (lastMove == startDir) // We are trapped
      return;
    }
    try {
      rc.move(lastMove);
    } catch (GameActionException e) {
      System.out.println("Move exception");
      // e.printStackTrace();
    }
  }
예제 #29
0
 public static void goDirectionAvoidMines(Direction dir) throws GameActionException {
   if (rc.isActive()) {
     Direction lookingAtCurrently = dir;
     boolean movedYet = false;
     lookAround:
     for (int d : directionOffsets) {
       lookingAtCurrently = Direction.values()[(dir.ordinal() + d + 8) % 8];
       if (rc.canMove(lookingAtCurrently) && rc.isActive()) {
         if (!hasBadMine(rc.getLocation().add(lookingAtCurrently))) {
           movedYet = true;
           rc.move(lookingAtCurrently);
         }
         break lookAround;
       }
       if (!movedYet) { // if the robot still hasn't moved
         if (rc.senseNearbyGameObjects(Robot.class, 2, rc.getTeam().opponent()).length == 0) {
           // if there are no nearby enemies
           rangedDefuseMine();
         }
       }
     }
   }
 }
예제 #30
0
  /**
   * Checks if rc can move in direction dir (runs isCoreReady and canMove). If so, moves. If not,
   * moves rc in any of the four directions nearest dir, if possible.
   *
   * @param rc
   * @param dir
   * @return true if rc moves else false
   * @throws GameActionException
   */
  private static void moveTowards(RobotController rc, Direction dir) throws GameActionException {
    if (rc.isCoreReady() && !dir.equals(Direction.OMNI) && !dir.equals(Direction.NONE)) {
      Direction[] moveRight = {
        dir,
        dir.rotateRight(),
        dir.rotateLeft(),
        dir.rotateRight().rotateRight(),
        dir.rotateLeft().rotateLeft()
      };
      Direction[] moveLeft = {
        dir,
        dir.rotateLeft(),
        dir.rotateRight(),
        dir.rotateLeft().rotateLeft(),
        dir.rotateRight().rotateRight()
      };
      Direction[] nearDirections =
          Math.random() >= .5
              ? moveRight
              : moveLeft; // 50% chance robot tries to move to right first

      for (Direction nearDir : nearDirections) {
        if (rc.canMove(nearDir) && rc.isCoreReady()) {
          rc.move(nearDir);
        }
      }
      if (rc.getType() != RobotType.TTM
          && rc.getType() != RobotType.TTM) // these types can't clear rubble
      {
        if (rc.isCoreReady()
            && rc.onTheMap(rc.getLocation().add(dir))
            && rc.senseRubble(rc.getLocation().add(dir)) > RUBBLE_LOWER_CLEAR_THRESHOLD) {
          clearRubble(rc);
        }
      }
    }
  }