Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 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 %.dependencies;
  9. has $!done;
  10.  
  11. method BUILD() {
  12. self.add-dependency(&self.ask);
  13. self.add-dependency(&self.agent);
  14. }
  15.  
  16. method add-dependency($dependency) {
  17. %.dependencies{$dependency.name => $dependency};
  18. }
  19.  
  20. method ask(%args) {
  21. return qq:to/RET/:
  22. You can ask me the following:
  23. agent, dispatch args = \{ "agent", Agent instance \}
  24. RET
  25.  
  26. }
  27.  
  28. # agent dispatched, overload for other agent parsing
  29. method dispatch_agent($agent) {
  30. return &$agent.dispatch;
  31. }
  32.  
  33. # Look if an agent is dispatched, note the "agent" key for agents
  34. method agent(%args) {
  35. %args{"agent"}.dispatch_agent(self);
  36. }
  37.  
  38. ### main call to the actor-agent
  39. method dispatch($message, %optargs) {
  40. unless $!done {
  41. self.dispatch($message, %optargs) for %!dependencies;
  42. $!done = True;
  43. }
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement