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

📄 policeforceagent.java

📁 2004年robotcup世界冠军源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Ending Move Reported Blockades : " + " In Time : " + time());        m_taskIsDone = true;        m_taskDone = TASK_MOVE_REPORTED_BLOCKADES;    case TASK_MOVE_NEAR_REFUGE_PATH:        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Starting Move Near Refuge Path : " + " In Time : " + time());        moveNearRefugePath();        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Ending Move Near Refuge Path : " + " In Time : " + time());//        break;        m_taskDone = TASK_MOVE_NEAR_REFUGE_PATH;        m_taskIsDone = true;    case TASK_MOVE_NEAR_FIRE_PATH:        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Starting Move Near Fire Path : " + " In Time : " + time());        moveNearFirePath();        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Ending Move Near Fire Path : " + " In Time : " + time());        m_taskDone =     TASK_MOVE_NEAR_FIRE_PATH;        m_taskIsDone = true;    case TASK_SEARCH_BLOCKADES://      if(!MRL.MRLConstants.IS_SIMPLE) choosePath();        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Starting SEARCH Blockades : " + " In Time : " + time());        searchBlockades();        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Ending SEARCH Blockades : " + " In Time : " + time());//      if (!changePartitionRequested && workingPartition() != null) requestChangingPartition();        m_taskDone = TASK_SEARCH_BLOCKADES;        m_taskIsDone = true;    case TASK_MOVE_NEAR_FIRE_BUILDINGS:        if  (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Starting MOVE Near Fire Bldgs : " + " In Time : " + time());        moveNearFireBuildings(true);        moveNearFireBuildings(false);        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Ending MOVE Near Fire Bldgs : " + " In Time : " + time());        m_taskDone =     TASK_MOVE_NEAR_FIRE_BUILDINGS;        m_taskIsDone = true;    case TASK_SEARCH_CIVILIANS:        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Starting SEARCH CIVILIANS : " + " In Time : " + time());        if(searchingPartition()  == null)            chooseTemporarySearchingPartition();        if(searchingPartition() != null)            searchCivilians(true);        else            searchCivilians(false);        if(searchingPartition() != null)            searchCivilians(true);        else            searchCivilians(false);        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Ending SEARCH CIVILIANS : " + " In Time : " + time());//      if (!partSearchAndClearedReported && workingPartition() != null) reportPartSearchedAndCleared();        m_taskDone =  TASK_SEARCH_CIVILIANS;        m_taskIsDone = true;    case TASK_CHECK_AND_REPORT_CIVS:        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Starting CHECK AND REPORT CIVS : " + " In Time : " + time());        checkAndReportCivilians();        if (MRL.MRLConstants.POLICE_TASK_DEBUG_DEEP_MODE)            System.out.println(self() + " , Ending CHECK AND REPORT CIVS : " + " In Time : " + time());        m_taskDone =   TASK_CHECK_AND_REPORT_CIVS;        m_taskIsDone = true;    default :       break;    }    //clearPathCompletely();     clearAnyRemainedBlockade();//    searchCiviliansInMap();//    if (!world.trafficICCPs.isEmpty()) roam(); // WHY?//    System.out.println("Police : " + self().id + " , DONE!");//    finished = true;//    restAtRefuge();    restAtRefuge();  }      private float MIN_PERCENT_OF_UNSEARCHED_BLDGS_TO_ASSIGN_TEMP_PART = 0.4f;      protected void chooseTemporarySearchingPartition(){          if(workingPartition() != null) return;          Partition part;          int unsearchedBldgs;          Building bldg;          List parts = new ArrayList();          for(Iterator it = world.partitioner.getPartitions().iterator();it.hasNext();){              part = (Partition) it.next();              unsearchedBldgs =0;              for(Iterator it2= world.unvisitedBuildings.iterator();it2.hasNext();){                  bldg = (Building) it2.next();                  if(part.ML_OBJS_IN_PART_CND.eval(bldg))                      unsearchedBldgs++;              }              if(unsearchedBldgs > MIN_PERCENT_OF_UNSEARCHED_BLDGS_TO_ASSIGN_TEMP_PART * part.getBuildings().size()){                  parts.add(part);              }          }          world.sortByID(parts);          List freePols = taskHandler().getWithoutTaskFreePolices();          world.sortByID(freePols);          int indx = freePols.indexOf(self());          if(indx == -1) return;          if(indx >= 2* parts.size())              return;          if(indx >= parts.size()){              indx -= parts.size() ;          }          part = world.partitioner.getPartition(indx);          if(part == null) return;          world.setSearchingPartition(part);      }  private final Comparator firePathComparator = new Comparator(){      Path path1,path2;      int path1Con , path2Con , path1Dist,path2Dist , path1Val , path2Val;      final int FIRE_BLDGS_THRESH = FIRE_BUILDINGS_THRESH_FOR_COMPARATOR;      public int compare(Object obj1,Object obj2){          path1 = (Path) obj1;          path2 = (Path) obj2;          path1Con = path1.getValForFieryComparator();//          path1Dist = self().distance(path1.position());          path2Con = path2.getValForFieryComparator();//          path2Dist = self().distance(path2.position());          path1Val = path1Con  /*- path1Dist / 10000*/ ;          path2Val = path2Con  /* - path2Dist / 10000 */;          if(path1 == world.getPrevPath())            path1Val -= FIRE_BLDGS_THRESH;          else if(path2 == world.getPrevPath())            path2Val -= FIRE_BLDGS_THRESH;          return path1Val - path2Val;      }  };  protected void moveNearFirePath() throws ActionCommandException {    List res = new ArrayList();    Building bldg;    Path path;    for (Iterator it = world.burningBuildings.iterator(); it.hasNext(); ) {      bldg = (Building) it.next();      if (isBuildingsPathOpen(bldg))continue;      path = world.getContainingPath(bldg);      if (path == null)continue;      if (workingPartition() != null) {        if (workingPartition().ML_OBJS_IN_PART_CND.eval(path)) {          res.add(path);        }      } else {        res.add(path);      }    }      if(res.isEmpty()) return;      Collections.sort(res,firePathComparator);      path =  (Path) res.get(0);      world.setPrevPath(path);      Route rt = getClearingRoute(path);      if(res.size() > 1){          Path nPath = (Path) res.get(1);          rt = checkNextPathAndGetCompleteRoute(rt,nPath);      }      move(rt);  }    public Route checkNextPathAndGetCompleteRoute(Route rt , Path nextPath){        Route res=rt;        if(! (res.end instanceof Node)) return res;        Node node = (Node) res.end;        if (node.getConnectedRoads().size() > 1) {          if (nextPath != null) {            res = getRouteToNextPath(rt, nextPath);            Node end = (Node) res.end;            if (nextPath.getEdges().contains(end)) {              Route te = nextPath.goToEndFromStart((Node) res.end);              res = te.merge(res);              if (MRL.MRLConstants.ROUTING_DEBUG_MODE) System.out.println(self() +                  " Could Find A Route Connecting Two Targets");            }          } else if (MRL.MRLConstants.ROUTING_DEBUG_MODE) System.out.println(              self() + " Null Next Path");          res.validateAndSubmit();        }        return res;    }    public final Collection openPathBuildings = self().openPathBuildings;    public boolean isBuildingsPathOpen(Building bldg){        if(openPathBuildings.contains(bldg))            return true;        Path path = world.getContainingPath(bldg);        if(path == null) {            Node entr = (Node)bldg.entrance();            for(Iterator it = entr.getConnectedPaths().iterator();it.hasNext();){                path = (Path) it.next();                if(path.checkPathIsOpen()){                    openPathBuildings.addAll(path.getConnectedBuildings());                }            }        }        else        {            if(path.checkPathIsOpen()){                openPathBuildings.addAll(path.getConnectedBuildings());            }        }        return openPathBuildings.contains(bldg);    }  private Refuge m_lastRefugeTarget = null;  protected void moveNearRefugePath() throws ActionCommandException {    Refuge ref;    if (m_lastRefugeTarget != null) {        checkBuildingsPathIsClearedOrMove(m_lastRefugeTarget,true);        m_lastRefugeTarget=null;    }    for (Iterator it = world.refuges.iterator(); it.hasNext(); ) {        ref = (Refuge) it.next();        m_lastRefugeTarget = ref;        checkBuildingsPathIsClearedOrMove(ref,true);    }      m_lastRefugeTarget = null;  }  protected void checkBuildingsPathIsClearedOrMove(Building bldg, boolean goToTraffic) throws ActionCommandException{      if(isBuildingsPathOpen(bldg)) return;      if(workingPartition() != null && ! workingPartition().ML_OBJS_IN_PART_CND.eval(bldg)) return;      Path path = world.getContainingPath(bldg);      if(path == null) return;      checkPathIsClearedOrMove(path,goToTraffic);  }  protected void checkPathIsClearedOrMove(Path path , boolean goToTraffic) throws ActionCommandException{      if(workingPartition() != null && ! workingPartition().ML_OBJS_IN_PART_CND.eval(path)) return;      if(!goToTraffic){        if(IN_TRAFFIC_C.eval(path))            return;      }      if(path.checkPathIsOpen())        return;      Route rt = getClearingRoute(path);      move(rt);  }  protected void continuePrevRouteIfValid() {    if (workingPartition() == null)return;    if (prevRoute == null || ! submittedMoveAct)return;    if (time() <= 5)return;    if (self().motionlessPosition() instanceof Building)return;    MotionlessObject pos = self().motionlessPosition();    if (prevRoute.end == pos)return;    if (pos instanceof Road && NOT_PASSABLE_C.eval(pos))return;    if (!prevRoute.isContaining(pos))return;    Route rt = prevRoute.Clone().trimStartTo(pos);    MotionlessObject mo;    for (Route rt2 = rt; rt2 != null; rt2 = rt2.previous()) {      mo = rt.end;      if (world.isInTraffic(mo))return;    }    if (rt.validate()) {      if (MRL.MRLConstants.ROUTING_DEBUG_MODE) System.out.println(self() +          " Continuing To : " + rt.end);      decidedRoute = rt;    } else if (MRL.MRLConstants.ROUTING_DEBUG_MODE) System.out.println(self() +        " Invalid Route Made From PrevRoute");  }  protected void clearAnyRemainedBlockade() throws ActionCommandException {    //Should Complete This    Collection shouldcheck = SHOULD_CHECK_PATH_CND.extract(world.paths);    if(shouldcheck.isEmpty()){        clearPathCompletely();        Collection col = CLEARABLE_C.extract(world.roads);        if (col.isEmpty())return;        move(col);    }    Path path = (Path)distancePrp.min(shouldcheck);    Route rt = getClearingRoute(path);    move(rt);  }  protected void hearTell(RealObject sender, String msg) {  }  private void choosePath() throws ActionCommandException {    if (workingPartition() != null) {      //    boolean debug = (workingPartition().getID() == 6);      MotionlessObject pos = self().motionlessPosition();      Path path;      Collection roadsToCheck;      do {//        Path path2;//        path2 = chooseMaxValPath();          path = getNextMaxValPath(world.pathsIP,null);//        if(! path2.shouldCheck()) throw new Error ("Should'nt Be Checked");//        if(path2 != path) throw new Error (self() + " Path 1 : "+ path.getValue() + " Path 2 : " + path2.getValue());        if (path == null) {          return;        }        roadsToCheck = SHOULD_CHECK_ROAD_CND.extract(path);        if (roadsToCheck.isEmpty()) {//          throw new Error("Path Shouldnt Be Checked");            return;        }        Route res = null;          world.setPrevPath(path);          res = getClearingRoute(path);          Path nextPath = getNextMaxValPath(world.pathsIP,path);          if (nextPath != null && nextPath != path) {             res = checkNextPathAndGetCompleteRoute(res,nextPath);          }        move(res);      } while (path != null);      if (MRL.MRLConstants.PARTITION_DEBUG_MODE)        System.out.println("PF : " + self().id + " No More Path !");    }    if (MRL.MRLConstants.PARTITION_DEBUG_MODE) {      System.out.println(self() + " Has No Working Partition In Time : " + time());    }  }//  protected Path getPath(int indx) { // Should Implement Traffic Here .//    List paths = world.sortedBlockedPathsIP;//    if (indx >= paths.size())return null;//    Path path = null;//    int tIndx = indx;//    int cnt = 0;//    do {//      if (cnt >= paths.size()) {//        if (indx == 0 && !paths.isEmpty())return (Path) paths.get(0);//        return null;//      }//      path = (Path) paths.get(cnt);//      if (path.checkPathIsOpen()) {//        paths.remove(path);//        continue;//      }//      if (world.isInTraffic(path)) {//        tIndx++;//      }//      cnt++;//    } while (cnt <= tIndx);//    return path;//  }  protected Path getNextMaxValPath(Collection inp , Path path){    Path tp,res=null;    float pathVal , max = path == null ? Integer.MAX_VALUE : path.getValue() , best = -Integer.MAX_VALUE;    for(Iterator it = inp.iterator();it.hasNext();){      tp = (Path) it.next();      if(!tp.shouldCheck()) continue;      if(IN_TRAFFIC_C.eval(tp)) continue;      pathVal = tp.getValue();      if(tp == world.getPrevPath())        pathVal += PREV_PATH_VALUE_THRESH;      if(pathVal <= max && tp != path && pathVal > best){        res = tp;        best = pathVal;      }    }    if(res == path) res = null;    return res;  }  protected Path getPath(Collection inp , int indx){    if(indx >= inp.size()) return null;    Path path = null;//    if(indx == 0 ) return maxVal;

⌨️ 快捷键说明

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