Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. import jade.core.Agent;
  2. import jade.core.behaviours.*;
  3.  
  4. import java.util.concurrent.ThreadLocalRandom;
  5.  
  6.  
  7. public class klasa_2_1 extends Agent {
  8.  
  9.  
  10. protected void setup()
  11. {
  12. System.out.println("startuję");
  13.  
  14. FSMBehaviour FSM1 = new FSMBehaviour();
  15.  
  16. FSM1.registerFirstState(new OneShotBehaviour() {
  17. public void action() { System.out.println("A"); }
  18. }, "A");
  19.  
  20. FSM1.registerLastState(new OneShotBehaviour() {
  21. public void action() { System.out.println("E"); }
  22. }, "E");
  23.  
  24. FSM1.registerState(new OneShotBehaviour() {
  25. public void action() { System.out.println("B"); }
  26. public int onEnd() { return ThreadLocalRandom.current().nextInt(0,2); }
  27. }, "B");
  28.  
  29. FSM1.registerState(new OneShotBehaviour() {
  30. public void action() { System.out.println("C"); }
  31. }, "C");
  32.  
  33. FSM1.registerState(new OneShotBehaviour() {
  34. public void action() { System.out.println("D"); }
  35. public int onEnd() { return ThreadLocalRandom.current().nextInt(0,2); }
  36. }, "D");
  37. }
  38.  
  39. protected void takeDown()
  40. {
  41. System.out.println("zaraz się usunę");
  42. }
  43.  
  44. public class zachowanie_1 extends Behaviour
  45. {
  46. private char stan = 'A';
  47. int rnd;
  48.  
  49. public void action()
  50. {
  51. switch(stan)
  52. {
  53. case 'A':
  54. System.out.println("Stan: " + stan);
  55. stan = 'B';
  56. break;
  57. case 'B':
  58. System.out.println("Stan: " + stan);
  59. rnd = ThreadLocalRandom.current().nextInt(0,2);
  60. if(rnd == 0)
  61. stan = 'D';
  62. else
  63. stan = 'C';
  64. break;
  65. case 'C':
  66. System.out.println("Stan: " + stan);
  67. stan = 'D';
  68. break;
  69. case 'D':
  70. System.out.println("Stan: " + stan);
  71. rnd = ThreadLocalRandom.current().nextInt(0,2);
  72. if(rnd == 0)
  73. stan = 'E';
  74. else
  75. stan = 'A';
  76. break;
  77. }
  78. }
  79.  
  80. public boolean done()
  81. {
  82. return stan == 'E';
  83. }
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement