/** Test of run method, of class BreadthFirst. */
 @Test
 public void testRun() {
   System.out.println("run");
   Maze maze = new Maze();
   maze.setStart(maze.getMazeCell(0, 0));
   BreadthFirst instance = new BreadthFirst();
   instance.run(maze);
   MazeCell cell = maze.getStart();
   Node[] nodes = cell.getNodes();
   for (Node node : nodes) {
     if (node != null) {
       assertTrue(0.5 == node.getValue());
     }
   }
 }
  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();
    }
  }
Example #4
0
 public static void generateProposals(
     MapLocation locus,
     int distToLocus,
     int incrementalDist,
     ArrayList<Proposal> proposalList,
     Direction[] consideredDirs) {
   for (Direction d : consideredDirs) {
     Proposal p;
     if (d.isDiagonal()) {
       p = new Proposal(locus.add(d), d, distToLocus + incrementalDist * 14);
     } else {
       p = new Proposal(locus.add(d), d, distToLocus + incrementalDist * 10);
     }
     int val = BreadthFirst.getMapData(p.loc);
     if (val > 0) { // not off-map or entirely void-filled
       p.dist +=
           Math.pow((val - 10000), 2)
               * 10; // TODO evaluate fudge factor of 10 for importance of void spaces
       proposalList.add(p);
     }
   }
 }