Пример #1
0
 private static void turret(RobotController rc) {
   // do one time things here
   turtleCorner = turtleCorner == null ? LOCATION_NONE : turtleCorner;
   try {
     RobotInfo[] friendlyRobots =
         rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam());
     if (rc.getHealth() <= 3 && rc.isInfected() && friendlyRobots.length > 0) {
       rc.disintegrate();
     }
     turretAttack(rc);
     processFighterSignals(rc);
     if ((archonIsTooClose(rc) || isAdjacentToWall(rc))
         && rc.getType() == RobotType.TURRET
         && rc.isCoreReady()) {
       rc.pack();
     }
     if (turtleCorner != LOCATION_NONE && rc.isCoreReady() && rc.getType() == RobotType.TURRET) {
       int minCornerRadius = (20 + (rc.getRobotCount() / 10));
       if (rc.getLocation().distanceSquaredTo(turtleCorner) < minCornerRadius) {
         rc.pack();
       }
     }
     rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
     rc.setIndicatorString(1, "I am a turret");
     // if (turtleCorner.equals(LOCATION_NONE)) tryToLocateCorner(rc);
     Clock.yield();
   } catch (GameActionException e) {
     e.printStackTrace();
   }
 }
Пример #2
0
 /**
  * Working on soldier behavior: 1) If about to die and infected and senses nearby friendly robots,
  * self destruct 2) Attack if possible 3) Process signals. (If another soldier signals, move
  * towards that soldier (means there is a zombie den nearby)) 4) Move away from walls / archons 5)
  * Use position and relative position to turtle corner to move away or toward turtle corner 6) Try
  * to clear surrounding rubble
  *
  * @param rc
  */
 private static void soldier(RobotController rc) {
   turtleCorner = LOCATION_NONE;
   while (true) {
     try {
       // 1)
       RobotInfo[] friendlyRobots =
           rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam());
       if (rc.getHealth() <= 3 && rc.isInfected() && friendlyRobots.length > 0) {
         rc.disintegrate();
       } else {
         // 2)
         attackFirst(rc);
         // 3)
         processFighterSignals(rc);
         // 4)
         moveAwayFromArchons(rc);
         moveAwayFromWalls(rc);
         // 5)
         if (!turtleCorner.equals(LOCATION_NONE)) {
           moveFromCorner(rc);
         } else if (currentMode == TRANSITION_MODE) {
           moveTowardsArchon(rc);
         }
         // 6)
         clearRubble(rc);
         //					if(turtleCorner.equals(LOCATION_NONE)) tryToLocateCorner(rc);
       }
       rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
       rc.setIndicatorString(1, "Current Mode" + currentMode);
       Clock.yield();
     } catch (GameActionException e) {
       e.printStackTrace();
     }
   }
 }
Пример #3
0
 /**
  * 1) process signals, try to find turtleCorner 2) if enemies are within sensing radius, unpack 3)
  * if too close to archons, move away 4) if too close to wall, move away 5) if too close to
  * corner, move away 6) if it did nothing, unpack
  *
  * @param rc
  */
 private static void ttm(RobotController rc) {
   turtleCorner = turtleCorner.equals(null) ? LOCATION_NONE : turtleCorner;
   try {
     RobotInfo[] friendlyRobots =
         rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam());
     if (rc.getHealth() <= 3 && rc.isInfected() && friendlyRobots.length > 0) {
       rc.disintegrate();
     }
     // 1)
     if (isNearbyEnemies(rc) && rc.isCoreReady()) {
       rc.unpack();
     }
     // 2)
     processFighterSignals(rc);
     // 3)
     moveAwayFromArchons(rc);
     // 4)
     moveAwayFromWalls(rc);
     // 5)
     if (turtleCorner != LOCATION_NONE) moveFromCorner(rc);
     // 6)
     if (rc.isCoreReady() && rc.getType() == RobotType.TTM && rc.getRoundNum() % 25 == 0)
       rc.unpack();
     rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
     rc.setIndicatorString(1, "I am a TTM!");
     Clock.yield();
   } catch (GameActionException e) {
     e.printStackTrace();
   }
 }
Пример #4
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);
   }
 }
Пример #5
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();
    }
  }
Пример #6
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());
      }
    }
  }
Пример #7
0
 public static void setRetreatingStatus(RobotController rc, RobotInfo[] hostiles)
     throws GameActionException {
   // Retreating is when your first hit less than a third health or when you were retreating
   // already and is not max health yet.
   // But you should not be retreating if you are infected. That's not a good idea!
   healing =
       (3 * rc.getHealth() < RobotType.SOLDIER.maxHealth
               || (wasHealing && rc.getHealth() < RobotType.SOLDIER.maxHealth))
           && (rc.getHealth() > 2 * rc.getViperInfectedTurns());
   if (!healing) {
     if (wasHealing) bugging = null;
     wasHealing = false;
   }
   if (healing) {
     RobotInfo[] nearbyRobots = rc.senseNearbyRobots(sightRadius, myTeam);
     for (RobotInfo r : nearbyRobots) {
       if (r.type == RobotType.ARCHON) nearestArchonLocation = r.location;
     }
     rc.setIndicatorString(0, "should be retreating " + nearestArchonLocation + rc.getRoundNum());
     if (!wasHealing || !bugging.destination.equals(nearestArchonLocation)) {
       if (nearestArchonLocation == null) {
         bugging = new Bugging(rc, rc.getLocation().add(Direction.EAST));
       } else {
         bugging = new Bugging(rc, nearestArchonLocation);
       }
     }
     wasHealing = true;
   }
 }
 /**
  * @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 yield() {
    if (my_type == RobotType.ARCHON) rc.setIndicatorString(0, "Beta 1.5");

    if (rc.getRoundNum() % 25 == 0) Scanner.reset_health();

    Clock.yield();
  }
Пример #10
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();
     }
   }
 }
Пример #11
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();
    }
  }
Пример #12
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);

  }
Пример #13
0
  /*
   * Moves towards the nearest enemy
   * Returns true if we moved or are in the right place
   */
  private static boolean doCloseWithEnemyMove(boolean ignoreThreat) {
    // Move to within attack range of the nearest enemy - ignore towers and HQ until later in the
    // game
    // We can move in closer if we are still out of range of the enemy
    RobotInfo nearest = null;
    RobotInfo preferred = null;
    RobotInfo[] enemies = rc.senseNearbyRobots(senseRange * 16, enemyTeam);
    boolean canFly = (myType == RobotType.DRONE);

    int now = Clock.getRoundNum();
    for (RobotInfo e : enemies) {
      // We want to find and circle units, not towers or HQ (until later in the game)
      if (now < maxRounds / 2 && (e.type == RobotType.HQ || e.type == RobotType.TOWER)) continue;
      // Drones on VOID tiles cannot be reached by ground troops - ignore them
      if (!canFly && rc.senseTerrainTile(e.location) != TerrainTile.NORMAL) continue;
      // Commanders are good at picking off miners, beavers and non combat buildings - have a
      // preference for them
      if (myType == RobotType.COMMANDER
          && commanderLikes(e.type)
          && (preferred == null
              || e.location.distanceSquaredTo(myLoc) < preferred.location.distanceSquaredTo(myLoc)))
        preferred = e;
      if (nearest == null
          || e.location.distanceSquaredTo(myLoc) < nearest.location.distanceSquaredTo(myLoc))
        nearest = e;
    }

    if (preferred != null) nearest = preferred;

    int attackRange = myType.attackRadiusSquared;
    if (myType == RobotType.LAUNCHER)
      attackRange = (1 + GameConstants.MISSILE_LIFESPAN) * (1 + GameConstants.MISSILE_LIFESPAN);

    if (nearest != null) {
      if (ignoreThreat || myLoc.distanceSquaredTo(nearest.location) > attackRange) {
        rc.setIndicatorString(2, "Closing with " + nearest.type + " at " + nearest.location);
        if (rc.isCoreReady()) tryMove(rc.getLocation().directionTo(nearest.location), ignoreThreat);
      } else {
        rc.setIndicatorString(
            2, "Holding at range with " + nearest.type + " at " + nearest.location);
      }
      return true;
    }
    return false;
  }
Пример #14
0
 /*
  * If there are no good moves we should stay and fight
  */
 private static void doRetreatMove() {
   try {
     if (myType == RobotType.COMMANDER
         && rc.hasLearnedSkill(CommanderSkillType.FLASH)
         && rc.getFlashCooldown() == 0) flashTowards(myHQ, true);
     Direction d = myLoc.directionTo(myHQ);
     rc.setIndicatorString(2, "Threatened - retreating towards HQ " + d);
     if (rc.isCoreReady()) tryMove(d, false);
   } catch (GameActionException e) {
     System.out.println("Retreat exception");
     // e.printStackTrace();
   }
 }
Пример #15
0
  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());
  }
Пример #16
0
  public HQPlayer(RobotController rc) {
    super(rc);
    this.currentLocation = rc.getLocation();
    this.directionToEnemyHQ = this.currentLocation.directionTo(enemyHQLocation);
    this.initialMineCount = rc.senseMineLocations(currentLocation, 10000, Team.NEUTRAL).length;

    try {
      if (this.canBeTrapped()) {
        rc.setIndicatorString(2, "Can be trapped");
        this.markSpawnSquare();
      } else {
        rc.setIndicatorString(2, "No trap sensed");
      }

      // pick encampments on our side of the map

      rc.broadcast(TargetEncampmentsStartChannel, targetEncampmentsStart);
      this.targetEncampments =
          rc.senseEncampmentSquares(
              currentLocation,
              this.currentLocation.distanceSquaredTo(enemyHQLocation) / 4,
              Team.NEUTRAL);
      // int a = Clock.getBytecodeNum();
      QuicksortLocations(this.targetEncampments, this.currentLocation);
      // int b = Clock.getBytecodeNum();
      // rc.setIndicatorString(1, "Bytecodes: "+(b-a));

      this.broadcastTargetEncampments();

      int rendezvousX = (3 * this.currentLocation.x + this.enemyHQLocation.x) / 4;
      int rendezvousY = (3 * this.currentLocation.y + this.enemyHQLocation.y) / 4;
      MapLocation rendezvous = new MapLocation(rendezvousX, rendezvousY);
      rc.broadcast(RendezVousChannel, intFromMapLocation(rendezvous));
    } catch (GameActionException e) {
      e.printStackTrace();
    }
  }
Пример #17
0
  /**
   * To be run by archons during the intro phase (and others? change it a bit?) to handle and gather
   * information from incoming message signals
   *
   * @param rc
   */
  private static void processIntroMessageSignals(RobotController rc) {
    int cornerX = Integer.MIN_VALUE;
    int cornerY = Integer.MIN_VALUE;
    int denX = Integer.MIN_VALUE;
    int denY = Integer.MIN_VALUE;

    Signal[] signals = rc.emptySignalQueue();
    for (Signal s : signals) {
      if (s.getTeam().equals(myTeam) && s.getMessage() != null) {
        final int[] message = s.getMessage();
        if (message[0] == SENDING_CORNER_X) {
          cornerX = message[1];
        } else if (message[0] == SENDING_CORNER_Y) {
          cornerY = message[1];
        } else if (message[0] == SENDING_DEN_X) {
          denX = message[1];
        } else if (message[0] == SENDING_DEN_Y) {
          denY = message[1];
        }
      }
    }
    if (cornerX > Integer.MIN_VALUE && cornerY > Integer.MIN_VALUE) {
      MapLocation newCorner = new MapLocation(cornerX, cornerY);
      if (!SCOUTED_CORNERS.contains(newCorner)) {
        SCOUTED_CORNERS.add(newCorner);
        rc.setIndicatorString(0, "Added new corner: " + newCorner);
        rc.setIndicatorString(2, "Current Mode" + currentMode);
      }
      rc.setIndicatorString(1, SCOUTED_CORNERS + "");
    }
    if (denX > Integer.MIN_VALUE && denY > Integer.MIN_VALUE) {
      MapLocation newDen = new MapLocation(denX, denY);
      if (!ZOMBIE_DEN_LOCATIONS.contains(newDen)) {
        ZOMBIE_DEN_LOCATIONS.add(newDen);
      }
    }
  }
Пример #18
0
  // Move towards enemy HQ if we can attack
  private static void doAdvanceMove() {
    try {
      if (myType == RobotType.COMMANDER
          && rc.hasLearnedSkill(CommanderSkillType.FLASH)
          && rc.getFlashCooldown() == 0) flashTowards(threats.enemyHQ, false);
    } catch (GameActionException e) {
      System.out.println("Flash exception");
      // e.printStackTrace();
    }

    if (rc.isCoreReady()) {
      Direction dir = null;

      if (myType.canAttack() || (myType == RobotType.LAUNCHER && Clock.getRoundNum() > 550)) {
        if (myType != RobotType.DRONE) dir = bfs.readResult(myLoc, threats.enemyHQ);
        if (dir == null) dir = myLoc.directionTo(threats.enemyHQ);
        rc.setIndicatorString(2, "Advancing " + dir);
      } else {
        dir = myLoc.directionTo(myHQ);
        rc.setIndicatorString(2, "HQ Defensive unit " + dir);
      }
      tryMove(dir, false);
    }
  }
Пример #19
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;
     }
   }
 }
 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);
       }
     }
   }
 }
Пример #21
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();
    }
  }
Пример #22
0
  public void run(final RobotController robotController) throws GameActionException {

    final MapInfoModule mapInfoModule = new MapInfoModule();

    final CombatModule combatModule = new CombatModule();
    final CommunicationModule communicationModule = new CommunicationModule(mapInfoModule);
    final DirectionModule directionModule = new DirectionModule(robotController.getID());
    final MovementModule movementModule = new MovementModule();
    final RubbleModule rubbleModule = new RubbleModule();

    final Team currentTeam = robotController.getTeam();
    int turnsStuck = 0;

    while (true) {

      RobotType type = robotController.getType();
      MapLocation currentLocation = robotController.getLocation();

      // update communication

      communicationModule.processIncomingSignals(robotController);

      // let's verify existing information

      communicationModule.verifyCommunicationsInformation(robotController, null, false);

      if (type == RobotType.TTM) {

        // MOVE

        // let's get the best assignment

        CommunicationModuleSignal objectiveSignal = null;
        int closestObjectiveLocationDistance = Integer.MAX_VALUE;

        final Enumeration<CommunicationModuleSignal> zombieDenCommunicationModuleSignals =
            communicationModule.zombieDens.elements();
        while (zombieDenCommunicationModuleSignals.hasMoreElements()) {

          final CommunicationModuleSignal signal =
              zombieDenCommunicationModuleSignals.nextElement();
          final int distance = signal.location.distanceSquaredTo(currentLocation);
          if (distance < closestObjectiveLocationDistance) {

            objectiveSignal = signal;
            closestObjectiveLocationDistance = distance;
          }
        }

        final Enumeration<CommunicationModuleSignal> enemyArchonCommunicationModuleSignals =
            communicationModule.enemyArchons.elements();
        while (enemyArchonCommunicationModuleSignals.hasMoreElements()) {

          final CommunicationModuleSignal signal =
              enemyArchonCommunicationModuleSignals.nextElement();
          final int distance =
              signal.location.distanceSquaredTo(currentLocation)
                  * 6; // multiplying by 6 to prioritize the dens
          if (distance < closestObjectiveLocationDistance) {

            objectiveSignal = signal;
            closestObjectiveLocationDistance = distance;
          }
        }

        final Enumeration<CommunicationModuleSignal> enemyTurretCommunicationModuleSignals =
            communicationModule.enemyTurrets.elements();
        while (enemyTurretCommunicationModuleSignals.hasMoreElements()) {

          final CommunicationModuleSignal signal =
              enemyTurretCommunicationModuleSignals.nextElement();
          final int distance = signal.location.distanceSquaredTo(currentLocation) * 20;
          if (distance < closestObjectiveLocationDistance) {

            objectiveSignal = signal;
            closestObjectiveLocationDistance = distance;
          }
        }

        boolean shouldMove = true;
        Direction desiredMovementDirection = null;
        Direction targetRubbleClearanceDirection = null;

        // check to make sure we are safe

        final RobotInfo[] enemies =
            robotController.senseHostileRobots(
                currentLocation, robotController.getType().sensorRadiusSquared);

        if (robotController.isCoreReady() && enemies.length > 0) {

          final Direction fleeDirection =
              directionModule.averageDirectionTowardDangerousRobotsAndOuterBounds(
                  robotController, enemies);
          if (fleeDirection != null) {

            final Direction fleeMovementDirection =
                directionModule.recommendedMovementDirectionForDirection(
                    fleeDirection.opposite(), robotController, false);
            if (fleeMovementDirection != null) {

              robotController.move(fleeMovementDirection);
              currentLocation = robotController.getLocation();
              robotController.setIndicatorString(
                  1, fleeDirection.name() + " " + fleeMovementDirection.name());
            }
          }
        }

        // check if there are nearby signals

        if (desiredMovementDirection == null) {

          int closestSignalDistance = Integer.MAX_VALUE;
          MapLocation closestSignalLocation = null;

          final ArrayList<Signal> notifications = communicationModule.notifications;
          for (int i = 0; i < notifications.size(); i++) {

            final Signal signal = notifications.get(i);
            final int distance = currentLocation.distanceSquaredTo(signal.getLocation());
            if (distance < closestSignalDistance) {

              closestSignalDistance = distance;
              closestSignalLocation = signal.getLocation();
            }
          }
          if (closestSignalLocation != null) {

            desiredMovementDirection = currentLocation.directionTo(closestSignalLocation);
          }
        }

        // now let's try move toward an assignment

        if (robotController.isCoreReady()
            && communicationModule.initialInformationReceived
            && shouldMove) {

          // check if we have an objective

          if (desiredMovementDirection == null) {

            if (objectiveSignal != null) {

              final MapLocation objectiveLocation = objectiveSignal.location;
              if (objectiveLocation.distanceSquaredTo(currentLocation) >= 8) {

                desiredMovementDirection = currentLocation.directionTo(objectiveLocation);
              }
            }
          }

          // try move towards archon starting positions

          if (desiredMovementDirection == null) {

            int closestArchonDistance = Integer.MAX_VALUE;
            MapLocation closestArchonLocation = null;

            final MapLocation[] archonLocations =
                robotController.getInitialArchonLocations(robotController.getTeam().opponent());
            for (int i = 0; i < archonLocations.length; i++) {

              final MapLocation location = archonLocations[i];
              final int distance = currentLocation.distanceSquaredTo(location);
              if (distance < closestArchonDistance) {

                closestArchonDistance = distance;
                closestArchonLocation = location;
              }
            }
            if (closestArchonLocation != null) {

              desiredMovementDirection = currentLocation.directionTo(closestArchonLocation);
            }
          }

          // process movement

          if (desiredMovementDirection != null) {

            final Direction recommendedMovementDirection =
                directionModule.recommendedMovementDirectionForDirection(
                    desiredMovementDirection, robotController, false);
            final MapLocation recommendedMovementLocation =
                recommendedMovementDirection != null
                    ? currentLocation.add(recommendedMovementDirection)
                    : null;
            if (recommendedMovementDirection != null
                && !movementModule.isMovementLocationRepetitive(
                    recommendedMovementLocation, robotController)) {

              robotController.move(recommendedMovementDirection);
              movementModule.addMovementLocation(recommendedMovementLocation, robotController);
              currentLocation = robotController.getLocation();
              turnsStuck = 0;
            }
          }
        }

        // unpack if we're safe

        RobotInfo[] nearbyTeammates = robotController.senseNearbyRobots(8, currentTeam);
        RobotInfo[] nearbySoldiers =
            combatModule.robotsOfTypesFromRobots(
                nearbyTeammates, new RobotType[] {RobotType.SOLDIER});

        if (nearbySoldiers.length > 2) {

          robotController.unpack();
        }

      } else {

        // ATTACK

        final RobotInfo[] enemies =
            robotController.senseHostileRobots(
                currentLocation, robotController.getType().attackRadiusSquared);

        RobotInfo bestEnemy = this.getBestEnemyToAttackFromEnemies(robotController, enemies);

        // handle attacking

        if (bestEnemy != null) {

          if (robotController.isWeaponReady()) {

            // we can attack the enemy

            robotController.attackLocation(bestEnemy.location);
            if (bestEnemy.type != RobotType.ZOMBIEDEN) {

              communicationModule.broadcastSignal(
                  robotController,
                  CommunicationModule.maximumFreeBroadcastRangeForRobotType(
                      robotController.getType()));
            }
          }
        }

        // pack if we aren't near soldiers

        RobotInfo[] nearbyTeammates =
            robotController.senseNearbyRobots(type.sensorRadiusSquared, currentTeam);
        RobotInfo[] nearbySoldiers =
            combatModule.robotsOfTypesFromRobots(
                nearbyTeammates, new RobotType[] {RobotType.SOLDIER});

        if (nearbySoldiers.length < 3) {

          robotController.pack();
        }
      }

      Clock.yield();
    }
  }
