📄 firebrigadeagent.java~
字号:
// Copyright (C) 2002 Takeshi Morimoto <morimoto@takopen.cs.uec.ac.jp>// All rights reserved.package sample;import java.net.*;import java.util.*;import yab.agent.*;import yab.agent.object.*;public class FireBrigadeAgent extends AbstractFireBrigadeAgent { public FireBrigadeAgent(InetAddress address, int port) { super(address, port); } protected static final Property FIERYNESS_PRP = Property.get("Building", "fieryness"), BURNING_TIME_PRP = Property.get("Building", "burningTime"), ENTRANCE_PRP = Property.get("Building", "entrance"); protected static final int BURNING_TIME_OF_AN_EARLY_FIRE = 3; protected static final Condition IS_BURNING_CND = FIERYNESS_PRP.gte(1).and(FIERYNESS_PRP.lte(3)), IS_EARLY_CND = BURNING_TIME_PRP.lte(BURNING_TIME_OF_AN_EARLY_FIRE); protected final Condition isNearCnd = distancePrp.lte(EXTINGUISHABLE_DISTANCE); protected void act() throws ActionCommandException //动作执行函数(最主要的函数) { reportBlockade(); //moveToRefugeIfDamagedOrTankIsEmpty(); //1 添加一个是否需要加水的策略 //extinguishNearIgnitions(); //2 添加一个对建筑物属性判断的策略 Collection fires = IS_BURNING_CND.extract(world.buildings); Collection earlyFires = IS_EARLY_CND.extract(fires); extinguishOrMove(earlyFires); extinguishOrMove(fires); moveToRefuges(); } //*************************************************************************//1 private void moveToRefugeIfDamagedOrTankIsEmpty() throws ActionCommandException { if(!isThereRefuge) //判断是否有避难所 return; if ((self().damage() > 0 && self().hp() < 5000) || self().waterQuantity() == 0) //判断水的条件等 { if(self().motionlessPosition() instanceof Refuge) rest(); else move(world.refuges); } } //*************************************************************************// //*************************************************************************//2 private void extinguishNearIgnitions() throws ActionCommandException { ArrayList igns = new ArrayList(); for(int i=0;i<world.buildings.size();++i) { Building b = (Building)world.buildings.get(i); if(b.fieryness() != FIERYNESS_BURNT_OUT && b.temprature() == IGNITION_DEGREE) //根据房屋的属性判断救火策略 { igns.add(b); } } if(igns.size() == 0) return; extinguish(igns); } //*************************************************************************// protected void reportBlockade() { MotionlessObject pos = self().motionlessPosition(); if (pos instanceof Road && ((Road) pos).passableLines() == 0) tell("clear " + pos.id); } protected void extinguishOrMove(Collection fires) throws ActionCommandException { extinguishNearFire(fires); moveToEntrances(fires); } protected void extinguishNearFire(Collection fires)throws ActionCommandException { if (tankFillingState && (self().waterQuantity() <= 3000)) return; if (!tankFillingState) { Collection nearFires = isNearCnd.extract(fires); if (!nearFires.isEmpty()) extinguish((Building) BURNING_TIME_PRP.min(nearFires)); } if (tankFillingState) { if(self().motionlessPosition() instanceof Refuge) rest(); else move(world.refuges); } } protected void moveToEntrances(Collection fires) throws ActionCommandException { if (!fires.isEmpty()) move(ENTRANCE_PRP.collect(fires)); } protected void moveToRefuges() throws ActionCommandException { if (self().motionlessPosition() instanceof Refuge) rest(); move(world.refuges); } protected void hearTell(RealObject sender, int channelId, String message) { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -