示例#1
0
  // In this function the HQ spawns a soldier ideally toward the enemy base but in any direction
  // otherwise
  public static void SpawnSoldiers(RobotController rc) {
    try {
      if (rc.isActive() && rc.getType() == RobotType.HQ) {
        Direction toEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
        if (rc.senseObjectAtLocation(rc.getLocation().add(toEnemy)) == null) {
        } else {
          for (int i = 0; i < 7; i++) {
            toEnemy = toEnemy.rotateLeft();

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

        if (toEnemy != Direction.NONE) {
          if (rc.isActive()) {
            if (rc.getType() == RobotType.HQ) {
              rc.spawn(toEnemy);
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Utility Exception");
    }
  }
示例#2
0
 public static void fireCircle(RobotController rc, int radius, MapLocation center) {
   for (int k = 0; k < directions.length; k++) {
     while (!rc.isActive()) {}
     MapLocation toFire = center.add(directions[k], radius);
     try {
       if (toFire.x >= 0
           && toFire.x < rc.getMapWidth()
           && toFire.y >= 0
           && toFire.y < rc.getMapHeight()) {
         rc.attackSquare(toFire);
         rc.yield();
       }
     } catch (Exception e) {
     }
     while (!rc.isActive()) {}
     toFire = center;
     for (int a = 0; a < radius / 2; a++) {
       toFire = toFire.add(directions[k]);
       toFire = toFire.add(directions[(k + 1) % directions.length]);
     }
     try {
       if (toFire.x >= 0
           && toFire.x < rc.getMapWidth()
           && toFire.y >= 0
           && toFire.y < rc.getMapHeight()) {
         rc.attackSquare(toFire);
         rc.yield();
       }
     } catch (Exception e) {
     }
   }
 }
示例#3
0
  static void runDefender(RobotController rc, int squad) throws GameActionException {
    Team team = rc.getTeam();
    Team enemy = team.opponent();

    int squadInfo = rc.readBroadcast(squad);
    MapLocation target = Conversion.intToMapLocation(squadInfo);
    MapLocation curr = rc.getLocation();

    int status = rc.readBroadcast(squad + 1);
    int PASTRstatus = Channels.NTPASTRDecoding(status)[1];
    int NTstatus = Channels.NTPASTRDecoding(status)[0];

    Robot[] allies =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().attackRadiusMaxSquared * 2, team);

    // Create a PASTR/NT if not already there

    // System.out.println(allies.length + " " + rc.readBroadcast(Channels.numAlliesNeededChannel));
    if (allies.length >= rc.readBroadcast(Channels.numAlliesNeededChannel)
        && curr.distanceSquaredTo(target) < distanceThreshold
        && rc.isActive()) {
      if (PASTRstatus == 0) {
        rc.construct(RobotType.PASTR);
        rc.broadcast(squad + 1, Channels.NTPASTREncoding(NTstatus, 1));
        System.out.println("Constructing a PASTR...");

      } else if (NTstatus == 0) {
        rc.construct(RobotType.NOISETOWER);
        rc.broadcast(squad + 1, Channels.NTPASTREncoding(1, PASTRstatus));
        System.out.println("Constructing a NT...");
      }
    }

    // Then go to right place
    if (curr.distanceSquaredTo(target) > 8) Move.moveTo(rc, target);

    // Then attack!
    Robot[] enemyRobots =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().sensorRadiusSquared * 2, enemy);
    MapLocation eloc = Attack.nearestEnemyLoc(rc, enemyRobots, rc.getLocation());

    if (eloc != null) {
      if (rc.isActive()) Move.moveToward(rc, eloc);
      if (rc.isActive() && rc.canAttackSquare(eloc)) rc.attackSquare(eloc);
    }

    // If there is a pastr and noisetower, don't block them!
    if (PASTRstatus == 1 && NTstatus == 1) {
      if (enemyRobots.length == 0 && rc.senseCowsAtLocation(rc.getLocation()) > 30) {
        Move.tryToSneak(rc);
      }
    }
  }
示例#4
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;
       }
     }
   }
 }
示例#5
0
  static void spawnRobot(RobotController rc) throws GameActionException {

    if (rc.senseRobotCount() < GameConstants.MAX_ROBOTS && rc.isActive()) {

      int squad = nextSquadNum(rc);
      boolean spawnSuccess = false;
      Robot[] allies =
          rc.senseNearbyGameObjects(
              Robot.class, RobotType.SOLDIER.attackRadiusMaxSquared / 2, team);

      if (squad > 10) {
        spawnSuccess = tryToSpawn(rc, 1);
        if (spawnSuccess) {
          int j = Util.assignmentToInt(squad, 1);
          rc.broadcast(Util.spawnchannel, j);
          //					System.out.println("Spawned an attacker: " + j);
        }

      } else if (squad < 11) {
        spawnSuccess = tryToSpawn(rc, 0);
        if (spawnSuccess) {
          int j = Util.assignmentToInt(squad, 0);
          rc.broadcast(Util.spawnchannel, j);
          //					System.out.println("Spawned a defender: " + j);
        }
      }

      // Increase the squad member count by one
      if (spawnSuccess) {
        rc.broadcast(squad, rc.readBroadcast(squad) + 10000);
      }
    }
  }
  public void play() throws GameActionException {
    if (rc.isActive()) {
      int soundChannel = 1;
      int pastrChannel = 2;
      Message ms = Comms.ReadMessage(rc, soundChannel);
      Message mp = Comms.ReadMessage(rc, pastrChannel);
      if (ms != null) {
        if (rc.senseObjectAtLocation(ms.loc) == null) {
          rc.broadcast(soundChannel, 0);
        }
      }
      if (mp != null) {
        if (rc.senseObjectAtLocation(mp.loc) == null) {
          rc.broadcast(pastrChannel, 0);
        }
      }
      // in principle the HQ is really good at killing enemies
      // BUT
      // killing nearby enemies almost never happens
      // because the HQ is so busy spawning more robots
      // and it cant shoot during spawning
      Tactics.killNearbyEnemiesHQ(rc, info);

      spawnRobot();
    }
  }
  /* (non-Javadoc)
   * @see team001.robots.BasePlayer#attackEnemy(battlecode.common.MapLocation)
   */
  @Override
  public boolean enemyInSight(MapLocation enemyLocation) {

    try {
      if (rc.isActive()) {
        if (rc.getLocation().distanceSquaredTo(enemyLocation)
            < Constants.MINIMUM_ENEMY_VISIBLE_RANGE) {
          rc.setIndicatorString(1, "I see enemy robot at " + enemyLocation);
          Message enemyat = new Message();
          enemyat.setLocation(enemyLocation);
          enemyat.setMessageType(MessageType.ENEMYAT);
          enemyat.setRobotID(Constants.BROADCAST_CHANNEL);
          sendMessage(enemyat);
          rc.attackSquare(enemyLocation);
          return true;
        } else {
          return false;
        }
      } else {
        rc.yield();
      }

    } catch (GameActionException e) {
      e.printStackTrace();
    }
    return false;
  }
 private static void goToLocationAvoidMines(MapLocation whereToGo) throws GameActionException {
   int dist = rc.getLocation().distanceSquaredTo(whereToGo);
   if (dist > 0 && rc.isActive()) {
     Direction dir = rc.getLocation().directionTo(whereToGo);
     goDirectionAvoidMines(dir);
   }
 }
 /**
  * @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);
     }
   }
 }
示例#10
0
  static void runAttacker(RobotController rc, int squad) throws GameActionException {

    Team team = rc.getTeam();
    Team enemy = team.opponent();

    int squadInfo = rc.readBroadcast(squad);
    MapLocation target = Conversion.intToMapLocation(squadInfo);
    MapLocation curr = rc.getLocation();

    Robot[] allies =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().attackRadiusMaxSquared * 2, team);

    // First steps away from home HQ
    if (curr.distanceSquaredTo(rc.senseHQLocation()) < 25) Move.tryToMove(rc);

    // attack!
    Robot[] enemyRobots =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().sensorRadiusSquared * 2, enemy);
    MapLocation eloc = Attack.nearestEnemyLoc(rc, enemyRobots, rc.getLocation());

    if (eloc != null) {
      if (rc.isActive()) Move.moveToward(rc, eloc);
      if (rc.isActive() && rc.canAttackSquare(eloc)) rc.attackSquare(eloc);
    }

    // Go to right place
    if (curr.distanceSquaredTo(target) > 7) {
      // System.out.println(target + " target " + allies.length + "ally length");
      Move.moveTo(rc, target);
    }
  }
示例#11
0
  public void run() {
    while (true) {
      if (rc.getType() == RobotType.SOLDIER) {
        switch (corner) {
          case 1:
            Utilities.MoveMapLocation(rc, new MapLocation(2, 2), true);
            break;
          case 2:
            Utilities.MoveMapLocation(rc, new MapLocation(rc.getMapWidth() - 3, 2), true);
            break;
          case 3:
            Utilities.MoveMapLocation(rc, new MapLocation(2, rc.getMapHeight() - 3), true);
            break;
          default:
            Utilities.MoveMapLocation(
                rc, new MapLocation(rc.getMapWidth() - 3, rc.getMapHeight() - 3), true);
            break;
        }

        if (rc.isActive()) {
          try {
            rc.construct(RobotType.PASTR);
          } catch (Exception e) {
          }
        }
      }
    }
  }
示例#12
0
 public static void hqCode() throws GameActionException {
   if (rc.isActive()) {
     // Spawn a soldier
     Direction dir = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
     if (rc.canMove(dir)) rc.spawn(dir);
   }
 }
示例#13
0
 public static void rangedDefuseMine() throws GameActionException {
   if (rc.hasUpgrade(Upgrade.DEFUSION)) {
     MapLocation[] mines = rc.senseMineLocations(rc.getLocation(), 14, rc.getTeam().opponent());
     if (mines.length > 0 && rc.isActive()) {
       rc.defuseMine(mines[0]);
     }
   }
 }
示例#14
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;
       }
     }
   }
 }
示例#15
0
  public void run() {
    while (true) {
      try {
        Robot[] enemies = rc.senseNearbyGameObjects(Robot.class, 35, rc.getTeam().opponent());

        if (rc.isActive()) {
          Movement.fire(rc, enemies, null);
          HQFunctions.SpawnSoldiers(rc);
        }

        if (Clock.getRoundNum() % 50 == 0) {
          System.out.println();
          System.out.println("Enemy Bots: ");
          int[] AllEnemies = FightMicro.AllEnemyBots(rc);
          for (int i = 0; i < AllEnemies.length; i++) {
            System.out.print(FightMicro.getBotLocation(AllEnemies[i]));
          }
          System.out.println();
        }

        int broadcast = rc.readBroadcast(rallyPoint2);
        if (broadcast != 0) {
          if (broadcast != fightZone) {
            fightZone = broadcast;
            roundSet = Clock.getRoundNum();
          }
          // now it is time for us to move on
          else if (roundSet + 75 < Clock.getRoundNum()) {
            fightZone = 0;
            rc.broadcast(rallyPoint2, 0);
          }
        }

        if (Clock.getRoundNum() % 5 == 0 && Clock.getRoundNum() > 100) {
          // HQFunctions.moveTargetLocationRandomly(rc);
          /*
          if (goneForPastr && (rc.sensePastrLocations(rc.getTeam()).length > 0 || roundNum > (Clock.getRoundNum() - 250)))
          {
              HQFunctions.setTargetLocation(rc, goneForPastr);
          }
          else
          {
              goneForPastr = HQFunctions.setTargetLocation(rc, goneForPastr);
              roundNum = Clock.getRoundNum();
          }*/
          HQFunctions.setTargetLocation(rc, true);
          // HQFunctions.findInitialRally(rc);

        }
      } catch (Exception e) {
      }
      rc.yield();
    }
  }
  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
 static boolean tryToSpawn(RobotController rc, int type) throws GameActionException {
   if (rc.isActive() && rc.senseRobotCount() < GameConstants.MAX_ROBOTS) {
     Direction dir = Util.findDirToMove(rc);
     if (dir != null) {
       rc.spawn(dir);
       robotTypeCount[type]++;
       return true;
     }
   }
   return false;
 }
