⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 platoonagent.java

📁 2004年robotcup世界冠军源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }    if(self() instanceof FireBrigade){        if ((!self().HasMovedInLastCycle()) && submittedMoveAct) {          if (prevRoute.end instanceof Building) {              bldg = (Building) prevRoute.end;              if(! (bldg instanceof Refuge)){                setBuildingIsFull(bldg , time);              }          }        }        MovingObject mo;        for(Iterator it = world.updatedmovingobjects.iterator();it.hasNext();){            mo = (MovingObject) it.next();            if( mo instanceof FireBrigade){                if(mo.motionlessPosition() instanceof Building){                    bldg = (Building) mo.motionlessPosition();                    if(!(bldg instanceof Refuge)){                        setBuildingIsFull(bldg , time);                    }                }            }        }    }  }  protected void setBuildingIsFull(Building bldg , int time){      fullBuildingsTimeMap.remove(bldg);      fullBuildingsTimeMap.put(bldg , time);  }  protected void updateLockedCivInfo() {//    Collection civPoses = BUILDING_C.not().and(AMBULANCE_TEAM_C.not()).extract(POSITION_PRP.collect(world.civilians));    if (self().motionlessPosition() instanceof Refuge)return;    Civilian civ;    MotionlessObject mo;    Road road;    Collection civs = CIVILIAN_C.and(ALIVE_C).and(BURIED_C.not()).extract(world.        updatedmovingobjects);    for (Iterator it = civs.iterator(); it.hasNext(); ) {      civ = (Civilian) it.next();      mo = civ.motionlessPosition();      if (mo instanceof Building || civ.position() instanceof AmbulanceTeam)continue;      if (isLockedInBlockades(civ)) {        road = world.getRespondingRoad(mo, mo);        if (NOT_PASSABLE_C.eval(road)) {          if (!world.m_lockedCivPos_Map.containsKey(civ))            world.m_lockedCivPos_Map.put(civ, road);        }      }    }  }  protected boolean shouldRoam = false;    protected void doSomethingIfWereStuckByHumanoids() {//    if (self() instanceof PoliceForce)return;        MotionlessObject pos = self().motionlessPosition();        if (pos instanceof Road &&            NOT_PASSABLE_C.eval((Road) pos)) return;        int time = time();        if(time <= TIME_STARTING_ACTION + 1 ) return;        if ((!self().HasMovedInLastCycle()) && submittedMoveAct) {          if(MRL.MRLConstants.ROUTING_DEBUG_MODE)              System.out.println(self() + " , Starting Determining Traffic : " + time());          if (pos instanceof Building)return;//      if( prevRoute.end instanceof Building ) return;//      Collection nearAgents = AGENT_C.extract(world.//                                              updatedmovingobjects);//      nearAgents.remove(self());//      if (nearAgents.isEmpty())return;          if (self() instanceof PoliceForce) {            Path path = world.getCurrentPath();            boolean isInPath;            if(path == null){              isInPath=false;              Route rt = prevRoute.trimStartTo(self().motionlessPosition());              MotionlessObject mo = rt.getObject(rt.getRouteCount()-1);              Road road;              if (mo instanceof Road) {                road = (Road) mo;              } else {                mo = rt.getObject(rt.getRouteCount() - 2);                if (mo instanceof Road)                  road = (Road) mo;                else{               //     System.err.println(self() + " Error , Invalid Prev Route");                    return; // Wanted To Go To A Building And Building Is Full                }              }              path = world.getContainingPath(road);            } else{              isInPath=true;            }            int fireSearchDist = EXTINGUISHABLE_DISTANCE; // =            MIN_FIRE_AVAILABLE_SEARCH            if(pos instanceof Road)                fireSearchDist += ((Road)pos).length()/2;            int nearFires = Utils.getConditionCount(world.burningBuildings,self().motionlessPosition().                                                    distancePrp.lte(fireSearchDist));            int notMoved = self().getStuckCycles();            if(notMoved ==0)                   throw new Error("WHA");            if(MRL.MRLConstants.ROUTING_DEBUG_MODE)                System.out.println(self() +" Has Not Moved For : " + notMoved);            if (nearFires == 0) {                if(notMoved < MAX_TIME_WAIT_TO_SET_TRAFFIC){                    requestAgentsGoingAway();                }                else if(notMoved<MAX_TIME_WAIT_TO_ROAM_FROM_TRAFFIC){                    setTraffic(path,time(),isInPath);                }                else{                    setTraffic(path,time(),isInPath);                    shouldRoam = true;                }              }            else {                if(notMoved<MAX_TIME_WAIT_TO_ROAM_FROM_TRAFFIC){                    setTraffic(path,time(),isInPath);                }                else{                    setTraffic(path,time(),isInPath);                    shouldRoam = true;                }            }            return;          } // Instanceof PoliceForce          Path cPath = world.getCurrentPath();          Road road;          Route rt = prevRoute.trimStartTo(self().motionlessPosition());          if (cPath == null) { // What Should They Do If They're Stuck By Eachother At A CrossWay?            Collection nei = ((Node) pos).getConnectedRoads();            Path path;            for (Iterator it = nei.iterator(); it.hasNext(); ) {              road = (Road) it.next();              if (rt.isContaining(road)) {                path = world.getContainingPath(road);                setTraffic(path,time(),false);              }            }          } else { // Agent Is In A Path                setTraffic(cPath,time(),true);          }        }      }  protected void setTraffic(Path path , int time , boolean isInPath){      if(isInPath){          Route traffRoute = getRouteCausedTrafficFromPrevRoute();          if(traffRoute != null){              Collection inPathTraffic = traffRoute.getObjects();              inPathTraffic.retainAll(path.getContainingObjects());              inPathTraffic.removeAll(path.getEdges());              if(MRL.MRLConstants.ROUTING_DEBUG_MODE)                  System.out.println(self() + " , Found : " + inPathTraffic.size() + " Objects From TrafficRoute .");              world.curCycleTraffObjs.addAll(inPathTraffic);          }          else              System.out.println(self() + " , Null Traffic Route .");        }      world.setTraffic(path,time());      if(MRL.MRLConstants.ROUTING_DEBUG_MODE)          System.out.println(self() + " , Detected Traffic In : " + path.getID() + " Started : " + world.trafficICCPs.get(path) + " , Time : " + time() + " Is In Path : " + isInPath);  }  protected void requestAgentsGoingAway() {    if (prevRoute == null)return;    Route rt = prevRoute.trimStartTo(self().motionlessPosition());    if (rt == null)return;    int[] arr = rt.toIDs();    int[] res;    if (arr.length > OBJS_TO_REQUEST_TO_CLEAR) {      res = new int[OBJS_TO_REQUEST_TO_CLEAR];      for (int i = 0; i < OBJS_TO_REQUEST_TO_CLEAR; i++)        res[i] = arr[i];    } else res = arr;//    for (int i = 0; i < res.length; i++) {//      res[i] = world.motionlessObjects.indexOf((RealObject) world.get(res[i]));//    }    if (res.length > 0)    {        String msg = "";        for (int i = 0; i < res.length; i++) {            if (i > 0) msg += ",";            msg += res[i];        }        if(MRL.MRLConstants.ROUTING_DEBUG_MODE)System.out.println(self() + " , Requesting Clearing : " + msg);        say(msg);    }  }  protected void correctTMPs() {    if (roamed && time() - m_prevTimeRoamed > 1) roamed = false;    Path cPath = world.getCurrentPath();    Path path;    int blockedTime;    int curTime = world.time();    for (Iterator it = world.trafficICCPs.keySet().iterator(); it.hasNext(); ) {      path = (Path) it.next();      blockedTime = ((Integer) world.trafficICCPs.get(path)).intValue();      if (path != cPath && curTime - blockedTime > MIN_TIME_TO_CLEAR_TRAFFIC) it.remove();    }//    world.trafficICCPs.retainAll(Collections.singleton(cPath)); // Should Be Dealed With More Carefully    /*         Road road;     for(Iterator it = m_Road_OrigBlockMap.keySet().iterator();it.hasNext();){      road = (Road) it.next();      if(cPath != null && cPath.contains(road)) continue;      assumeRoadIsUnBlocked(road);      it.remove();         }     */  }  protected void getFreeingRoute() {    MotionlessObject pos = self().motionlessPosition();    Node op = (Node) outsidePosition();    if (decidedRoute != null) {      if (MRL.MRLConstants.ROUTING_DEBUG_MODE) System.out.println(self() +          " , Already Decided Something , Not Running Get Freeing Route");      return;    }    Path cPath = world.getContainingPath(pos);    Road road = cPath.getNearestBlockedRoad(op);    Route routeToHead = cPath.getRouteToHeadFromNode(op),                        routeToTail = cPath.getRouteToTailFromNode(op);    if (road == null) { // One Way Is Surely Free !      if (true)return; /// Should Do Something Here      road = (Road) prevRoute.getObjects().get(1);      if (routeToHead.isContaining(road)) {        decidedRoute = routeToTail;      } else if (routeToTail.isContaining(road)) {        decidedRoute = routeToHead;      }//      else throw new Error("What?");    } else {      if (routeToHead.isContaining(road)) {        decidedRoute = routeToTail;      } else if (routeToTail.isContaining(road)) {        decidedRoute = routeToHead;      }//      else throw new Error("What?");    }//    Node target = prevRoute.isContaining(cPath.getFirstNode()) ? cPath.getFirstNode() : cPath.getLastNode();//    Route rt = Router.get(pos,Collections.singleton(target),HumanoidAgent.POLICE_COST_FUNCTION);//    decidedRoute=rt;  }    protected void tryToGetOutOfBlockades()  {        if (decidedRoute != null) {          if (MRL.MRLConstants.ROUTING_DEBUG_MODE) System.out.println(self() +              " , Already Decided Something , Not Running Get Freeing Route");          return;        }        if (self().motionlessPosition() instanceof Building)return;        Path cPath = world.getCurrentPath();        Node target = null;        if (cPath == null) { // At A CrossWay , It's Not Right To Decide Something Here            System.err.println(self() + " Invalid Usage For TryToGetOutOfBlockades ");          return;        } else {//      road = cPath.getNearestBlockedRoad(op);//      road = (Road) distancePrp.min(NOT_PASSABLE_C.extract(cPath));//      if (road == null) throw new Error("WHA");          Node cHN = cPath.getFirstNode(), cTN = cPath.getLastNode();          if (prevRoute == null) {            if (random.nextInt(100) > 50)              target = cHN; // Random ?            else target = cTN;          } else {            target = prevRoute.end == cHN ? cTN : cHN;          }          Route rt = getRouteFromCurrentPos(target,CLEARING_COST_FUNCTION);          if(MRL.MRLConstants.ROUTING_DEBUG_MODE) System.out.println(self() +                             " Found This Route TO Get Out Of Blockades : " + rt);          decidedRoute = rt;        }      }    protected void updateHums() {        int time = time();        Collection hums = NEED_RESCUE_C.extract(world.updatedmovingobjects);        Humanoid hum;        for (Iterator it = hums.iterator(); it.hasNext(); ) {          hum = (Humanoid) it.next();          if(!(hum.position() instanceof Building)) continue;//      if (!messagepool.isHumanoidReported(hum)) {//        messagepool.ReportHumanoid(hum);//        continue;//      }            world.civCheckTime.remove(hum);            world.civCheckTime.put(hum, new Integer(time));        }      }  protected final void reportBurriedness() {    if (self().buriedness() > 0)        messageManager.reportVictim(self());  }  /**   * todo Aghazadeh : How About Reporting BLOCKADES Instead Of One Block ??   */  protected final void reportLockedByBlockade()  {//    Path cpath = world.getCurrentPath();//    Road road = null;//    if (cpath == null) {//      for (Iterator it = ((Node) self().motionlessPosition()).getConnectedRoads().//                         iterator(); it.hasNext(); ) {//        cpath = world.getContainingPath((Road) it.next());//        if (cpath.passableLines() == 0)break;//      }//    }//    if (cpath == null)throw new Error("WHA!");//    List open = new ArrayList(), visited = new ArrayList();//    Collection res;//    open.add(cpath);//    while (!open.isEmpty()) {//      cpath = (Path) open.remove(0);//      if (cpath.passableLines() == 0)break;//      open.addAll(cpath.getConnectedPaths());//      open.removeAll(visited);//      visited.add(cpath);//    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -