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); }
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(); } }