Beispiel #1
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) {
     }
   }
 }
Beispiel #2
0
  public static void runCowboy(RobotController rc, int assignment) throws GameActionException {

    if (assignment == 0) assignment = rc.readBroadcast(rc.getRobot().getID());

    int squad = Channels.assignmentDecoding(assignment)[0];
    int role = Channels.assignmentDecoding(assignment)[1];

    if (rc.readBroadcast(squad) == 0) {
      System.out.println(
          "My time has elapsed. I must die in battle with honor for my squad " + squad + "!");
      kamikaze(rc);
    }

    // checkIfBackupNeeded(rc);

    switch (role) {
      case 0:
        COWBOY.runDefender(rc, squad);
        break;
      case 1:
        COWBOY.runAttacker(rc, squad);
        break;
      case 2:
        COWBOY.runScout(rc, squad);
        break;
    }

    rc.yield();
  }
  /* (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;
  }
  // All combat units (Soldiers, Bashers, Tanks, Drones, Launchers, Commander)
  private static void runCombat() {
    while (true) {
      threats.update();
      myLoc = rc.getLocation();

      // Move if we can and want to
      if (rc.isCoreReady()) {
        boolean ignoreThreat = overwhelms();

        if (!ignoreThreat && shouldRetreat()) {
          if (rc.isWeaponReady() && myType.loadingDelay == 0) attackWeakest();
          doRetreatMove(); // Pull back if in range of the enemy guns
        } else {
          boolean engaged = false;
          if (rc.isCoreReady() && inCombat(4)) engaged = doCloseWithEnemyMove(ignoreThreat);
          if (rc.isCoreReady()
              && !engaged) // Close with enemy might not do a move if the enemy is a drone out of
                           // reach
          doAdvanceMove();
        }
      }

      // Attack if there is an enemy in sight
      if (myType == RobotType.LAUNCHER) doLaunch();
      else if (rc.isWeaponReady()) attackWeakest();

      doTransfer();

      rc.yield();
    }
  }
  // Drones
  private static void runDrone() {
    moveDir = Direction.NORTH;
    droneMoveCurrent = 1;
    droneMoveMax = 2;
    patrolClockwise = true;
    droneCentred = false; // We haven't made it to the centre of our spiral yet

    while (true) {
      threats.update();
      myLoc = rc.getLocation();

      // Attack if there is an enemy in sight
      if (rc.isWeaponReady()) attackWeakest();

      // Move if we can and want to
      if (rc.isCoreReady()) {
        if (shouldRetreat()) {
          doRetreatMove(); // Pull back if in range of the enemy guns
        } else if (Clock.getRoundNum() < 600) {
          doPatrol();
        } else {
          doSupply();
        }
      }

      doTransfer();

      rc.yield();
    }
  }
Beispiel #6
0
  public static void run(RobotController rcIn) {
    rc = rcIn;

    while (true) {
      try {
        if (rc.getType() == RobotType.HQ) {
          Hatchery hatchery = new Hatchery(rc);
          hatchery.run();
        } else if (rc.getType() == RobotType.NOISETOWER) {
          GenericTower tower = new GenericTower(rc, false);
          tower.run();
        } else if (rc.getType() == RobotType.PASTR) {

        }
        // other wise we must be a soldier
        else {
          // our hq spawns larva which run to a rally point and then morph into whatever unit is
          // most critical at that point
          Larva larva = new Larva(rc);
          larva.run();
        }
      } catch (Exception e) {
        e.printStackTrace();
        System.out.println("RobotPlayer Exception");
      }
      rc.yield();
    }
  }
  private static void runTower() {
    while (true) {
      threats.update();

      // Attack if there is an enemy in sight
      if (rc.isWeaponReady()) attackWeakest();

      rc.yield();
    }
  }
Beispiel #8
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();
    }
  }
  private static void runMissile() {
    int lastTurn = Clock.getRoundNum() + GameConstants.MISSILE_LIFESPAN;
    int[] damageRange = {0, 8, 15, 24, 35, 48};
    MapLocation target = null;
    boolean targetMoves = true;

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

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

      try {
        if (target != null) {
          if (myLoc.distanceSquaredTo(target) <= GameConstants.MISSILE_RADIUS_SQUARED) rc.explode();
          else {
            Direction d = myLoc.directionTo(target);
            if (rc.canMove(d)) rc.move(d);
            else if (rc.canMove(d.rotateLeft())) rc.move(d.rotateLeft());
            else if (rc.canMove(d.rotateRight())) rc.move(d.rotateRight());
          }
        }
      } catch (GameActionException e) {
        System.out.println("Missile exception");
        // e.printStackTrace();
      }
      rc.yield();
    }
  }
 public 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();
   }
 }
  // Factories and supply depots
  private static void runBuilding() { // Most builds spawn units
    if (myType.canSpawn()) strategy = new BuildStrategy(rc);

    while (true) {
      if (rc.isCoreReady() && myType.canSpawn()) {
        threats.update();
        RobotType build = strategy.getBuildOrder();
        if (build != null) trySpawn(rc.getLocation().directionTo(threats.enemyHQ), build);
      }

      doTransfer();

      rc.yield();
    }
  }
  // Beavers
  private static void runBeaver() {
    strategy = new BuildStrategy(rc);
    rand = new Random(rc.getID());

    while (true) {
      threats.update();
      myLoc = rc.getLocation();

      if (rc.isCoreReady()) {
        RobotType build = strategy.getBuildOrder();
        if (build != null) tryBuild(rc.getLocation().directionTo(threats.enemyHQ), build);
      }

      // Attack if there is an enemy in sight
      if (rc.isWeaponReady()) attackWeakest();

      double ore = rc.senseOre(rc.getLocation());

      // Move if we can and want to
      if (rc.isCoreReady()) {
        boolean ignoreThreat = overwhelms();

        if (!ignoreThreat && shouldRetreat()) {
          doRetreatMove(); // Pull back if in range of the enemy guns
        } else {
          doMinerMove();
          if (ore == 0 && rc.isCoreReady()) { // We didn't find ore nearby
            doSearchMove();
          }
        }
      }

      // Mine if possible
      if (rc.isCoreReady() && ore > 0) {
        try {
          rc.mine();
        } catch (GameActionException e) {
          System.out.println("Mining Exception");
          // e.printStackTrace();
        }
      }

      doTransfer();

      rc.yield();
    }
  }
Beispiel #13
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();
   }
 }
Beispiel #14
0
  public static void soldierCode(RobotController myRC) throws GameActionException {
    rc = myRC;
    rallyPoint = findRallyPoint();
    while (true) {
      try {
        // returns all enemy robots within our sight range (aka that we can actually fight right now
        // or very soon)
        Robot[] closeEnemyRobots =
            rc.senseNearbyGameObjects(Robot.class, rc.getLocation(), 14, rc.getTeam().opponent());

        // returns all enemy robots reasonably close to us (aka that we should move toward and
        // potentially assist our allies in fighting)
        Robot[] enemyRobots = rc.senseNearbyGameObjects(Robot.class, 63, rc.getTeam().opponent());

        if (closeEnemyRobots.length == 0 && enemyRobots.length == 0) // no enemies are nearby
        {
          int command = HQCommand();
          switch (command) {
            case Constants.commandExpand:
              expand();
              break;
            case Constants.commandRally:
              rally();
              break;
            case Constants.commandEnemyNukeHalfDone:
              rally();
            case Constants.commandBuildIndividual: // TODO- implement this
              break;
          }
        } else {

          // enemy spotted
          localscan = false;
          MapLocation closestEnemy = findClosestRobot(enemyRobots);
          goToLocation(closestEnemy);
        }
      } catch (Exception e) {
        System.out.println("Soldier Exception");
        e.printStackTrace();
      }
      rc.yield();
    }
  }
  public static void run(RobotController myRC) {
    rc = myRC;
    barracks = findBarracks();
    while (true) {
      try {
        if (rc.getType() == RobotType.SOLDIER) {
          Robot[] enemyRobots =
              rc.senseNearbyGameObjects(
                  Robot.class, 50000, rc.getTeam().opponent()); // list of enemy robots
          if (enemyRobots.length == 0) {
            Clock.getRoundNum(); // gets the round number
            if (Clock.getRoundNum() < 250) {
              goToLocation(
                  barracks); // if you are before round 250 travel to the "barracks" or meeting
                             // place.
            } else {
              goToLocation(rc.senseEnemyHQLocation());
            }
          } else { // else attack the closest enemy
            int closestDist = 50000;
            MapLocation closestEnemy = null;
            for (int i = 0; i < enemyRobots.length; i++) {
              Robot enemyBot = enemyRobots[i];
              RobotInfo arobotInfo = rc.senseRobotInfo(enemyBot);
              int dist = arobotInfo.location.distanceSquaredTo(rc.getLocation());
              if (dist < closestDist) {
                closestDist = dist;
                closestEnemy = arobotInfo.location;
              }
            }
            goToLocation(closestEnemy);
          }
        } else {
          HqCommand();
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
      rc.yield(); // end turn
    }
  }
  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);
    */
  }
