bdi4jade

Hello world example.

10/19/2011 12:02:21 PM

Details

diff --git a/bdi-jade-test/src/br/pucrio/inf/les/bdi4jade/examples/AgentStarter.java b/bdi-jade-test/src/br/pucrio/inf/les/bdi4jade/examples/AgentStarter.java
index 1bd0650..3e89e6c 100644
--- a/bdi-jade-test/src/br/pucrio/inf/les/bdi4jade/examples/AgentStarter.java
+++ b/bdi-jade-test/src/br/pucrio/inf/les/bdi4jade/examples/AgentStarter.java
@@ -37,6 +37,8 @@ import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import br.pucrio.inf.les.bdi4jade.examples.helloworld.HelloWorldAgent;
+
 /**
  * @author ingrid
  * 
@@ -47,8 +49,9 @@ public class AgentStarter {
 
 	static {
 		agents = new HashMap<String, Agent>();
-		agents.put(BDIAgent1.MY_NAME, new BDIAgent1());
-//		agents.put(BDIAgent2.MY_NAME, new BDIAgent2());
+		agents.put(HelloWorldAgent.class.getSimpleName(), new HelloWorldAgent());
+		// agents.put(BDIAgent1.MY_NAME, new BDIAgent1());
+		// agents.put(BDIAgent2.MY_NAME, new BDIAgent2());
 	};
 
 	public static void main(String[] args) {
diff --git a/bdi-jade-test/src/br/pucrio/inf/les/bdi4jade/examples/helloworld/HelloWorldAgent.java b/bdi-jade-test/src/br/pucrio/inf/les/bdi4jade/examples/helloworld/HelloWorldAgent.java
new file mode 100644
index 0000000..547467e
--- /dev/null
+++ b/bdi-jade-test/src/br/pucrio/inf/les/bdi4jade/examples/helloworld/HelloWorldAgent.java
@@ -0,0 +1,49 @@
+/*
+ * Created on 19 Oct 2011 14:42:24 
+ */
+package br.pucrio.inf.les.bdi4jade.examples.helloworld;
+
+import br.pucrio.inf.les.bdi4jade.core.BDIAgent;
+import br.pucrio.inf.les.bdi4jade.core.Capability;
+import br.pucrio.inf.les.bdi4jade.goal.Goal;
+import br.pucrio.inf.les.bdi4jade.util.plan.SimplePlan;
+
+/**
+ * @author ingridn
+ * 
+ */
+class HelloWorldGoal implements Goal {
+
+	private static final long serialVersionUID = -9039447524062487795L;
+
+	private String name;
+
+	public HelloWorldGoal(String name) {
+		this.name = name;
+	}
+
+	public String getName() {
+		return name;
+	}
+}
+
+public class HelloWorldAgent extends BDIAgent {
+
+	private static final long serialVersionUID = 2712019445290687786L;
+
+	protected void init() {
+		addCapability(new Capability() {
+
+			private static final long serialVersionUID = 5271907167861942067L;
+
+			protected void setup() {
+				getPlanLibrary().addPlan(
+						new SimplePlan(HelloWorldGoal.class,
+								HelloWorldPlan.class));
+			}
+
+		});
+
+		addGoal(new HelloWorldGoal("reader"));
+	}
+}
diff --git a/bdi-jade-test/src/br/pucrio/inf/les/bdi4jade/examples/helloworld/HelloWorldPlan.java b/bdi-jade-test/src/br/pucrio/inf/les/bdi4jade/examples/helloworld/HelloWorldPlan.java
new file mode 100644
index 0000000..b952afe
--- /dev/null
+++ b/bdi-jade-test/src/br/pucrio/inf/les/bdi4jade/examples/helloworld/HelloWorldPlan.java
@@ -0,0 +1,32 @@
+/*
+ * Created on 19 Oct 2011 15:00:34 
+ */
+package br.pucrio.inf.les.bdi4jade.examples.helloworld;
+
+import jade.core.behaviours.OneShotBehaviour;
+import br.pucrio.inf.les.bdi4jade.plan.PlanBody;
+import br.pucrio.inf.les.bdi4jade.plan.PlanInstance;
+import br.pucrio.inf.les.bdi4jade.plan.PlanInstance.EndState;
+
+/**
+ * @author ingridn
+ * 
+ */
+public class HelloWorldPlan extends OneShotBehaviour implements PlanBody {
+
+	private static final long serialVersionUID = -9039447524062487795L;
+
+	private String name;
+
+	public void action() {
+		System.out.println("Hello, " + name + "!");
+	}
+
+	public EndState getEndState() {
+		return EndState.SUCCESSFUL;
+	}
+
+	public void init(PlanInstance planInstance) {
+		this.name = ((HelloWorldGoal) planInstance.getGoal()).getName();
+	}
+}