jadex.bdi.examples.puzzle.PlayGamePlan 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.puzzle;
import jadex.bdi.runtime.IGoal;
import jadex.bdi.runtime.Plan;
/**
* Play the game until a solution is found.
*/
public class PlayGamePlan extends Plan
{
/**
* The plan body.
*/
public void body()
{
System.out.println("Now puzzling:");
long start = getTime();
long startmem = Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory();
IGoal play = createGoal("makemove");
play.getParameter("depth").setValue(new Integer(0));
try
{
dispatchSubgoalAndWait(play);
// System.out.println("Found a solution: "
// +board.getMoves().size()+" "+board.getMoves());
}
// catch(GoalFailureException gfe)
catch(Exception gfe)
{
System.out.println("No solution found :-( "+gfe);
}
long end = getTime();
System.out.println("Needed: "+(end-start)+" millis.");
if(getBeliefbase().containsBelief("endmem"))
{
Long endmem = (Long) getBeliefbase().getBelief("endmem").getFact();
if(endmem!=null)
{
System.out.println("Needed: "+(((endmem.longValue()-startmem)*10/1024)/1024)/10.0+" Mb.");
}
}
killAgent();
}
}