Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import jade.core.Agent;
- import jade.core.behaviours.*;
- import java.util.concurrent.ThreadLocalRandom;
- public class klasa_2_1 extends Agent {
- protected void setup()
- {
- System.out.println("startuję");
- FSMBehaviour FSM1 = new FSMBehaviour();
- FSM1.registerFirstState(new OneShotBehaviour() {
- public void action() { System.out.println("A"); }
- }, "A");
- FSM1.registerLastState(new OneShotBehaviour() {
- public void action() { System.out.println("E"); }
- }, "E");
- FSM1.registerState(new OneShotBehaviour() {
- public void action() { System.out.println("B"); }
- public int onEnd() { return ThreadLocalRandom.current().nextInt(0,2); }
- }, "B");
- FSM1.registerState(new OneShotBehaviour() {
- public void action() { System.out.println("C"); }
- }, "C");
- FSM1.registerState(new OneShotBehaviour() {
- public void action() { System.out.println("D"); }
- public int onEnd() { return ThreadLocalRandom.current().nextInt(0,2); }
- }, "D");
- }
- protected void takeDown()
- {
- System.out.println("zaraz się usunę");
- }
- public class zachowanie_1 extends Behaviour
- {
- private char stan = 'A';
- int rnd;
- public void action()
- {
- switch(stan)
- {
- case 'A':
- System.out.println("Stan: " + stan);
- stan = 'B';
- break;
- case 'B':
- System.out.println("Stan: " + stan);
- rnd = ThreadLocalRandom.current().nextInt(0,2);
- if(rnd == 0)
- stan = 'D';
- else
- stan = 'C';
- break;
- case 'C':
- System.out.println("Stan: " + stan);
- stan = 'D';
- break;
- case 'D':
- System.out.println("Stan: " + stan);
- rnd = ThreadLocalRandom.current().nextInt(0,2);
- if(rnd == 0)
- stan = 'E';
- else
- stan = 'A';
- break;
- }
- }
- public boolean done()
- {
- return stan == 'E';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement