All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.micro.examples.hunterprey.service.prey.ServicePreyAgent Maven / Gradle / Ivy

Go to download

The Jadex micro applications package contains several example applications, benchmarks and testcases using micro agents.

There is a newer version: 4.0.267
Show newest version
package jadex.micro.examples.hunterprey.service.prey;

import jadex.micro.annotation.Agent;
import jadex.micro.annotation.Binding;
import jadex.micro.annotation.RequiredService;
import jadex.micro.annotation.RequiredServices;
import jadex.micro.examples.hunterprey.service.IHunterPreyEnvironmentService;


/**
 *  A prey implemented using the EnvSupport service interface.
 */
@Agent
@RequiredServices(@RequiredService(name="env", type=IHunterPreyEnvironmentService.class,
	binding=@Binding(scope=Binding.SCOPE_PLATFORM)))
public class ServicePreyAgent
{
//	//-------- attributes --------
//	
//	/** The environment. */
//	@AgentService(name="env")
//	protected IHunterPreyEnvironmentService	env;
//	
//	//-------- agent methods --------
//	
//	/**
//	 *  Register the agent as a prey at startup.
//	 */
//	@AgentCreated
//	public void	start()
//	{
//		env.registerPrey().addResultListener(new IntermediateDefaultResultListener>()
//		{
//			public void intermediateResultAvailable(Collection percepts)
//			{
//				perceptsReceived(percepts);
//			}
//		});
//	}
//	
//	//-------- prey methods --------
//	
//	/**
//	 *  Called once in each round.
//	 */
//	public void	perceptsReceived(Collection percepts)
//	{
//		boolean	done	= false;
//		for(IPreyPerceivable percept: percepts)
//		{
//			if(percept instanceof IFood)
//			{
//				IFood	food	= (IFood)percept;
//				// At location of food -> eat
//				if(food.getX()==0 && food.getY()==0)
//				{
//					env.eat(food);
//					done	= true;
//				}
//			}
//		}
//		
//		if(!done)
//		{
//			String[]	dirs	= new String[]{
//				IHunterPreyEnvironmentService.DIRECTION_UP, IHunterPreyEnvironmentService.DIRECTION_DOWN,
//				IHunterPreyEnvironmentService.DIRECTION_LEFT, IHunterPreyEnvironmentService.DIRECTION_RIGHT};
//			env.move(dirs[new Random().nextInt(dirs.length)]);
//		}
//	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy