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

jadex.bdi.examples.puzzle.PlayGamePlan 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.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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy