Ejemplo n.º 1
0
 public void clearNearestBlockade() throws SOSActionException {
   log.info("clearing NearestBlockade");
   PriorityQueue<Blockade> blockadesInRange =
       model().getBlockadesInRange(agent.me().getX(), agent.me().getY(), agent.clearDistance);
   log.debug("Blockades in Range=" + blockadesInRange);
   Blockade selectedBlock = null;
   if (!blockadesInRange.isEmpty()) selectedBlock = blockadesInRange.remove();
   log.debug("best blockade:" + selectedBlock);
   if (selectedBlock != null) clear(selectedBlock);
 }
Ejemplo n.º 2
0
  public Pair<Area, Point2D> getEntrancePoint(Area dest) {
    if (dest == null) {
      log.error("why try to move to " + dest + "?????");
      return null;
    }
    Path path = agent.move.getPathTo(Collections.singleton(dest), PoliceMove.class);
    ArrayList<EntityID> pathArray = path.getIds();
    if (pathArray.isEmpty()) {
      log.error("path is empty. why????");
      return null;
    }

    Edge inComingEdge;
    if (pathArray.size() == 1) {
      inComingEdge = dest.getEdgeTo(agent.location());
    } else {
      inComingEdge = dest.getEdgeTo(pathArray.get(pathArray.size() - 2));
    }
    if (inComingEdge == null) return new Pair<Area, Point2D>(dest, dest.getPositionPoint());
    Line2D wallLine =
        inComingEdge
            .getLine(); // new Line2D(edge.getStartX(), edge.getStartY(), edge.getEndX() -
                        // edge.getStartX(), edge.getEndY() - edge.getStartY());

    Vector2D offset;
    if (AliGeometryTools.havecorrectDirection(dest)) {
      offset = wallLine.getDirection().getNormal().normalised().scale(10);
    } else {
      offset = wallLine.getDirection().getNormal().normalised().scale(-10);
    }
    Point2D destXY = inComingEdge.getMidPoint().plus(offset);
    return new Pair<Area, Point2D>(dest, destXY);
  }
Ejemplo n.º 3
0
  private int computeBlockadeValue(Blockade blockade) {
    return (int)
        (1000000 / Math.max(agent.me().getPositionPoint().distance(blockade.getCenteroid()), 1));
    // return 100000 / blockade.getRepairCost();
    // TODO
    // moteallegh be kodam sakhteman hastand.(CV)

  }
Ejemplo n.º 4
0
 public void move(Path path) throws SOSActionException {
   log.info("moving to path: " + path);
   if (path == null) {
     log.error("path is null!!!");
     moveToARandomArea();
   }
   justMakeReachable(path);
   agent.move(path);
 }
Ejemplo n.º 5
0
 public boolean isReachableTo(StandardEntity se) {
   if (se instanceof Human) {
     Human hum = (Human) se;
     if (agent.getVisibleEntities(Human.class).contains(hum)
         && hum.isPositionDefined()
         && hum.getAreaPosition().isBlockadesDefined()) {
       for (Blockade blockade : hum.getAreaPosition().getBlockades()) {
         if (blockade.getShape().contains(hum.getPositionPoint().toGeomPoint())) return false;
       }
     }
     if (!hum.getImReachableToEdges().isEmpty())
       return agent
           .move
           .getMoveType(PoliceReachablityMove.class)
           .isReallyReachableTo(hum.getImReachableToEdges());
   }
   return isReachableTo(se.getPositionPair());
 }
Ejemplo n.º 6
0
  private void justMakeReachableWithGoodReachablity(Path path) throws SOSActionException {
    log.info("making reachable with good reachablity to " + path);

    ArrayList<Blockade> blocks = reachablityTool.getBlockingBlockadeOfPath(path);
    log.debug("clearableBlockadeToReachablebyReachablityTool is " + blocks);
    ArrayList<Blockade> blockadeEdge = reachableWithEdge.getBlockingBlockadeOfPath(path);
    blocks.addAll(blockadeEdge);

    log.debug("clearableBlockadeToReachableWithEdge is " + blocks);

    Blockade clearBlock = chooseBestBlockade(blocks);

    if (clearBlock != null) clear(clearBlock);
    else if (clearBlock == null && !blocks.isEmpty()) {
      log.debug("No blockade is in range but the path is close!!! so move to close area");
      ArrayList<Pair<? extends Area, Point2D>> dest =
          new ArrayList<Pair<? extends Area, Point2D>>();
      for (Blockade blockade : blocks) {
        dest.add(blockade.getPositionPair());
      }
      path = agent.move.getPathToPoints(dest, PoliceMove.class);
      agent.move(path);
    } else log.debug("No Blockade found---> we can move");
  }
Ejemplo n.º 7
0
 private void moveWithGoodReachablity(Path path) throws SOSActionException {
   log.info("moving with good reachablity to path: " + path);
   justMakeReachableWithGoodReachablity(path);
   agent.move(path);
 }
Ejemplo n.º 8
0
 protected PoliceWorldModel model() {
   return agent.model();
 }
Ejemplo n.º 9
0
 public boolean isReachableTo(Pair<? extends Area, Point2D> b) {
   return agent.isReachableTo(b);
 }
Ejemplo n.º 10
0
 protected void clear(Point point) throws SOSActionException {
   agent.clear(point);
 }
Ejemplo n.º 11
0
 protected void clear(Blockade blockade) throws SOSActionException {
   log.info("clearing " + blockade);
   agent.clear(blockade);
 }