AgentDecision.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. namespace MazeGen
  2. {
  3. /// <summary>
  4. /// Abstract base class for all agent decisions. Each decision encapsulates:
  5. /// - A precondition check (CanExecute)
  6. /// - An action to perform (Execute)
  7. /// - A narration of the decision (Think)
  8. ///
  9. /// The key insight: keeping CanExecute, Execute, and Think together ensures that
  10. /// every action the agent takes is explained to the observer. Adding a new decision
  11. /// without narration makes the agent's behavior unexplainable.
  12. ///
  13. /// Decisions are evaluated in order by AgentDecisionTree, which returns the first
  14. /// one whose CanExecute() returns true.
  15. /// </summary>
  16. public abstract class AgentDecision
  17. {
  18. /// <summary>
  19. /// Check if this decision can be executed given the agent's current state.
  20. /// Return true if this decision should be considered.
  21. /// </summary>
  22. public abstract bool CanExecute(MazeAgent agent);
  23. /// <summary>
  24. /// Execute the decision. This modifies the agent's state or the world.
  25. /// Returns true if the decision consumed the agent's decision this tick,
  26. /// false if the agent should continue to the next decision in the tree.
  27. /// </summary>
  28. public abstract bool Execute(MazeAgent agent);
  29. /// <summary>
  30. /// Narrate this decision to the agent's thought log.
  31. /// Called after Execute() if Execute() returned true.
  32. /// This is what the HUD's "Agent thoughts" panel shows.
  33. ///
  34. /// Keep this synchronized with Execute(): if Execute() does something,
  35. /// Think() must explain it. Otherwise the observer sees an agent doing
  36. /// things for no explained reason.
  37. /// </summary>
  38. public abstract void Think(MazeAgent agent);
  39. /// <summary>
  40. /// Human-readable name for debugging/logging.
  41. /// </summary>
  42. public abstract string DecisionName { get; }
  43. }
  44. }