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

jadex.bdi.examples.garbagecollector_classic.CheckingPlan Maven / Gradle / Ivy

Go to download

The Jadex BDI applications package contain several example applications, benchmarks and testcases using BDI agents.

There is a newer version: 2.4
Show newest version
package jadex.bdi.examples.garbagecollector_classic;

import jadex.bdi.runtime.IGoal;
import jadex.bdi.runtime.Plan;

/**
 *  Check the grid for garbage.
 */
public class CheckingPlan extends Plan
{
	/**
	 *  The plan body.
	 */
	public void body()
	{
		Environment env = (Environment)getBeliefbase().getBelief("env").getFact();
		int size = env.getGridSize();
		Position mypos = (Position)getBeliefbase().getBelief("pos").getFact();
		Position newpos = computeNextPosition(mypos, size);

//		System.out.println("Moving from "+mypos+" to: "+newpos);
		IGoal go = createGoal("go");
		go.getParameter("pos").setValue(newpos);
		dispatchSubgoalAndWait(go);
//		System.out.println("Moved to: "+newpos);
	}

	/**
	 *  Compute the next position.
	 */
	protected static Position computeNextPosition(Position pos, int size)
	{
		if(pos.getX()+1=0 && pos.getY()%2==1)
		{
			pos = new Position(pos.getX()-1, pos.getY());
		}
		else
		{
			pos = new Position(pos.getX(), (pos.getY()+1)%size);
		}

		return pos;
	}

	/*public static void main(String[] args)
	{
		Position pos = new Position(0,0);
		while(true)
		{
			System.out.println(pos);
			pos = computeNextPosition(pos, 5);
		}
	}*/
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy