I'm reading about goal-oriented planning for AI, but there I'm having difficulty finding an implementation so that I can address some questions that I have. Specifically, I don't understand how to handle scenarios in which an agent is in the middle of a goal, but then another goal gets calculated as higher priority. For example, suppose I have the following goals/subgoals/actions
MineGold (goal) |--> MoveToGoldMine (goal) | |--> MoveToPosition (action) |--> SwingPickaxe (action) |--> TakeGold (action) |--> DeliverGold (goal) | |--> MoveToTownHall (goal) | | |--> MoveToPosition (action) | |--> DropGold (action) AvoidEnemy (goal) |--> MoveToHidingSpot (goal) | |--> MoveToPosition (action) |--> Wait (action) AttackEnemmy (goal) |--> MoveToEnemy (goal) | |--> MoveToPosition (action)
When the game starts, my agent calculates its goal priorities and its highest priority is the
MineGold goal. So it pushes the list of subgoals and actions for
MineGold onto its planning stack.
Suppose the agent moves to the gold mine, mines the gold, takes the gold, and then starts to move back to the town hall. While it's moving back to the town hall, an enemy soldier gets close enough such that the
AvoidEnemy goal becomes higher priority than the
MineGold goal. So now the agent pushes the
AvoidEnemy subgoals and actions into its stack, ahead of the remaining
While the agent is avoiding the soldier, an enemy assassin sneaks up on his team's commander. The commander calls for help so the
AttackEnemy goal becomes the highest priority. So
AttackEnemy is pushed onto the stack ahead of
Eventually the assassin is killed, so the
AttackEnemy goal is no longer valid and gets popped off the stack. Now the topmost goal is
AvoidEnemy to avoid the enemy soldier. But if my agent just attacked the assassin, it would be weird for him to then start running away from the soldier (or maybe the soldier is already far away and I don't want to keep moving to a hiding spot), so I would rather him return to his original goal of
Here are my questions:
- Am I correct in assuming that I should be periodically recalculating the highest priority goal and switching to the highest priority goal if it's different than the existing goal?
- Am I correct that when a new goal becomes higher priority than the current goal, then I should be pushing that new goal onto the stack ahead of the current goal, as opposed to overwriting the current goal with the new goal?
- Assuming I'm correct that new goals are additive, how do I handle this situation where sometimes I don't want an agent to return to certain prior goals? I know that I could accomplish this through a set of "mutually exclusive" flags or something, but that seems like an inelegant way and that it would start to return me to using finite state machines instead of goal-oriented planning.