jadex.bdi.examples.garbagecollector_classic.CheckingPlan Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-bdi Show documentation
Show all versions of jadex-applications-bdi Show documentation
The Jadex BDI applications package contain
several example applications, benchmarks and
testcases using BDI agents.
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);
}
}*/
}