示例#18
0
 public static void tryToSpawn() throws GameActionException {
   if (rc.isActive() && rc.senseRobotCount() < GameConstants.MAX_ROBOTS) {
     for (int i = 0; i < 8; i++) {
       Direction trialDir = allDirections[i];
       if (rc.canMove(trialDir)) {
         rc.spawn(trialDir);
         break;
       }
     }
   }
 }
示例#19
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();
         }
       }
     }
   }
 }
 public void play() throws GameActionException {
   MapLocation dest = Abilities.ClosestPastr(rc, rc.getLocation(), ENEMY);
   if (dest != null) {
     Deque<Move> path = Navigation.pathAStar(rc, dest);
     while (Navigation.attackMoveOnPath(rc, path, INFO.type.attackRadiusMaxSquared, ENEMY)) {
       Tactics.killNearbyEnemies(rc, INFO);
     }
   }
   Tactics.killNearbyEnemies(rc, INFO);
   if (rc.isActive()) {
     wanderingDirection = Navigation.wonder(rc, rand, wanderingDirection);
   } else {
     rc.yield();
   }
 }
示例#21
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;
 }
示例#22
0
  private static void expand() throws GameActionException {
    // rallyPoint = findClosestLocation(rc.senseAllEncampmentSquares());
    if (!localscan) {
      rallyPoint = findClosestEmptyCamp();
    }
    if (rc.getLocation().distanceSquaredTo(rallyPoint)
        < 1) // if we are at the location of the rally point
    {
      if (!localscan) {
        rallyPoint = findFurthestLocalCamp();
        localscan = true;
      }
    }
    if (rc.getLocation().distanceSquaredTo(rallyPoint)
        < 1) // if we are at the location of the rally point
    {

      if (rc.isActive()) // if we are allowed to capture
      {
        if (rc.senseCaptureCost() + 1.8 * getNumberOfAlliedRobosAfterMe()
            < rc.getTeamPower()) // if we have enough power to capture
        {
          int readIn = rc.readBroadcast(Constants.campChannel);
          if (readIn == Constants.campGen) {
            rc.broadcast(Constants.campChannel, Constants.campGenInProduction);
            rc.captureEncampment(RobotType.GENERATOR);
          } else if (readIn == Constants.campGenInProduction) {
            rc.captureEncampment(RobotType.SUPPLIER);
          } else if (readIn == Constants.campSupplier) {
            rc.captureEncampment(RobotType.SUPPLIER);
          } else // TODO: transmissions may be being scrambled, for now just make supplier
          {
            rc.captureEncampment(RobotType.SUPPLIER);
          }
        }
      }
    } else if (rc.senseNearbyGameObjects(Robot.class, rallyPoint, 0, rc.getTeam()).length
        > 0) // if there is an allied robot on our rally point
    {
      rallyPoint = findClosestEmptyCamp();
      if (rallyPoint == null) {
        rallyPoint = findRallyPoint();
      }
      goToLocation(rallyPoint);
    } else {
      goToLocation(rallyPoint);
    }
  }
示例#23
0
 private static void goToLocation(MapLocation whereToGo) throws GameActionException {
   MapLocation meee = rc.getLocation();
   int dist = meee.distanceSquaredTo(whereToGo);
   if (dist > 0 && rc.isActive()) {
     Direction dir = meee.directionTo(whereToGo);
     int[] directionOffsets = {0, 1, -1, 2, -2};
     Direction lookingAtCurrently = null;
     for (int d : directionOffsets) {
       lookingAtCurrently = Direction.values()[(dir.ordinal() + d + 8) % 8];
       if (rc.canMove(lookingAtCurrently)) {
         moveOrDefuse(lookingAtCurrently);
         break;
       }
     }
   }
 }
示例#24
0
 public void run() {
   while (true) {
     try {
       if (rc.isActive()) {
         if (rc.getLocation().equals(towerSpot)
             || (rc.getLocation().isAdjacentTo(towerSpot)
                 && !rc.canMove(rc.getLocation().directionTo(towerSpot)))) {
           rc.construct(RobotType.NOISETOWER);
         } else {
           Movement.MoveMapLocation(rc, towerSpot, false);
         }
       }
     } catch (Exception e) {
     }
   }
 }
 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);
       }
     }
   }
 }
示例#26
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);

  }
示例#27
0
 public static void expandIndividual() throws GameActionException {
   MapLocation expandLocation =
       new MapLocation(
           rc.readBroadcast(Constants.singleExpandXChannel),
           rc.readBroadcast(Constants.singleExpandYChannel));
   rc.broadcast(Constants.commandChannel, Constants.commandRally);
   while (true) {
     if (rc.getLocation().distanceSquaredTo(expandLocation)
         < 1) // if we are at the location of the rally point
     {
       if (rc.isActive()) // if we are allowed to capture
       {
         if (rc.senseCaptureCost() + 1.8 * getNumberOfAlliedRobosAfterMe()
             < rc.getTeamPower()) // if we have enough power to capture
         {
           int readIn = rc.readBroadcast(Constants.campChannel);
           if (readIn == Constants.campGen) {
             rc.broadcast(Constants.campChannel, Constants.campGenInProduction);
             rc.captureEncampment(RobotType.GENERATOR);
           } else if (readIn == Constants.campGenInProduction) {
             rc.captureEncampment(RobotType.SUPPLIER);
           } else if (readIn == Constants.campSupplier) {
             rc.captureEncampment(RobotType.SUPPLIER);
           } else // TODO: transmissions may be being scrambled, for now just make supplier
           {
             rc.captureEncampment(RobotType.SUPPLIER);
           }
           break;
         }
       }
     } else if (rc.senseNearbyGameObjects(Robot.class, expandLocation, 0, rc.getTeam()).length
         > 0) // if there is an allied robot on our rally point
     {
       expandLocation = findClosestEmptyCamp();
       if (expandLocation == null) {
         expandLocation = findRallyPoint();
       }
       goToLocation(expandLocation);
     } else {
       goToLocation(expandLocation);
     }
     rc.yield();
   }
 }
  public void play() throws GameActionException {

    if (rc.isActive()) {
      rc.attackSquare(targetList.get(pos));
      if (pos < targetList.size() - 1) {
        pos++;
      } else {
        pos = 0;
      }
    } else {
      rc.yield();
    }
    /*
    if(!rc.canAttackSquare(currentTarget)){
    	currentTarget=firstTarget;
    }
    rc.attackSquare(currentTarget);
    currentTarget=currentTarget.add(DIRECTION_TO_HQ);
    currentTarget=currentTarget.add(DIRECTION_TO_HQ);
    */
  }
  public SoundStrategy(final RobotController rc, Random rand) throws GameActionException {
    targetList = new ArrayList<MapLocation>();
    this.rc = rc;
    int pastrChannel = 2;
    Message mp = Comms.ReadMessage(rc, pastrChannel);
    if (mp != null) {
      this.pastrLoc = mp.loc;
    } else {
      this.pastrLoc = null;
    }
    int increment = 2;
    // int increment=NOISE_SCARE_RANGE_SMALL; // this doesnt seem to exist in GameConstants?
    // The above strategy is pretty poor.  How about two-dimensional forloop
    // building an array of target MapLocations we can hit.
    for (int x = 0; x < rc.getMapWidth(); x = x + increment) {
      for (int y = 0; y < rc.getMapHeight(); y = y + increment) {
        if (rc.isActive()) {
          currentTarget = new MapLocation(x, y);
          if (rc.canAttackSquare(currentTarget)) {
            targetList.add(currentTarget);
            // System.out.println("Adding x:" + x + " y:" + y);
          }
        } else {
          rc.yield();
        }
      }
    }
    pos = 0;
    // sort by distance from rc.getLocation()

    Collections.sort(
        targetList,
        new Comparator<MapLocation>() {
          public int compare(MapLocation b, MapLocation a) {
            return new Integer(pastrLoc.distanceSquaredTo(a))
                .compareTo(pastrLoc.distanceSquaredTo(b));
          }
        });
  }
示例#30
0
  public static void run(RobotController rc) {

    enemyHQ = rc.senseEnemyHQLocation();
    myHQ = rc.senseHQLocation();
    mapHeight = rc.getMapHeight();
    mapWidth = rc.getMapWidth();

    while (true) {
      try {
        if (rc.getType() == RobotType.SOLDIER) {
          if (rc.isActive()) soldierRun(rc);
        } else if (rc.getType() == RobotType.HQ) {
          hqCode.hqRun(rc, enemyHQ);
        } else if (rc.getType() == RobotType.ARTILLERY) {
          encampCode.artilleryRun(rc);
        }
        rc.yield();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }