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

📄 policeforceagent.java

📁 2004年robotcup世界冠军源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    for (int i = 0; i < indx + 1; i++) {      path = getNextMaxValPath(inp,path);    }    return path;  }  protected void checkAgentIsInPartition() throws ActionCommandException {    if (workingPartition() != null &&        !workingPartition().IsContaining(self().motionlessPosition())) {      move(workingPartition().getRoads());    }  }  protected Route makeRouteBigger(Route route) { // Last Route In route Should Be A Path's Edge // ,Router.CostFunction cf    if (route.getLength() > 350000)return route;    Node end = (Node) route.end;    Road lastRoad = (Road) route.previous().end;    Path lastPath = world.getContainingPath(lastRoad);    Node fn = lastPath.getFirstNode(), ln = lastPath.getLastNode();    if (end != fn && end != ln)throw new Error("Invalid Usage");    Collection ns;    if (end == fn) {      ns = lastPath.getPathToHead();    } else {      ns = lastPath.getPathToTail();    }    ns.remove(lastPath);    if (workingPartition() != null) {      ns = workingPartition().ML_OBJS_IN_PART_CND.extract(ns);    }    Path path;    Route tr, res = route;    for (Iterator it = ns.iterator(); it.hasNext(); ) {      path = (Path) it.next();      if (!path.shouldCheck() || res.isContaining(path.getFirstRoad()))continue;      if(path.isOneWayPath()){          if(end == path.getFirstNodeForOneWayPaths()){            tr = path.goToEndFromStart(end);          }          else continue;      }      else{          tr = path.goToEndFromStart(end);      }//      System.out.println(self() + " Complete Route To End : "+ tr + "\nRes : " + res);      res = tr.merge(res);      break;    }    res.validateAndSubmit();    return res;  }  protected Route getExploringRoute(Path path){    Route res,toPathRT;    MotionlessObject pos = self().motionlessPosition();    if(pos instanceof Building)        pos = ((Building)pos).entrance();    if(path.IsContaining(self().motionlessPosition()))        return getNeedCheckVisitingRoute(pos, path);    if(path.isOneWayPath()){        toPathRT = getRouteFromCurrentPos(path.getFirstNodeForOneWayPaths(),POLICE_EXPLORING_COST_FUNCTION);    }    else{        toPathRT = getRouteFromCurrentPos(path.getEdges(),POLICE_EXPLORING_COST_FUNCTION);    }    Node st = (Node)toPathRT.end;    Route tr = path.goToEndFromStart(st);    res = tr.merge(toPathRT);    return res;  }  protected Route getRouteToNextPath(Route rt, Path nextPath) {    if (!nextPath.shouldCheck())throw new Error("Path Shouldn't Be Checked");    if (rt.getLength() > 300000)return rt;    MotionlessObject end = rt.end;    Route rtT = Router.get(end, nextPath.getEdges(),                           getCFNotIncludingCol(MOVING_COST_FUNCTION,                                                rt.getObjects())); // getNIPCCF(rt.getObjects())    Route res = rt;//    if (rtT.cost < (float)Integer.MAX_VALUE * Integer.MAX_VALUE) {      res = rtT.merge(rt);      res.validateAndSubmit();//    }    return res;  }  private void requestChangingPartition() {    if (workingPartition() == null)return;    messageManager.reportRequestPartitionChanging();  }  private void reportPartSearchedAndCleared() {    if (workingPartition() == null)return;    messageManager.reportPartitionFinished();  }  public Router.CostFunction getNIPCCF(Collection col) {    return getCFNotIncludingCol(HumanoidAgent.CLEARING_COST_FUNCTION, col);  }//    int prevBlock = -1;//    Road prevRoad = null;    protected void reportClearedRoads(){        Road road;        if(self().motionlessPosition() instanceof Road){            road = (Road) self().motionlessPosition();//            if(road == prevRoad)//                System.out.println(self() + " Road : " + road + " prevBlock : " + prevBlock + " CurrBlock : " + road.block() + " RC : " + road.repairCost());//            else//                prevRoad = road;//            prevBlock = road.block();            if(NOT_PASSABLE_C.eval(road)){                messageManager.reportClear(road);                road.reportClear.update(world.time());            }        }//        else prevRoad = null;//        Path path;        for(Iterator it = roadsCleared.iterator();it.hasNext();){            road = (Road) it.next();//            path = world.getContainingPath(road);            if(!road.isReportedAsClear()){                road.reportClear.update(world.time());                messageManager.reportClear(road);                it.remove();            }            else             it.remove();        }    }    protected boolean m_shouldSearchBlocks = true;    protected boolean shouldSearchBlocks(){//        if(!m_shouldSearchBlocks) return false;        if(workingPartition() != null){            int totalSize = world.pathsIP.size();            int shouldCheck = (int) (PERCENT_OF_PATHS_CLEARED_TO_STOP_EXPLORING_FOR_PARTITIONED * totalSize);            int uncleared = Utils.getConditionCount(world.pathsIP,SHOULD_CHECK_PATH_CND);            int cleared = totalSize - uncleared;            int remaining = shouldCheck - cleared;            return remaining <= 0;        }        else {            int totalSize = world.paths.size();            int shouldCheck = (int) (PERCENT_OF_PATHS_CLEARED_TO_STOP_EXPLORING_FOR_FREE * totalSize);            int uncleared = Utils.getConditionCount(world.paths,SHOULD_CHECK_PATH_CND);            int cleared = totalSize - uncleared;            int remaining = shouldCheck - cleared;            return remaining <= 0;        }    }    private int m_taskDone = -1;    private boolean m_taskIsDone = false;    protected boolean isCurrentTaskDone(){//        return m_taskIsDone;        boolean res =false;//        if(m_taskDone >= self().task() && time() >= TASK_ASSIGN_START_TIME && time() > self().taskStartTime())//            res = true;//        else{            int task = self().task();            res = isTaskDone(task);//        }        return res;    }    private boolean isTaskDone(int task){        boolean res = false;        switch(task){        case TASK_MOVE_REPORTED_BLOCKADES : {           Collection tot , rem ;           int mustClear,total;           int remBur = 0;           if(workingPartition() != null){               rem = self().reportedBlockadesIP;               tot = self().totalReportedPathsIP;               total = tot.size();               mustClear = (int) (PERCENT_OF_REPORTED_BLOCKADES_TO_CLEAR_BEFORE_CHANGE_TASK_FOR_PARTITIONED * total);               Humanoid hum ;               for(Iterator it = world.platoonAgents.iterator();it.hasNext();){                   hum = (Humanoid) it.next();                   if(hum.buriedness() == 0) continue;                   if(hum.position() == null || hum.position() instanceof AmbulanceTeam) continue;                   if(workingPartition().ML_OBJS_IN_PART_CND.eval(hum.motionlessPosition()))                       remBur ++;               }           }           else{               rem = self().reportedBlockades;               tot = self().totalReportedPaths;               total = tot.size();               mustClear = (int) (PERCENT_OF_REPORTED_BLOCKADES_TO_CLEAR_BEFORE_CHANGE_TASK_FOR_FREE * total);               remBur = Utils.getConditionCount(world.platoonAgents,BURIED_C);           }           int cleared = total - rem.size();           int remaining = mustClear - cleared + remBur;           if(remaining <= 0 ){//                    System.out.println(self() + " MoveReportedBlockade Task Is Determined Done In : " + time());               res = true;           }           else{//                    System.out.println(self() + " Total Reported Paths : " + total + " , Remaining : " + remaining);               res = false;           }           break;       }            case TASK_MOVE_NEAR_REFUGE_PATH:{                List polsAssigned = taskHandler().getFreePolicesInTask(TASK_MOVE_NEAR_REFUGE_PATH);                if(!polsAssigned.contains(self()) && !polsAssigned.isEmpty()){                     res = true;                }                else{                    Collection refs;                    if(workingPartition() != null){                        refs = workingPartition().ML_OBJS_IN_PART_CND.extract(world.refuges);                    }                    else{                        refs = world.refuges;                    }                    int refSize = refs.size();                    int cleared = getTotalBuildingsWithClearedPathCount(refs);                    if(cleared == refSize)                        res = true;                    else                        res = false;                }                break;            }            case TASK_MOVE_NEAR_FIRE_PATH:{                Collection bldgs;                int bldgSize , shouldSearch;                if(workingPartition() != null){                    bldgs = workingPartition().ML_OBJS_IN_PART_CND.extract(world.burningBuildings);                    bldgSize = bldgs.size();                    shouldSearch = (int)(PERCENT_OF_NEAR_FIRE_PATHS_CLEARED_TO_STOP_TASK_FOR_PARTITIONED * bldgSize);                }                else{                    bldgs = world.burningBuildings;                    bldgSize = bldgs.size();                    shouldSearch = (int)(PERCENT_OF_NEAR_FIRE_PATHS_CLEARED_TO_STOP_TASK_FOR_FREE * bldgSize);                }                int cleared = getTotalBuildingsWithClearedPathCount(bldgs);                if(cleared >= shouldSearch && time() > MIN_TIME_TO_CONSIDER_MOVE_NEAR_FIRE_PATHS_DONE)                    res = true;                else                    res = false;                break;            }            case TASK_SEARCH_BLOCKADES :{                res = shouldSearchBlocks();                break;            }            case TASK_SEARCH_CIVILIANS :{                if(world.unvisitedBuildings.isEmpty()) res = true;                else{                    Collection toSearch , total;                    int tot,shouldSearch;                    if(searchingPartition() != null){                        toSearch = searchingPartition().ML_OBJS_IN_PART_CND.extract(world.unvisitedBuildings);                        total = searchingPartition().getBuildings();                        tot = total.size();                        shouldSearch = (int)(PERCENT_OF_BUILDINGS_TO_SEARCH_BEFORE_CHANGE_TASK_FOR_PARTITIONED * tot);                    }                    else{                        toSearch = world.unvisitedBuildings;                        total = world.buildings;                        tot = total.size();                        shouldSearch = (int)(PERCENT_OF_BUILDINGS_TO_SEARCH_BEFORE_CHANGE_TASK_FOR_FREE * tot);                    }                    int rem = toSearch.size();                    int doneSearch = tot - rem;                    if(doneSearch < shouldSearch)                        res = false;                    else                        res = true;                }             break;            }            case TASK_MOVE_NEAR_FIRE_BUILDINGS :{                List fires;                int maxRem;                if(searchingPartition()!= null){                    fires = searchingPartition().ML_OBJS_IN_PART_CND.extract(world.burningBuildings);                    maxRem = MAX_REMAINING_NEAR_FIRE_BUILDINGS_TO_SEARCH_BEFORE_CHANGE_TASK_FOR_PARTITIONED;                }                else{                    fires =world.burningBuildings;                    maxRem = MAX_REMAINING_NEAR_FIRE_BUILDINGS_TO_SEARCH_BEFORE_CHANGE_TASK_FOR_FREE;                }                int rem = getNearFireBuildingsCount(fires);                if(self().taskHandler.myCurrentTask() > TASK_MOVE_NEAR_FIRE_BUILDINGS)                    maxRem += REMAINING_NEAR_FIRE_BUILDINGS_TOLERANCE;                res= rem <= maxRem;                break;            }        }        return res;    }    protected void moveBuriedAgentPath() throws ActionCommandException{        if(Utils.getConditionCount(world.platoonAgents,BURIED_C) == 0) return;        List buriedAgents = BURIED_C.extract(world.platoonAgents);        List buriedAgentsPos = POSITION_PRP.collect(buriedAgents);        List paths = new ArrayList();        MotionlessObject mo;        Path path;        for(Iterator it = buriedAgentsPos.iterator();it.hasNext();){            mo = (MotionlessObject) it.next();            path = world.getContainingPath(mo);            if(path == null) continue;            if(path.checkPathIsOpen()) continue;            paths.add(path);        }        if(paths.isEmpty()) return;        world.sortByID(paths);        Route res;        if(workingPartition() != null){            List pathsIP = workingPartition().ML_OBJS_IN_PART_CND.extract(paths);            if(pathsIP.isEmpty()) return;            path = (Path)pathsIP.get(0);            if(path == null) return;            res = getClearingRoute(path);        }        else{            List freePols = taskHandler().getWithoutTaskFreePolices();            world.sortByID(freePols);            path = choosePathToClear(paths,freePols);            if(path == null) return;            res = getClearingRoute(path);            }        if(res != null)            move(res);    }    private Path choosePathToClear(List paths,List agents){        int indx = 0;        int agIndx = agents.indexOf(self());        if(agIndx  == -1)        {            return null;//            throw new Error("AHAIN!");        }        int size = paths.size();        if(agIndx >= size){            if(agIndx >= size * 2)                return null;            else//                indx = agIndx - size;                indx = 2*size - agIndx-1;        }        else{            indx = agIndx;        }        return (Path) paths.get(indx);    }    public int getTotalBuildingsWithClearedPathCount(Collection bldgs){        Building bldg;        int res =0;        for(Iterator it = bldgs.iterator();it.hasNext();){            bldg = (Building) it.next();            if(isBuildingsPathOpen(bldg))                res++;        }        return res;    }  // ---------------------------------------------------------------- OMID}

⌨️ 快捷键说明

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