Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. use v6.c;
  2.  
  3. use AI::Agent::Actor;
  4. use AI::Agent::Agent;
  5.  
  6. class AI::Agent::HashedAgent is AI::Agent::Agent
  7. {
  8. has &!callback;
  9. has AI::Agent::Agent @!dependencies;
  10. has Bool $.done;
  11.  
  12. method BUILD(:$status) {
  13. $.status = $status;
  14. self.add-depedency(self.ask);
  15. self.add-depedency(self.agent);
  16. }
  17.  
  18. method add-dependency(AI::Agent::Agent $dependency) {
  19. push @!dependencies, $dependency;
  20. }
  21.  
  22. method ask(%args) {
  23. return "You can ask me the following:
  24. RET
  25. agent, dispatch args = \{ agent, agent instance \}
  26. RET
  27. ";
  28. }
  29.  
  30. # agent dispatched, overload for other agent parsing
  31. method dispatch_agent($agent) {
  32. return &$agent.dispatch;
  33. }
  34.  
  35. # Look if an agent is dispatched, note the "agent" key for agents
  36. method agent(%args) {
  37. %args{"agent"}.dispatch_agent(self);
  38. }
  39. 24,1 55%
  40. ### main call to the actor-agent
  41.  
  42. method dispatch($message, %optargs) {
  43. unless $!done {
  44. self.dispatch($message, %optargs) for @!dependencies;
  45. &!callback();
  46. $!done = True;
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement