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

📄 ambulanceteamagent.java

📁 机器人设计的Java源程序,提供给大家参考参考
💻 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 AmbulanceTeamAgent extends AbstractAmbulanceTeamAgent {    private final Set m_unvisitedBuildings;    public AmbulanceTeamAgent(InetAddress address, int port)     {        super(address, port);        m_unvisitedBuildings = new HashSet(world.buildings);    }    protected MotionlessObject mlpos()     {     	return self().motionlessPosition();     }    protected static final Property        DAMAGE_PRP     = Property.get("Humanoid", "damage"),        BURIEDNESS_PRP = Property.get("Humanoid", "buriedness"),        POSITION_PRP   = Property.get("MovingObject", "position"),        FIERYNESS_PRP  = Property.get("Building", "fieryness");    protected static final Condition        IS_NOT_BURNING_CND = FIERYNESS_PRP.lt(1).or(FIERYNESS_PRP.gt(3));    protected void prepareForAct()     {        super.prepareForAct();        if (mlpos() instanceof Building)            m_unvisitedBuildings.remove(mlpos());    }    protected void act() throws ActionCommandException //动作执行函数(最主要的函数)    {    	//needToGoRefuge();              //1  添加一个判断是否受伤的策略       		if (isLoadingInjured())       		carry();        List hmns = POSITION_PRP.eq(mlpos()).extract(world.humanoids);        hmns.remove(self());        if (!hmns.isEmpty())         {            rescue(hmns);            load(hmns);        }        searchTheInjured();    }	//*************************************************************************//1    private void needToGoRefuge() throws ActionCommandException                     {        if ((self().hp() < 5500 && self().damage() > 4) || self().damage()>=400 )//根据自己的生命值、受伤程度,判断        {        	if(self().motionlessPosition() instanceof Refuge)                   //自己是否在避难所?        		rest();															//是的,休息            else             	move(world.refuges);											//不是,移动到避难所        }    }    //*************************************************************************//    protected void carry() throws ActionCommandException     {        if (mlpos() instanceof Refuge)            unload();        else            move(world.refuges);    }    protected void rescue(List hmns) throws ActionCommandException    {        List brd = BURIEDNESS_PRP.gt(0).extract(hmns);        if (!brd.isEmpty())            rescue((Humanoid) DAMAGE_PRP.max(brd));    }    protected void load(List hmns) throws ActionCommandException    {        List inj = DAMAGE_PRP.gt(0).extract(hmns);        if (!inj.isEmpty())            load((Humanoid) DAMAGE_PRP.max(inj));    }    protected void searchTheInjured() throws ActionCommandException    {        List bldgs = IS_NOT_BURNING_CND.extract(m_unvisitedBuildings);        if (!bldgs.isEmpty())            move(bldgs);    }    protected void hearTell(RealObject sender, int channelId, String message) 	{	}}

⌨️ 快捷键说明

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