Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. package examples;
  2.  
  3. import jade.core.Agent;
  4. import jade.core.behaviours.CyclicBehaviour;
  5. import jade.wrapper.AgentController;
  6. import jade.wrapper.ContainerController;
  7.  
  8. public class CounterAgent extends Agent {
  9.  
  10.     private int round = 0;
  11.     private boolean finished = true;
  12.  
  13.     protected void setup() {
  14.         addBehaviour(new MyCyclicBehaviour(this));
  15.         addBehaviour(new AnotherCyclicBehaviour(this));
  16.  
  17.         ContainerController c = getContainerController();
  18.         try {
  19.             AgentController a = c.createNewAgent("IVAN", "examples.CounterAgent", null);
  20.             a.start();
  21.         } catch (Exception e) {
  22.             e.printStackTrace();
  23.         }
  24.     }
  25.  
  26.     class MyCyclicBehaviour extends CyclicBehaviour {
  27.  
  28.         public MyCyclicBehaviour(Agent agent) {
  29.             super(agent);
  30.         }
  31.  
  32.         @Override
  33.         public void action() {
  34.             System.out.println("Inside ACTION:: " + round++);
  35.         }
  36.  
  37.     }
  38.  
  39.     class AnotherCyclicBehaviour extends CyclicBehaviour {
  40.  
  41.         public AnotherCyclicBehaviour(Agent agent) {
  42.             super(agent);
  43.         }
  44.  
  45.         @Override
  46.         public void action() {
  47.             if (round == 21) {
  48.                 this.myAgent.doDelete();
  49.             }
  50.         }
  51.  
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement