(GoToItem) // push Pickup when the item is reached(Pickup, GoToItem) // pop Pickup, meaning perform the action(GoToItem) // push Pickup when the item is reached(Pickup, GoToItem) // pop Pickup, meaning perform the action(GoToItem) // push ReturnCargo when the cargo hold is full(ReturnCargo, GoToItem) // pop ReturnCargo, meaning perform the action(GoToItem) // continue item hunting
As I read your example, it looks like you have at most 2 goals on the stack at a time.
In my approach, I created the complete plan by laying out all the goals before starting the execution. So after going through the for loops the queue contained about 7 goals, and only then would execution begin.
So it may come down to picking the data structure that matches one's way of thinking about the problem...