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

📄 coforagefieldsim.java

📁 利用JAVA编写的群体机器人局部通讯完成一定得队形控制
💻 JAVA
字号:
/* * CoForageFieldSim.java */package EDU.gatech.cc.is.simulation;import java.awt.*;import EDU.gatech.cc.is.util.Vec2;import EDU.gatech.cc.is.util.Units;import EDU.gatech.cc.is.communication.Message;import EDU.cmu.cs.coral.util.Polygon2;import EDU.cmu.cs.coral.util.Circle2;/** * Draw an official RoboCup soccer field. * <P> * Copyright (c)2000 Tucker Balch * * @author Tucker Balch * @version $Revision: 1.3 $ */public class CoForageFieldSim extends Object implements SimulatedObject	{	protected 	Vec2	position = new Vec2(0,0);	protected	Color	foreground = Color.green;	protected	SimulatedObject[] all_objects = new SimulatedObject[0];	protected	int	visionclass = 0;	protected	int	unique_id = 0;	protected	double	homeRadius = 1.5;		protected	double	workRadiusOne = 8;	protected	double	workRadiusTwo = 18;		protected	double	top = 20;	protected	double	bottom = -20;	protected	double	left = -20;	protected	double	right = 20;	protected	double	width = 660;//pixels	protected	double	height = 660;//pixels	protected	double	meterspp = (right-left)/width;	public		static final boolean DEBUG = false;	/**	 * Instantiate a <B>SocFieldSmallSim</B> object.  Be sure	 * to also call init with proper values.	 * @see SocFieldSmallSim#init	 */    public CoForageFieldSim()		{		if (DEBUG) System.out.println("CoForageFieldSim: instantiated.");		}	    /**     * Initialize an <B>SocFieldSmallSim</B> object.	 * Called automatically by JavaBotSim.	 * None of the arguments are used except unique id.	 * @param xp	ignored.	 * @param yp	ignored.	 * @param t	ingored.	 * @param r	ignored.	 * @param f	ignored.	 * @param b	ignored.	 * @param v	vision class (should be 0 for invisible).	 * @param i	the unique id.	 * @param s	random number seed.         */	public void init(double xp, double yp, double t, double r,		Color f, Color b, int v, int i, long s)		{		foreground = f;		visionclass = v;		setID(i);		if (DEBUG) System.out.println("CoForageFieldSim: initialized");		}	/**	 * Take a simulated step;	 */	public void takeStep(long time_increment, SimulatedObject[] all_objs)		{		// do nothink!		}		public boolean isObstacle()		{		return(false);		}		public boolean isPushable()		{		return(false);		}		public void receive(Message m)		{		// ignore messages.		}		public boolean isPickupable()		{		return(false);		}	    public Vec2 getPosition()        {		// say we are far away to avoid interactions.		return(new Vec2(99999999,0));        }	public Vec2 getClosestPoint(Vec2 from)		{		// say we are far away to avoid interactions.		return(new Vec2(99999999,0));		}    /**	 * determine if the object is intersecting with a specified circle.	 * This is useful for obstacle avoidance and so on.	 * @param c the circle which may be intersecting the current object.	 * @return true if collision detected.     */	public boolean checkCollision(Circle2 c)	    {	    return false;	    }    /**	 * determine if the object is intersecting with a specified polygon.	 * This is useful for obstacle avoidance and so on.	 * @param p the polygon which may be intersecting the current object.	 * @return true if collision detected.     */	public boolean checkCollision(Polygon2 p)		{		return false;				}	public Vec2 getCenter(Vec2 from)		{		// say we are far away to avoid interactions.		return(new Vec2(99999999,0));		}	public void push(Vec2 d, Vec2 v)		{		// ignore.		}	public void pickUp(SimulatedObject o)		{		// ignore.		}	public void putDown(Vec2 p)		{		// ignore.		}	public void setVisionClass(int v)		{		visionclass = v;		}	public int getVisionClass()		{		return(visionclass);		}	public void setID(int i)		{		unique_id = i;		}	public int getID()		{		return(unique_id);		}	public void quit()		{		}	/**	 * Convert from size in meters to pixels.	 */	public	int	size(double m)		{		return((int)((m / meterspp)));		}	/**	 * Convert y in field coordinates to Y in pixel coordinates.	 */	public	int	Y(double y)		{		return((int)(height-((y - bottom) / meterspp)));		}			/**	 * Convert x in field coordinates to X in pixel coordinates.	 */	public	int	X(double x)		{		return((int)(((x - left) / meterspp)));		}		    /**     * Draw the objects's State.     */     public void drawState(Graphics g, int w, int h,                double t, double b, double l, double r)         {         //skip for soccer fields         }     public void drawID(Graphics g, int w, int h,                double t, double b, double l, double r)          {          //skip for soccer fields          }               public void drawIcon(Graphics g, int w, int h,                double t, double b, double l, double r)        {          draw(g, w, h, t, b, l, r);        }     public void setTrailLength(int l)		{		//ignore		}     public void clearTrail()		{		//ignore		}     public void drawTrail(Graphics g, int w, int h,                double t, double b, double l, double r)    	{        //skip for soccer fields    	}	/**	 * Draw the field.	 */	public void draw(Graphics g, int w, int h,		double t, double b, double l, double r)		{					// draw the outer boundary				Color   border = new Color(0xB0C088);			g.setColor(border);						g.fillOval(0,0,(int)width,(int)height);			g.setColor(Color.white);			g.fillOval(2,2,(int)(width-4),(int)(height-4));						//draw the circle of workRadiusTwo.			Color   puckArea = new Color(0xF0F0FF);			g.setColor(puckArea);			g.fillOval((int)((top-workRadiusTwo)/meterspp),					   (int)((top-workRadiusTwo)/meterspp),					   (int)(2*workRadiusTwo/meterspp),					   (int)(2*workRadiusTwo/meterspp));					   		    //draw the circle of workRadiusOne.			g.setColor(Color.white);			g.fillOval((int)((top-workRadiusOne)/meterspp),					   (int)((top-workRadiusOne)/meterspp),					   (int)(2*workRadiusOne/meterspp),					   (int)(2*workRadiusOne/meterspp));					   			//draw the circle of home.			Color   home = new Color(0x7070BF);			g.setColor(home);					g.fillOval((int)((top-homeRadius)/meterspp),					   (int)((top-homeRadius)/meterspp),					   (int)(2*homeRadius/meterspp),					   (int)(2*homeRadius/meterspp));									}   /**    * Draw the field in a specific spot.	* This doesn't really make sense for the soccer field, but	* we need to handle it just in case someone calls it.    */    public void draw(Vec2 pos, Graphics g, int w, int h,                double t, double b, double l, double r)         {         	draw(g,w,h,t,b,l,r);         }                  	}

⌨️ 快捷键说明

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