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

📄 disasterspace.java

📁 2004年robotcup世界冠军源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
// Copyright (C) 2002 Takeshi Morimoto <morimoto@takopen.cs.uec.ac.jp>// All rights reserved.// Edited By Omid Aghazadehpackage yab.agent;import java.util.*;import yab.agent.object.*;import yab.io.*;import MRL.Utilities.Partitioning.*;import MRL.MRLConstants;import MRL.Ambulance.EAmbulanceCenter;import MRL.Ambulance.EAmbulanceTeam;import MRL.FireBrigade.FireBrigadeConstantsConditions;import MRL.FireBrigade.EFireStation;import MRL.FireBrigade.EFireBrigade;import MRL.Utilities.*;import MRL.Police.*;public class DisasterSpace implements MRL.Utilities.ConstantConditions, ProtocolConstants {  private final HashMap m_idObjMap = new HashMap();  public final RealObject self;  public Partitioner partitioner;  public final List roads = new ArrayList();  public final List nodes = new ArrayList();  public final List buildings = new ArrayList();  public final List refuges = new ArrayList();  public final List humanoids = new ArrayList();  public final List civilians = new ArrayList();  public final List ambulanceTeams = new ArrayList();  public final List fireBrigades = new ArrayList();  public final List policeForces = new ArrayList();  public final List updatedmovingobjects = new ArrayList(); // Updated Info For Agents This Agent's Seeing In Current Cycle Inlcuding Position , ...  public static Node Center = null;  public final boolean IsUsingPartitioning;  public boolean shouldUpdateAlphas = MRL.MRLConstants.POLICE_LEARN_MODE;//  public final ArrayList <Building> emptyBuildings = new ArrayList<Building>();  public final ArrayList ambulanceCenters = new ArrayList ();  public final ArrayList fireStations = new ArrayList ();  public final ArrayList policeOffices = new ArrayList ();//  public static boolean firsttest = true;//  public static int countertest = 0;//  public final Map lockedBBAgents = new HashMap(); // Locked By Blockade Agents  // These Are Added In Order To Enhance Path's Value Computation  public final ArrayList buriedAgents = new ArrayList();  public final List agents = new ArrayList();  public final List platoonAgents = new ArrayList();  public final List burningBuildings = new ArrayList();  public final List pathsIP = new ArrayList();  public final Map m_HearedCivPossPosMap = new HashMap();//  public final List possCivsIP = new ArrayList();  public final Map m_lockedCivPos_Map = new HashMap();  public final ArrayList motionlessObjects = new ArrayList();  public final Set unvisitedBuildings = new HashSet();  public final float[] ai;  private final Collection objToPartition = new HashSet();  public static final int MAX_FIRE_REPORT_IC = 3;  public Map civCheckTime = new HashMap();//saeed 85-2-3  public final BlockData blockData;  public final HearData hearData = new HearData(this);  public final AccessibleData accessibleData ;//  public final Collection travAndNotUpdatedRoads = new HashSet();  // ---- End Of These Are Added ...  // Omid AG  //note! It's different from bloacked agent( blocked agents can move themself)  // Omid AG  public final Map m_fireSet = new HashMap();  public final Map m_reportedFireSet = new HashMap();  // ---- Traffic  public final List visibleHumanoids = new ArrayList();  public final Map trafficICCPs = new HashMap();  // ---- Traffic  private final int selfId;  public DisasterSpace(int selfId, ObjectElement[] objs) {    this.selfId = selfId;    update(objs, Constants.TIME_INITIALIZING_AGENT);    self = get(selfId);    if (self instanceof PoliceForce || self instanceof PoliceOffice) {      IsUsingPartitioning = true;      ai = new float[Path.valCount];      if (MRL.MRLConstants.POLICE_LEARN_MODE)        Path.setAlphasFromFile(ai);      else {        Path.setAlphas(ai);//      Path.setAlphas1(ai);      }    } else {      IsUsingPartitioning = false;      ai = null;    }    createPath();    sortByID(paths);    sortByID(motionlessObjects);    objToPartition.addAll(motionlessObjects);    objToPartition.addAll(paths);      if(MRL.MRLConstants.PARTITION_DEBUG_MODE) System.out.println(self + " , MOS : " + motionlessObjects.size()+ " , PATHS : " +  paths.size());    if (self instanceof FireBrigade || self instanceof FireStation ||        self instanceof PoliceForce || self instanceof PoliceOffice)      PartitioningInit();    objToPartition.clear();    unvisitedBuildings.addAll(SPECIAL_BUILDING_C.not().extract(buildings));    computePrimitiveCalcs();    if(self instanceof EPoliceForce)        blockData = ((EPoliceForce)self).blockData;    else if(self instanceof PoliceOffice)        blockData = ((EPoliceOffice)self).blockData;    else blockData = null;    if(self instanceof MovingObject){        accessibleData = new AccessibleData(this);    }      else accessibleData = null;  }  private int m_time;  public int time() {    return m_time;  }  public void add(RealObject obj) {    m_idObjMap.put(new Integer(obj.id), obj);      if (obj instanceof MotionlessObject)        {            motionlessObjects.add (obj);            if (obj instanceof AmbulanceCenter)                ambulanceCenters.add (obj);            else if (obj instanceof FireStation)                fireStations.add (obj);            else if (obj instanceof PoliceOffice)                policeOffices.add (obj);            if (obj instanceof Road)                roads.add (obj);            else if (obj instanceof Node)                nodes.add (obj);            else if (obj instanceof Building)            {                buildings.add (obj);                if (obj instanceof Refuge) refuges.add (obj);            }        }      else if (obj instanceof Humanoid) {      humanoids.add(obj);      if (obj instanceof Civilian) civilians.add(obj);      else if (obj instanceof AmbulanceTeam) ambulanceTeams.add(obj);      else if (obj instanceof FireBrigade) fireBrigades.add(obj);      else if (obj instanceof PoliceForce) policeForces.add(obj);    }  }  public RealObject get(int id) {    return (RealObject) m_idObjMap.get(new Integer(id));  }  public static final int HUMANOID_SENSE_NEAR_DISTANCE = 10000;  public final List updatedBuildings = new ArrayList();  public final List updatedRoads = new ArrayList();  public final List entranceSet = new ArrayList();  public void update(ObjectElement[] objs, int time) {    m_time = time;    updatedmovingobjects.clear();    updatedBuildings.clear();    updatedRoads.clear();    for (int i = 0; i < objs.length; i++) {      RCRObject obj = get(objs[i].id);      if (obj == null) {        if(objs[i].id == selfId){            int type =objs[i].type;            if( type == ProtocolConstants.TYPE_POLICE_FORCE)                obj = new EPoliceForce(selfId,this);            else if( type == ProtocolConstants.TYPE_POLICE_OFFICE)                obj = new EPoliceOffice(selfId,this);            else if(type == ProtocolConstants.TYPE_AMBULANCE_CENTER)                obj = new EAmbulanceCenter(selfId,this);            else if(type == ProtocolConstants.TYPE_AMBULANCE_TEAM)                obj = new EAmbulanceTeam(selfId,this);            else if(type == ProtocolConstants.TYPE_FIRE_BRIGADE)                obj = new EFireBrigade(selfId,this);            else if(type == ProtocolConstants.TYPE_FIRE_STATION)                obj = new EFireStation(selfId,this);            else                obj = RCRObject.produce(objs[i].type, objs[i].id, this);        }          else            obj = RCRObject.produce(objs[i].type, objs[i].id, this);        if (obj instanceof RealObject) {          add((RealObject) obj);        }      }      obj.setTime(time);      boolean bFound = false;      if(obj instanceof Civilian){          if(((Civilian)obj).position() == null)            bFound = true;      }      obj.setProperty(time, objs[i].properties);      //--------------------Added by Ashkan      if (obj instanceof Humanoid)      {          Humanoid human = (Humanoid)obj;          int damageAverage;          if (human.lastHp() == 10000)            damageAverage = human.damage() ;          else            damageAverage = (human.damage() + human.lastDamage()) / 2;          int expectedHp = human.lastHp() - ((time() -  human.lastUpdateTime()) * damageAverage);          human.setLastDamage(human.damage());          human.setLastUpdateTime(time());          //if (expectedHp>0)          {          if (expectedHp > human.hp() - 500 && expectedHp <= human.hp() + 500)          {                obj.setProperty(time(), PROPERTY_HP, new int[]{expectedHp});                human.setLastHp(expectedHp);          }          else          {                obj.setProperty(time, PROPERTY_HP, new int[]{human.hp() - 500});                human.setLastHp(human.hp());          }          }         // else           //               human.setLastHp(human.hp());          if (human.hp()<0)          {              obj.setProperty(time, PROPERTY_HP, new int[]{0});              human.setLastHp(human.hp());          }      }      //--------------------Added by Ashkan      if(bFound){          Civilian civ = (Civilian) obj;         // System.out.println(self + " Sensed Civ : " + civ + " MP : " + civ.motionlessPosition() + " Burriedness: " + civ.buriedness() + " Time : " + time);          if(civ.motionlessPosition() instanceof Building && civ.buriedness() > 0){ //  && Utils.getConditionCount(ambulanceTeams,POSITION_PRP.eq(civ.motionlessPosition())) ==0              MotionlessObject mo = civ.motionlessPosition();              Building bldg = civ.guessedPosition();            //  System.out.println(self + " , Found Civilian : " + civ + " CivPos : " + mo +( bldg == null ? " NOT Guessed "  : " , GuessedPos : " + bldg) + " In Time : " + time + " Search Start Time : " + civ.getSearchStartTime() + " Time : " + time);          }      }      if (obj instanceof MovingObject)        if (obj != self) {          updatedmovingobjects.add(obj);          if (obj instanceof Civilian) {            if (m_HearedCivPossPosMap.containsKey(obj)) m_HearedCivPossPosMap.                remove(obj);          } else { // obj instanceof Platoon         ////////////////////////          }        } else // Obj = Self          if(time > 2) ((MovingObject) obj).updatePositionHistory();      // -----------------      if (obj instanceof Building) {        updatedBuildings.add(obj);        Building bldg = (Building) obj;//        if (!entranceSet.contains(((Building) obj).entrance())) {//          entranceSet.add(((Building) obj).entrance());//        }        if (bldg.isBurning()) {          if (m_fireSet.containsKey((Building) obj)) {            // =====================================          } else {            int t = m_time - Util.distance(self.motionlessPosition(),                                           (MotionlessObject) obj) /                    MRL.Utilities.SimulatorsConstants.VISIBLE_DISTANCE;            m_fireSet.put(obj, new Integer(t));          }        } else {          if (bldg.isPutOut() ||              bldg.isBurned()) {            m_fireSet.remove(obj);          }          if(bldg.isBurned()) unvisitedBuildings.remove(obj);        }      }        else if(obj instanceof Road)            updatedRoads.add((Road)obj);      // -----------------    }    updateValsAndCols();  }  private Condition hearedCivPossiblePosInPart_CND = new Condition() {    public boolean eval(Object obj) {      if (!m_HearedCivPossPosMap.containsKey(obj))return false;      else {        return workingPartition.IsContaining((Partitionable) m_HearedCivPossPosMap.                                         get(obj));      }    }  };  private boolean pathsSet = false;  public final Collection needRescueCivs = new HashSet();  public final Collection needLoadCivs = new HashSet();  private Path prevPath = null;  private void updateValsAndCols() {    switch (m_time) {    case 3:      agents.addAll(CENTER_C.extract(buildings));      platoonAgents.addAll(policeForces);      platoonAgents.addAll(fireBrigades);      platoonAgents.addAll(ambulanceTeams);      agents.addAll(platoonAgents);      doSortings();      break;    }    needRescueCivs.clear();    needRescueCivs.addAll(NEED_RESCUE_C.extract(civilians));    needRescueCivs.removeAll(lostCivs);    needLoadCivs.clear();    needLoadCivs.addAll(NEED_LOAD_C.extract(civilians));    needLoadCivs.removeAll(lostCivs);    correctNeedCheck(needRescueCivs);    correctNeedCheck(needLoadCivs);

⌨️ 快捷键说明

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