Пример #23
0
  public static void run() throws GameActionException {
    rc = RobotPlayer.rc;
    rand = new Random(rc.getID());

    // build scouts right away
    buildRobot(RobotType.SCOUT);

    while (true) {
      /*
       * INPUT
       */
      if (rc.getLocation().equals(goal)) {
        goal = null; // you made it to the goal
        past10Locations =
            new ArrayList<MapLocation>(); // delete the slug trail after you reach your goal
      }

      // sense locations around you
      nearbyMapLocations =
          MapLocation.getAllMapLocationsWithinRadiusSq(
              rc.getLocation(), rc.getType().sensorRadiusSquared);

      // parts locations
      nearbyPartsLocations = rc.sensePartLocations(RobotType.ARCHON.sensorRadiusSquared);

      // find the nearest mapLocation with the most parts
      double maxParts = 0;
      MapLocation nearbyLocationWithMostParts = null;
      for (MapLocation loc : nearbyPartsLocations) {
        // add to locationsWithParts arraylist
        if (locationsWithParts.contains(loc) == false) {
          locationsWithParts.add(loc);
        }

        // find the location with the most parts
        double partsAtLoc = rc.senseParts(loc);
        if (partsAtLoc > maxParts) {
          maxParts = partsAtLoc;
          nearbyLocationWithMostParts = loc;
        }
      }

      // read signals
      Signal[] signals = rc.emptySignalQueue();
      for (Signal signal : signals) {
        // check if the signal has parts at the location
        int[] message = signal.getMessage();
        if (message != null && message[0] == Utility.PARTS_CODE) {
          // add that location to the locationsWithParts arraylist
          locationsWithParts.add(signal.getLocation());
        }
      }

      // sense robots
      MapLocation myLoc = rc.getLocation();
      robots = rc.senseNearbyRobots();
      foes = new ArrayList<RobotInfo>();
      foesWithinAttackRange = new ArrayList<RobotInfo>();
      for (RobotInfo robot : robots) {
        if (robot.team == Team.ZOMBIE
            || robot.team == rc.getTeam().opponent()) // if the robot is a foe
        {
          foes.add(robot);

          if (myLoc.distanceSquaredTo(robot.location) < robot.type.attackRadiusSquared) {
            foesWithinAttackRange.add(robot);
          }
        }
      }
      int nearbyFoes = foes.size();
      int nearbyFoesInAttackRange = foesWithinAttackRange.size();

      /*//check stats
      double health = rc.getHealth();
      int infectedTurns = rc.getInfectedTurns();
      int robotsAlive = rc.getRobotCount();
      */

      /*
       * OUPUT
       */

      // what to do
      if (nearbyFoes == 0) // if there are no foes in sight
      {
        if (rc.getTeamParts() >= RobotType.TURRET.partCost) // build if you can
        {
          buildRobots();
        } else {
          if (maxParts > 0 && goal == null) // if there are parts nearby
          {
            // make that the goal
            goal = nearbyLocationWithMostParts;
          } else if (goal == null) // if there aren't and there is no goal
          {
            // build something or find new parts
            // 80% build, 20% new parts
            if (locationsWithParts.size() > 0 && rand.nextFloat() > .8) {
              goal = locationsWithParts.get(0);
              locationsWithParts.remove(0);
              goalIsASafeLocation = false;
            }
            // calculate the next goal - maybe a new parts location you got via signal
          } else if (goal != null) // if there is a goal, move there
          {
            moveToLocation(goal);
          }
        }
      } else // there are foes nearby
      {
        // message for help!
        if (Math.random() < probSignal) {
          rc.broadcastSignal(archonInTroubleSignalRadiusSquared);
        }

        if (nearbyFoesInAttackRange > 0) {
          goal = findSaferLocation();
          rc.setIndicatorString(0, "" + goal.x + " " + goal.y);
          goalIsASafeLocation = true;
          moveToLocation(goal);
        }
      }

      Clock.yield();
    }
  }
Пример #24
0
  private static void rushMicro(RobotController rc, RobotInfo[] hostiles)
      throws GameActionException {
    // Prioritizes attacking turrets.
    RobotInfo bestEnemy = null;
    boolean canAttackBestEnemy = false;
    int bestEnemyDist = 10000; // only care if can't hit
    for (RobotInfo hostile : hostiles) {
      // Can attack this enemy.
      int dist = myLoc.distanceSquaredTo(hostile.location);
      // Summary:
      // Prioritizes enemies over zombies.
      // Prioritizes turret enemies over other enemies.
      // Prioritizes lowest health enemy last
      if (dist <= attackRadius) {
        if (bestEnemy != null) {
          if (bestEnemy.team == enemyTeam) { // best is already enemy
            if (hostile.team == enemyTeam) { // found an enemy
              if (countsAsTurret(bestEnemy.type)) {
                if (countsAsTurret(hostile.type)) {
                  // Take lowest health
                  if (bestEnemy.health > hostile.health) bestEnemy = hostile;
                }
              } else {
                if (countsAsTurret(hostile.type)) {
                  bestEnemy = hostile;
                } else {
                  // Take lowest health
                  if (bestEnemy.health > hostile.health) bestEnemy = hostile;
                }
              }
            }
          } else { // best is not an enemy!
            if (hostile.team == enemyTeam) { // found an enemy
              bestEnemy = hostile;
            } else {
              // Take lowest health
              if (bestEnemy.health > hostile.health) bestEnemy = hostile;
            }
          }
        } else {
          bestEnemy = hostile;
        }
        canAttackBestEnemy = true;
      } else {
        // Only update best enemy if you can't attack best enemy
        if (!canAttackBestEnemy) {
          if (bestEnemy != null) {
            // Pick the closest one
            if (bestEnemyDist > dist) {
              bestEnemyDist = dist;
              bestEnemy = hostile;
            }
          } else {
            bestEnemyDist = dist;
            bestEnemy = hostile;
          }
        }
      }
    }
    rc.setIndicatorString(0, "Round: " + rc.getRoundNum() + ", Best enemy: " + bestEnemy);
    if (rc.isCoreReady()) {
      // If there is a best enemy, attack him.
      if (bestEnemy != null) {
        // Move closer only if blocking someone.
        if (rc.canAttackLocation(bestEnemy.location)) {
          if (isBlockingSomeone(rc, bestEnemy.location)) {
            Direction desired = myLoc.directionTo(bestEnemy.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());
            }
          }
        }
        // If can't attack it, move closer!
        else {
          Direction desired = myLoc.directionTo(bestEnemy.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(dir.rotateLeft());
          } else if (shouldMine(rc, desired.rotateRight())) {
            rc.clearRubble(desired.rotateRight());
          }
        }
      }
      // Otherwise move closer to destination
      else {
        if (currentDestination != null) {
          RobotInfo info = null;
          if (rc.canSenseLocation(currentDestination)) {
            info = rc.senseRobotAtLocation(currentDestination);
          }
          if (info != null) {
            // If can attack it, just only move closer if blocking someone behind.
            if (rc.canAttackLocation(info.location)) {
              if (isBlockingSomeone(rc, currentDestination)) {
                Direction desired = myLoc.directionTo(currentDestination);
                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());
                }
              }
            }
            // If can't attack it, move closer!
            else {
              Direction desired = myLoc.directionTo(currentDestination);
              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());
              }
            }
          }
          // If not there, just move closer.
          else {
            Direction desired = myLoc.directionTo(currentDestination);
            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());
            }
          }
        }
      }
    }

    // Attack whenever you can.
    if (bestEnemy != null) {
      if (rc.isWeaponReady()) {
        if (rc.canAttackLocation(bestEnemy.location)) {
          broadcastingAttack(rc, bestEnemy);
        }
      }
    }
  }
Пример #25
0
 protected void updateStatus() {
   myRC.setIndicatorString(1, Integer.toString(enemyDistance));
   myRC.setIndicatorString(2, state.name());
 }
Пример #26
0
  public static void run(RobotController rc) {
    sightRadius = RobotType.SOLDIER.sensorRadiusSquared;
    attackRadius = RobotType.SOLDIER.attackRadiusSquared;
    myTeam = rc.getTeam();
    enemyTeam = myTeam.opponent();
    while (true) {
      try {
        numEnemySoldiers = 0;
        totalEnemySoldierHealth = 0;
        myLoc = rc.getLocation();
        nearbyAllies = rc.senseNearbyRobots(sightRadius, myTeam);
        nearbyEnemies = rc.senseHostileRobots(myLoc, sightRadius);
        newArchonLoc = null;

        // clear bad locations
        resetLocations(rc);
        // read messages and get destination
        readMessages(rc);
        // heal if need (and set the archon destination to go to)
        setRetreatingStatus(rc, nearbyEnemies);

        // Remove turret locations that you can see are not there.
        // Does NOT remove turret locations due to broadcasts. Already done in read messages.
        removeTurretLocations(rc);

        if (newArchonLoc != null) {
          nearestArchonLocation = newArchonLoc;
        }

        rc.setIndicatorString(2, "Round: " + rc.getRoundNum() + ", rushing: " + rush);
        // Reset rushing if turns since rush is > 20 and see no more enemies.
        if (rush && myLoc.distanceSquaredTo(rushLocation) <= 100) turnsSinceRush++;
        if (turnsSinceRush > 20) {
          if (rc.senseNearbyRobots(sightRadius, enemyTeam).length == 0) {
            turnsSinceRush = 0;
            rush = false;
          }
        }

        // When rushing, be mad aggressive.
        if (rush) {
          rushMicro(rc, nearbyEnemies);
        }
        // When retreating, retreat
        else if (healing) {
          if (rc.isCoreReady()) {
            if (nearestArchonLocation != null) {
              if (myLoc.distanceSquaredTo(nearestArchonLocation) > 13) {
                bugging.enemyAvoidMove(nearbyEnemies);
                // Get away from archons that are not too close together.
              } else if (myLoc.distanceSquaredTo(nearestArchonLocation) <= 2) {
                Direction radialDir = nearestArchonLocation.directionTo(myLoc);
                Direction awayDir = Movement.getBestMoveableDirection(radialDir, rc, 2);
                if (awayDir != Direction.NONE) {
                  rc.move(awayDir);
                }
              }
            }
          }
          // Make sure to attack people even when retreating.
          // Prioritize the closest enemy. Then the closest zombie.
          if (rc.isWeaponReady()) {
            // Attack the closest enemy. If there is not one, then attack the closest zombie
            int closestDist = 10000;
            RobotInfo target = null;
            for (RobotInfo hostile : nearbyEnemies) {
              int dist = myLoc.distanceSquaredTo(hostile.location);
              if (rc.canAttackLocation(hostile.location)) {
                // There is already is a target
                if (target != null) {
                  if (target.team == enemyTeam) {
                    // Target is already enemy, so prioritize the closest
                    if (hostile.team == enemyTeam) {
                      if (dist < closestDist) {
                        target = hostile;
                        closestDist = dist;
                      }
                    } // If hostile is not an enemy, not worth considering.
                  } else {
                    // Target is not on enemy team, so hostile is best choice!
                    if (hostile.team == enemyTeam) {
                      target = hostile;
                      closestDist = dist;
                      // Both are zombies, so just pick the closest.
                    } else {
                      if (dist < closestDist) {
                        target = hostile;
                        closestDist = dist;
                      }
                    }
                  }
                  // Set a target when there is not one.
                } else {
                  target = hostile;
                  closestDist = dist;
                }
              }
            }
            // We know that if there is a target, we can attack it.
            if (target != null) {
              rc.attackLocation(target.location);
            }
          }
        }

        // When viper infected and will die from the infection, do special micro
        else if (isViperInfected(rc)
            && (rc.getHealth() < rc.getViperInfectedTurns() * 2 || rc.getRoundNum() > 2100)) {
          viperInfectedMicro(rc);
        }

        // if there are enemies in range, we should focus on attack and micro
        else if (nearbyEnemies.length > 0) {
          if (shouldLure(rc, nearbyEnemies, nearbyAllies)) luringMicro(rc);
          else micro(rc);
        } else { // otherwise, we should always be moving somewhere
          moveSoldier(rc);
        }

        Clock.yield();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Пример #27
0
 protected void setIndicatorString(int i, String s) {
   if (Config.DEBUG) {
     int roundNum = rc.getRoundNum();
     rc.setIndicatorString(i, String.format("%d: %s", roundNum, s));
   }
 }
Пример #28
0
  /**
   * @Nathan - Should we adjust these priorities (specifically where should building troops be?)
   * TODO for archons - 1) repair nearest injured unit 2) signal turtle location 3) pick up adjacent
   * parts and activate neutral units 4) move to turtle corner 5) build troops 6) run away from
   * enemies
   *
   * @param rc
   * @throws GameActionException
   */
  private static void archon(RobotController rc) {
    numArchons = rc.getInitialArchonLocations(myTeam).length;
    turtleCorner = LOCATION_NONE;
    while (true) {
      try {
        // 1) repair nearest injured unit
        repairFirst(rc);
        // 2) signal turtle location - every 25 turns
        int broadcastRadius = rc.getType().sensorRadiusSquared * (2 + (rc.getRobotCount() / 50));
        if (rc.getRoundNum() > 100 && rc.getRoundNum() % 30 == 0 && turtleCorner != LOCATION_NONE) {
          rc.broadcastMessageSignal(turtleCorner.x, turtleCorner.y, broadcastRadius);
        }

        // @Nathan - Intro mode is all you -- I just pasted all the text into a separate method for
        // clarity
        if (turtleCorner != LOCATION_NONE && currentMode != TURTLE_MODE) {
          currentMode = TRANSITION_MODE;
        }
        if (currentMode == INTRO_MODE) {
          archonIntroMode(rc);
          // if (turtleCorner.equals(LOCATION_NONE)) tryToLocateCorner(rc);
        }
        // 4) Move to turtle corner
        if (currentMode == TRANSITION_MODE) {
          if (rc.getLocation().distanceSquaredTo(turtleCorner) > 4) {
            moveTowards(rc, rc.getLocation().directionTo(turtleCorner));
          } else {
            // TODO get in proper position
            currentMode = TURTLE_MODE;
            rc.broadcastMessageSignal(SENDING_MODE, TURTLE_MODE, rc.getType().sensorRadiusSquared);
          }
        }

        // 5) Build Troops !
        // @Nathan do we need to build more scouts in turtle mode so we can do more kiting?
        boolean hasNearbyEnemies = isNearbyEnemies(rc);
        if (!hasNearbyEnemies && rc.getRobotCount() - numArchons < NUM_INTRO_SCOUTS) {
          tryToBuild(rc, RobotType.SCOUT);
          Direction directionToTargetCorner = calculateDirectionToClosestCorner(rc);
          rc.broadcastMessageSignal(
              SENDING_TARGET_DIRECTION, DIRECTION_TO_SIGNAL.get(directionToTargetCorner), 4);
        }
        if ((rc.getRobotCount() <= 30 || hasNearbyEnemies)) {
          tryToBuild(rc, RobotType.SOLDIER);
        }
        if (rc.getRobotCount() > 30 && !hasNearbyEnemies) {
          tryToBuild(rc, RobotType.TURRET);
        }
        // 6) if senses enemy troop that is not a scout, run away from it
        if (hasNearbyEnemies) moveAwayFromEnemies(rc);
        // 3) Pick up parts on current square, check for adjacent parts and try to collect them
        collectParts(rc);
        // 3a) activate any nearby units
        activateUnits(rc);
        rc.setIndicatorString(0, "Turtle x: " + turtleCorner.x + "Turtle y: " + turtleCorner.y);
        rc.setIndicatorString(1, "Current Mode" + currentMode);
        Clock.yield(); // end turn
      } catch (GameActionException e) {
        e.printStackTrace();
      }
    }
  }
Пример #29
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();
    }
  }