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

📄 platoonagent.java

📁 2004年robotcup世界冠军源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
      do{        rnd = random.nextInt(world.roads.size());        road = (Road) world.roads.get(rnd);      } while (world.isInTraffic(road));    }    if (MRL.MRLConstants.ROUTING_DEBUG_MODE) System.out.println(self() +        " , Time : " + time() + " , Roaming To : " + road);    roamed = true;    m_prevTimeRoamed = time();    move(road);  }  protected void exitIfIsBurning() throws ActionCommandException {    if (self() instanceof AmbulanceTeam || self() instanceof PoliceForce)return;    MotionlessObject pos = self().motionlessPosition();    if (pos instanceof Building) {      if (pos instanceof Refuge)return;      Building bldg = (Building) pos;      if (bldg.isBurning()) move(bldg.entrance());    }  }  protected void restIfIsDamaging() throws ActionCommandException {    if(self() instanceof FireBrigade ) return;    if (self().damage() > 50 && self().hp()<3000) {      restAtRefuge();    }  }  protected void restAtRefuge() throws ActionCommandException {    if (self().motionlessPosition() instanceof Refuge) {      rest();    }    move(world.refuges);  }    protected void searchCivilians(boolean onlyInPartition) throws ActionCommandException { // Also Makes Everyone Except One With Smallest ID Roam If They're In Same Building      if(onlyInPartition && searchingPartition() == null) return;      if(time() < 10) ATCivSearch();//      kaneNeedKaneVisibleCivs();      gotoPossibleCivBuildings(onlyInPartition);      moveNearFireBuildings(onlyInPartition); // Must Implement Partitioning      simpleSearch(onlyInPartition);    }    protected void kaneNeedKaneVisibleCivs() throws ActionCommandException{      List visibleNeedKaneCivs = SHOULD_KANE_CIVS.extract(world.updatedmovingobjects);      List vags = PLATOON_C.extract(world.updatedmovingobjects);      if(visibleNeedKaneCivs.size()>0){          Humanoid hum;          Building bldg,res=null;          int hp , minhp = Integer.MAX_VALUE;          for(Iterator it = visibleNeedKaneCivs.iterator();it.hasNext();){              hum = (Humanoid) it.next();              bldg = (Building) hum.motionlessPosition();              if(bldg.isBurning()) continue;              if(Utils.getConditionCount(vags,AMBULANCE_TEAM_C.and(POSITION_PRP.eq(bldg))) > 0) continue;              if(FULL_BUILDING_C.eval(bldg)) continue;              if(! REACHABLE_C.eval(bldg)) continue;              hp = hum.hp();              if(hp < minhp){                  minhp = hp;                  res = bldg;              }          }          if(res == null) return;          if(self().motionlessPosition() == res){              if(vags.indexOf(self()) > 0 ) return;              rest();          }else{              if(vags.indexOf(self()) > 0 ) return;              checkShouldContinueToBuildingAndMove(res, false,false);          }      }    }    private final int SIMPLE_SEARCH = 0 , NEAR_FIRE_SEARCH = 1 , AVAILABLE_SEARCH = 2 , HEARED_CIVILIAN_SEARCH = 3;    private Building m_lastSSBldg = null;    protected void simpleSearch(boolean onlyInPartition) throws ActionCommandException{      if(onlyInPartition && searchingPartition() == null) return;//      System.out.println(self() + " , Doing Simple Search In : " + time());      checkShouldContinueToBuildingAndMove(m_lastSSBldg,onlyInPartition,true);      List toCheckBuildings;      if(onlyInPartition){        List toCheckBuildingsIP = searchingPartition().ML_OBJS_IN_PART_CND.extract( //            world.unvisitedBuildings);            toCheckBuildings = correctListToCheck(toCheckBuildingsIP);      }      else{          toCheckBuildings= correctListToCheck(world.unvisitedBuildings);      }      if (!toCheckBuildings.isEmpty()) {        moveFirstToNearsThenToFarers(toCheckBuildings,SIMPLE_SEARCH);      }    }    protected void moveFirstToNearsThenToFarers(List bldgs,int search) throws // Relying On Hearing Mechanism        ActionCommandException {      if(bldgs.isEmpty()) return;      List nearBldgs ;      int searchRadius = HUMANOID_SEARCH_RADIUS * 2;      nearBldgs = distancePrp.lte(searchRadius).and(distancePrp.gte(MAX_HEARING_DISTANCE)).                    extract(bldgs);      if (!nearBldgs.isEmpty()) {          moveRandomBuilding(nearBldgs , search);      }      moveRandomBuilding(bldgs,search);    }    protected void checkShouldContinueToBuildingAndMove(Building bldg,boolean onlyInPartition,boolean mustBeNew) throws ActionCommandException{        if(bldg == null) return;        if(self().motionlessPosition() == bldg) return;        if(bldg.isBurning() || bldg.isBurned()) return;        if(onlyInPartition && (searchingPartition()== null || ! searchingPartition().ML_OBJS_IN_PART_CND.eval(bldg))) return;        if(mustBeNew && ! world.unvisitedBuildings.contains(bldg)) return;//        if(IN_TRAFFIC_C.eval(bldg)) return;        if(FULL_BUILDING_C.eval(bldg)) return;        if(!REACHABLE_C.eval(bldg)) return;        List vAgs = VISIBLE_C.and(POSITION_PRP.equal(bldg)).extract(world.platoonAgents);        if(Utils.getConditionCount(vAgs,AMBULANCE_TEAM_C)>0) return;//        if(vAgs.size() > 1) {//            if(vAgs.indexOf(self()) > 0 ) return;//        }        move(bldg);    }   protected void moveRandomBuilding(List bldgs,int search) throws ActionCommandException { // Impmements Traffic , Best For Near Bldgs.    if (bldgs.isEmpty())return;    List inTraff = IN_TRAFFIC_C.extract(bldgs);    List res = bldgs;    if(inTraff.size() < res.size())        res.removeAll(inTraff);    int indx = random.nextInt(res.size());    Building bldg= (Building) res.get(indx);    switch(search){        case SIMPLE_SEARCH :            m_lastSSBldg = bldg;            break;        case NEAR_FIRE_SEARCH:            m_lastNearFireBuilding = bldg;            break;    }    move(bldg);  }  public final Condition IN_TRAFFIC_C = new Condition () {    final Set trafficSet = world.inTraffic;    public boolean eval(Object obj){        return trafficSet.contains(obj);    }  };  public final Condition NOT_IN_TRAFFIC_C = IN_TRAFFIC_C.not();  protected void moveToBrokensFirst(List bldgs) throws ActionCommandException{    if (bldgs.isEmpty())return;    List broken = BROKEN_CND.extract(bldgs);    if (!broken.isEmpty()) {      move(broken);    }    move(bldgs);  }  private Building m_lastNearFireBuilding = null;  protected void moveNearFireBuildings(boolean onlyInPartition) throws ActionCommandException {    if(onlyInPartition && searchingPartition() == null) return;    if (world.burningBuildings.size() < MIN_BURNING_BLDGS_TO_START_SEARCH_AROUND_FIRE )return;    checkShouldContinueToBuildingAndMove(m_lastNearFireBuilding,onlyInPartition,true);     m_lastNearFireBuilding = null;//    List earlyFires = FIERYNESS_PRP.eq(1).extract(world.burningBuildings);    List fires ;    if(onlyInPartition)        fires = searchingPartition().ML_OBJS_IN_PART_CND.extract(world.burningBuildings);    else        fires =world.burningBuildings;    List posNearFires = getNearFireBuildings(fires,onlyInPartition);    posNearFires.removeAll(fullBuildings);    if (posNearFires.isEmpty())return;    moveFirstToNearsThenToFarers(posNearFires,NEAR_FIRE_SEARCH);  }  protected void moveAvailableBldgs(List bldgs) throws ActionCommandException {      Building bldg;      Route rt;      List res = new ArrayList();      for (Iterator it = bldgs.iterator(); it.hasNext(); ) {        bldg = (Building) it.next();        if (self().validRouteBldgs.contains(bldg)) {          res.add(bldg);          continue;        }      }      if (res.isEmpty())return;      moveRandomBuilding(res,AVAILABLE_SEARCH);  }  protected void checkStuck() throws ActionCommandException {    if (self().HasMovedInLastCycle() || submittedAction)return;    int st = time();    if(st <= TIME_STARTING_ACTION + MAX_WAITING_TO_ROAM )  return;    int[] ph;    int len;//    MotionlessObject mo = self().motionlessPosition();//    RealObject ro;    for (int i = st; i > st - MAX_WAITING_TO_ROAM; i--) {      ph = self().getPositionHistory(i);      len = ph.length;      if (len > 1)return;    }    System.out.println(self() + " Roaming Because Of CheckStuck In : "+ time());    roam();  }  protected List getRoadsNotInTrafficFromPrevRoute(){    List AvailableRoads = new ArrayList();    Path path = world.getCurrentPath();    if(path == null) return AvailableRoads;    Route traffRoute = getRouteCausedTrafficFromPrevRoute();    if(traffRoute != null){      AvailableRoads.addAll(path);      AvailableRoads.removeAll(traffRoute.getObjects());    }    return AvailableRoads;  }  protected Route getRouteCausedTrafficFromPrevRoute(){    if(! submittedMoveAct) return null;    Path path = world.getCurrentPath();    Route nextRt = prevRoute.trimStartTo(self().motionlessPosition());    if(path != null){        int fnIndx = nextRt.getIndexOf(path.getFirstNode()) , lnIndx = nextRt.getIndexOf(path.getLastNode());        if(fnIndx == -1){            nextRt = nextRt.trimEndTo(path.getLastNode());        }        else if(lnIndx == -1){            nextRt = nextRt.trimEndTo(path.getFirstNode());        }        else{            if (fnIndx>lnIndx) {              nextRt = nextRt.trimEndTo(path.getLastNode());            } else {              nextRt = nextRt.trimEndTo(path.getFirstNode());            }        }    }    if(MRL.MRLConstants.ROUTING_DEBUG_MODE)        System.out.println(self() + " , Traffic Route : " + nextRt + " In Time : " + time());    return nextRt;  }  // ---------------------------------------------------------------- OMID Aghazadeh    //Ashkan added    public static final int FIRE_SPEED = 10000;    public static final int MIN_EXPECTED_PASSED_LENGTH = 50000;    private void report() {            long s = System.currentTimeMillis();            messageManager.reportPosition(self());            if (self().buriedness() > 0) {                messageManager.reportVictim(self());            }            // === Reporting Fiery Buildings :            for (Iterator iterator = world.buildings.iterator();                 iterator.hasNext();) {                Building b = (Building) iterator.next();                if (b.time() == world.time() && /*b.report.getCount () == 0 &&*/ b.fieryness() > 0)                {                    if (b.fieryness() > 3)                        b.setFireStart(-2);                    if (b.getFireStart() == -2 && b.fieryness() <= 3)                    {                        b.setFireStart(time() - 1);                        messageManager.reportFire(b);                        b.report.update(world.time());                        //System.out.println("====================self = "+self().id+", time = "+time()+", Building : "+b.id+", fireStart = "+b.getFireStart()+"================");                        //System.out.flush();                    }                    else if (b.getFireStart() == -1 && b.fieryness() <= 3) {//                        //;//System.out.print(".....................................................");//                    ;//System.out.flush();                        Building building = (Building) b;                        if (lastPosition != null) {                            int lastdis = (int) (Util.distance(building, lastPosition) / (double) FIRE_SPEED);                            int nowdis = (int) (Util.distance(building,                                    self().motionlessPosition()) / FIRE_SPEED);                            if (lastdis < nowdis)                                lastdis = nowdis;                            int stTime = world.time() - (lastdis);                            int threshold = lastdis - nowdis;                            stTime--;                            if (stTime < 4) {                                stTime = 0;                            }                                building.setFireStart(stTime);                        } else {                            building.setFireStart(0);                        }                        messageManager.reportFire(b);                        b.report.update(world.time());                    }                }            }            // === Reporting Civilians            for (Iterator iterator = world.humanoids.iterator();                 iterator.hasNext();) {                Humanoid humanoid = (Humanoid) iterator.next();                if (humanoid.time() == world.time() && (humanoid.position                        () instanceof Building)){                    if( humanoid.needRescue() ){                        messageManager.reportVictim(humanoid);                        humanoid.report.update(world.time());                    }                    else if(humanoid.hp() <= 0 &&! humanoid.isReportedAsDead()){

⌨️ 快捷键说明

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