Beispiel #17
0
  public static void runHeadquarters(RobotController rc) throws GameActionException {

    if (!initializerRun) initializeGameVars(rc);

    updateSquadLocs(rc);
    updateRobotDistro(rc);

    rush = reactiveRush(rc); // TODO Be able to switch to a rush strategy midgame
    if (rush) {
      rc.broadcast(Util.strategyChannel, 1);
    }

    Robot[] allies =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().attackRadiusMaxSquared, team);
    Robot[] enemyRobots =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().attackRadiusMaxSquared, enemy);
    if (enemyRobots.length > 0) Util.indivShootNearby(rc, enemyRobots);
    else spawnRobot(rc);

    rc.yield();
  }
Beispiel #18
0
 private static void soldierRun(RobotController rc) throws GameActionException {
   Bug b = new Bug(rc.senseEnemyHQLocation(), rc);
   while (true) {
     b.go();
     rc.yield();
   }
   // MapLocation[] neutralMines = rc.senseMineLocations(rc.getLocation(), 2, Team.NEUTRAL);
   // MapLocation[] enemyMines = rc.senseMineLocations(rc.getLocation(), 2,
   // rc.getTeam().opponent());
   /*if (rc.senseEncampmentSquare(rc.getLocation())) {
   	if (rc.senseCaptureCost() < rc.getTeamPower()) rc.captureEncampment(RobotType.ARTILLERY);
   	return;
   }
   MapLocation[] nearbyEncampments;
   nearbyEncampments = rc.senseEncampmentSquares(rc.getLocation(), 16, Team.NEUTRAL);
   if (nearbyEncampments.length != 0) {
   	Direction dir = rc.getLocation().directionTo(nearbyEncampments[0]);
       if (rc.canMove(dir)) rc.move(dir);
       else rc.move(randomDir(rc));
   } else rc.move(randomDir(rc));*/
 }
  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));
          }
        });
  }
Beispiel #20
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();
      }
    }
  }
  // Computers
  private static void runOther() {
    int numTowers = -1;
    while (true) {
      threats.update();
      myLoc = rc.getLocation();

      // Move if we can and want to
      if (rc.isCoreReady() && myType.canMove()) {
        if (shouldRetreat()) doRetreatMove(); // Pull back if in range of the enemy guns
        else doAdvanceMove(); // Move towards our HQ
      }

      doTransfer();

      // Perform a background breadth first search to the enemy HQ
      if (myType == RobotType.COMPUTER && Clock.getBytecodesLeft() > 1000) {
        bfs.work(threats.enemyHQ, Bfs.PRIORITY_HIGH, 1000, numTowers != threats.enemyTowers.length);
      }
      numTowers = threats.enemyTowers.length;
      rc.yield();
    }
  }
Beispiel #22
0
 public static void pullInto(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 {
       while (toFire.distanceSquaredTo(center) > 3) {
         if (toFire.x >= 0
             && toFire.x < rc.getMapWidth()
             && toFire.y >= 0
             && toFire.y < rc.getMapHeight()) {
           try {
             rc.attackSquare(toFire);
             rc.yield();
           } catch (Exception e) {
           }
         }
         toFire = toFire.add(directions[k].opposite());
       }
     } catch (Exception e) {
     }
   }
 }
Beispiel #23
0
  public static void run(RobotController rc) {
    int type = 0;

    while (true) {
      try {
        if (rc.getType() == RobotType.HQ) {
          new SmartHQ(rc).run();
        } else if (rc.getType() == RobotType.NOISETOWER) {
          new GenericTower(rc, false).run();
        } else if (rc.getType() == RobotType.PASTR) {
          rc.yield();
        } else {
          if (type == 0) {
            type = rc.readBroadcast(0);
          } else if (type == SmartHQ.DURAN) {
            // new Duran(rc).run();
          } else if (type == SmartHQ.GHOST) {
            // new Ghost(rc).run();
          } else if (type == SmartHQ.GOLIATH) {
            // new Goliath(rc).run();
          } else if (type == SmartHQ.MARINE) {
            // new Marines(rc).run();
          } else if (type == SmartHQ.MULE) {
            new fastMULE(rc, true).run();
          } else if (type == SmartHQ.TOWER) {
            new SmartTower(rc, true).run();
          } else if (type == SmartHQ.TROLL) {
            // new Scout(rc).run();
          } else if (type == SmartHQ.OPTOWER) {
            new SmartTower(rc, false).run();
          } else if (type == SmartHQ.OPMULE) {
            new fastMULE(rc, false).run();
          }
        }
      } catch (Exception e) {
      }
    }
  }
Beispiel #24
0
 private static void rally() throws GameActionException {
   rallyPoint = findRallyPoint();
   // if we are fairly close to the rally point and we have the necessary soldier counts to make up
   // a wave, gogogogogo
   if (rc.getLocation().distanceSquaredTo(rallyPoint) < rallyRadius) {
     if (rc.readBroadcast(Constants.attackChannel) == Constants.attackAllIn) {
       while (true) {
         Robot[] closeEnemyRobots =
             rc.senseNearbyGameObjects(Robot.class, rc.getLocation(), 14, rc.getTeam().opponent());
         if (closeEnemyRobots.length == 0) {
           goToLocation(rc.senseEnemyHQLocation());
         } else {
           goToLocation(Util.findClosestRobot(rc, closeEnemyRobots));
         }
         rc.yield();
       }
     } else {
       goToLocation(rallyPoint);
     }
   } else {
     goToLocation(rallyPoint);
   }
 }
  public static void run(RobotController rcIn) throws GameActionException {
    rc = rcIn;
    randall.setSeed(rc.getRobot().getID());

    if (rc.getType() == RobotType.HQ) {
      tryToSpawn();
    } else {
      BreadthFirst.init(rc, bigBoxSize);
      MapLocation goal = getRandomLocation();
      path =
          BreadthFirst.pathTo(
              VectorFunctions.mldivide(rc.getLocation(), bigBoxSize),
              VectorFunctions.mldivide(goal, bigBoxSize),
              100000);
      // VectorFunctions.printPath(path,bigBoxSize);
    }

    // generate a coarsened map of the world
    // TODO only HQ should do this. The others should download it.
    //		MapAssessment.assessMap(4);
    //		MapAssessment.printBigCoarseMap();
    //		MapAssessment.printCoarseMap();

    while (true) {
      try {
        if (rc.getType() == RobotType.HQ) {
          runHQ();
        } else if (rc.getType() == RobotType.SOLDIER) {
          runSoldier();
        }
      } catch (Exception e) {
        // e.printStackTrace();
      }
      rc.yield();
    }
  }
Beispiel #26
0
  public static void run(RobotController rc) {
    Utils.initUtils(rc);
    RobotBehavior robot = null;
    switch (rc.getType()) {
      case HQ:
        // Strategy strategy = Strategy.decide();
        robot = new HQBehavior();
        break;
      case SOLDIER:
        robot = new SoldierBehavior();
        break;
      case PASTR:
        robot = new PastrBehavior();
        break;
      case NOISETOWER:
        try {
          robot = new OctantNoiseTowerBehavior();
        } catch (GameActionException e1) {
          e1.printStackTrace();
        }
        break;
      default: // autokill
        return;
    }

    while (true) {
      try {
        robot.beginRound();
        robot.run();
        robot.endRound();
        rc.yield();
      } catch (GameActionException e) {
        e.printStackTrace();
      }
    }
  }
  public static void run(RobotController rc) {
    try {
      switch (rc.getType()) {
        case HQ:
          while (true) {

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

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

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

            rc.yield();
          }

        case SOLDIER:
          while (true) {

            if (rc.isActive()) {}

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

            if (rc.isActive()) {}

            rc.yield();
          }

        case GENERATOR:
          while (true) {

            if (rc.isActive()) {}

            rc.yield();
          }

        case MEDBAY:
          while (true) {

            if (rc.isActive()) {}

            rc.yield();
          }

        case SHIELDS:
          while (true) {

            if (rc.isActive()) {}

            rc.yield();
          }

        case SUPPLIER:
          while (true) {

            if (rc.isActive()) {}

            rc.yield();
          }

        default:
          break;
      }
    } catch (Exception e) {
      rc.breakpoint();
      e.printStackTrace();
      // run(rc);
    }
  }
Beispiel #28
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();
    }
  }
Beispiel #29
0
  public static void MoveMapLocation(RobotController rc, MapLocation target, boolean sneak) {
    MapLocation[] pastLocations = new MapLocation[10];
    int side = 45;
    Direction dir;
    Direction newDir;
    rand = new Random();
    // we initialize pastLocations to hold our current location 5 times
    for (int i = 0; i < pastLocations.length; i++) {
      pastLocations[i] = rc.getLocation();
    }

    // this method will run until we get to our target location
    while (!rc.getLocation().equals(target)) {
      // we put the try block inside of the while loop so an exception won't terminate the method
      try {
        dir = rc.getLocation().directionTo(target);
        newDir = Direction.NONE;

        // simple shoot at an enemy if we see one will need to be improved later
        Robot[] nearbyEnemies = rc.senseNearbyGameObjects(Robot.class, 10, rc.getTeam().opponent());
        if (nearbyEnemies.length > 0 && rc.senseRobotInfo((Robot) nearbyEnemies[0]).health < 201) {
          fire(rc);
        }
        // if we can move towards target and we haven't been on the square recently then lets move
        else if (rc.canMove(dir)
            && !MapLocationInArray(rc, rc.getLocation().add(dir), pastLocations)) {
          newDir = dir;
          // if we found a direction to move then we go to it
          if (newDir != Direction.NONE) {
            // now we decide if we are going to sneak or run
            if (sneak) {
              // another check to make sure we don't throw any exceptions
              if (rc.isActive() && rc.canMove(newDir)) {
                // System.out.println(newDir);
                rc.sneak(newDir);
              }
            } else {
              // another check to make sure we don't throw any exceptions
              if (rc.isActive() && rc.canMove(newDir)) {
                rc.move(newDir);
              }
            }
          }
          side = 45;
        } else {
          // if their is a robot blocking our way then we just move in a random direction
          if (rc.senseObjectAtLocation(rc.getLocation().add(dir)) != null) {
            // newDir = directions[rand.nextInt(8)];
            MoveDirection(rc, dir, sneak);
          } else {
            // rc.setIndicatorString(2, "Looking elswhere");
            Direction dir2 = dir;
            MapLocation right;
            MapLocation left;
            dir2 = (dir.rotateRight());
            while (!rc.canMove(dir2)) {
              dir2 = dir2.rotateRight();
            }
            right = rc.getLocation().add(dir2);

            dir2 = dir.rotateLeft();
            while (!rc.canMove(dir2)) {
              dir2 = dir2.rotateLeft();
            }

            left = rc.getLocation().add(dir2);

            // left seems better so lets go that way
            if (left.distanceSquaredTo(target) < right.distanceSquaredTo(target)) {
              side = 1;
            }
            // right seems better so lets try that way
            else {
              side = 0;
            }

            // we will go hugging one side of obstacle until we get back on our original line
            while (!dir2.equals(dir) && !rc.getLocation().equals(target)) // && rc.canMove(dir2))
            {
              try {
                if (rc.isActive()) {
                  // rc.setIndicatorString(1, "Trying to Avoid");
                  // rc.setIndicatorString(2, ""+side);
                  dir2 = rc.getLocation().directionTo(target);
                  if (rc.canMove(dir2)
                      && !MapLocationInArray(rc, rc.getLocation().add(dir2), pastLocations)) //  &&
                  // !rc.senseTerrainTile(rc.getLocation().add(dir2).add(dir2)).equals(TerrainTile.VOID))
                  {
                    // rc.setIndicatorString(0, "Going straight");
                  } else {
                    for (int i = 0; i < 4; i++) {
                      if (side == 1) {
                        dir2 = dir2.rotateLeft();
                      } else {
                        dir2 = dir2.rotateRight();
                      }
                      if (rc.senseTerrainTile(rc.getLocation().add(dir2))
                          .equals(TerrainTile.OFF_MAP)) {
                        dir2 = Direction.NONE;
                        i = 48;
                      } else if ((rc.canMove(dir2)
                          || (rc.senseObjectAtLocation(rc.getLocation().add(dir2))
                              != null))) // && !MapLocationInArray(rc, rc.getLocation().add(dir2),
                      // pastLocations))// &&
                      // !rc.senseTerrainTile(rc.getLocation().add(dir2).add(dir2)).equals(TerrainTile.VOID))
                      {
                        i = 48;
                      } else if (i == 3) {
                        dir2 = Direction.NONE;
                        // rc.setIndicatorString(1, "We failed to find a spot");
                      }
                    }
                  }

                  // if we can move
                  if (dir2 != Direction.NONE) {
                    if (rc.isActive()) {
                      if (rc.canMove(dir2)) {
                        if (sneak) {
                          rc.sneak(dir2);
                        } else {
                          rc.move(dir2);
                        }
                      } else {
                        MoveDirection(rc, dir2, sneak);
                      }
                    }
                  } else {
                    if (side == 1) {
                      side = 0;
                    } else {
                      side = 1;
                    }
                  }
                }
                // rc.setIndicatorString(0, "Dir: "+ dir +" Dir2: " + dir2);
              } catch (Exception e) {
                // tell the console we through an exception in utility object for debug purposes
                // System.out.println("Utility Exception");
                // System.out.println(e.toString());
                e.printStackTrace();
                rc.yield();
              }
              if (!rc.getLocation().equals(pastLocations[(pastLocations.length - 1)])) {
                for (int j = 0; j < (pastLocations.length - 1); j++) {
                  pastLocations[j] = pastLocations[j + 1];
                  // System.out.println(pastLocations[j]);
                }
                // stick current local into array
                pastLocations[(pastLocations.length - 1)] = rc.getLocation();
              }

              rc.yield();
            }
            // rc.setIndicatorString(1, "Not trying to Avoid");
          }
        }

        // now we  shift everything up one in pastLocations
        if (rc.getLocation() != pastLocations[(pastLocations.length - 1)]) {
          for (int j = 0; j < (pastLocations.length - 1); j++) {
            pastLocations[j] = pastLocations[j + 1];
            // System.out.println(pastLocations[j]);
          }
          // stick current local into array
          pastLocations[(pastLocations.length - 1)] = rc.getLocation();
        }

        rc.yield();
      } catch (Exception e) {
        // tell the console we through an exception in utility object for debug purposes
        System.out.println("Utility Exception");
        e.printStackTrace();
        // System.out.println(e.toString());
        rc.yield();
      }
    }
  }
 public static void run(RobotController myRC) {
   rc = myRC;
   rallyPoint = findRallyPoint();
   while (true) {
     try {
       if (rc.getType() == RobotType.SOLDIER) {
         if (rc.senseEncampmentSquare(rc.getLocation())) {
           if (rc.getTeamPower() > 10 * (rc.senseAlliedEncampmentSquares().length + 10)) {
             rc.captureEncampment(RobotType.SUPPLIER);
           } else {
             rc.captureEncampment(RobotType.GENERATOR);
           }
         } else {
           Robot[] enemyRobots =
               rc.senseNearbyGameObjects(Robot.class, 100000, rc.getTeam().opponent());
           if (enemyRobots.length == 0
               || (enemyRobots.length == 1
                   && rc.senseRobotInfo(enemyRobots[0]).type
                       == RobotType.HQ)) { // no enemies nearby
             Robot[] alliedRobots = rc.senseNearbyGameObjects(Robot.class, 1000000, rc.getTeam());
             if (alliedRobots.length < 5 * (rc.senseAlliedEncampmentSquares().length) + 1) {
               if (Math.random() < 0.1 && alliedRobots.length < 20) {
                 if (rc.senseMine(rc.getLocation()) == null) {
                   rc.layMine();
                 }
               }
               goToLocation(rallyPoint);
             } else {
               goToLocation(rc.senseEnemyHQLocation());
             }
           } else { // someone spotted
             int closestDist = 100000;
             MapLocation closestEnemy = null;
             for (int i = 0; i < enemyRobots.length; i++) {
               Robot arobot = enemyRobots[i];
               RobotInfo arobotInfo = rc.senseRobotInfo(arobot);
               int dist = arobotInfo.location.distanceSquaredTo(rc.getLocation());
               if (dist < closestDist) {
                 closestDist = dist;
                 closestEnemy = arobotInfo.location;
               }
             }
             Robot[] nearbyAllies = rc.senseNearbyGameObjects(Robot.class, 64, rc.getTeam());
             if (nearbyAllies.length > 2.5 * enemyRobots.length) {
               if (closestDist > 4) {
                 goToLocation(closestEnemy);
               }
             }
             goToLocationAvoidMines(closestEnemy);
           }
         }
       } else {
         hqCode();
       }
     } catch (Exception e) {
       //				System.out.println("caught exception before it killed us:");
       //				e.printStackTrace();
     }
     rc.yield();
   }
 }