For the uninitiated GOAP stands for Goal Oriented Action Planner. The AI basically chooses a goal from a set of goals and then finds a chain of actions that allow it to meet that goal.
Each goal will have conditions that must be met to make it a success, each action will have preconditions that need to exist to execute it and effects of it being executed successfully. So for example take the following action:
Action: eat_cake
Preconditions: cakeCount>0
Effect: cakeCount--, hunger--
We can clearly see that eating a cake will lose us one cake, and also decrease our hunger. However we do need to have cake to eat cake hence the precondition.
GOAP traditionally chains these actions together using A*, so actions have costs associated with them, now the heuristic cost is a bit difficult. With A* used for path finding you can just draw a line from x to the end point and call that the heuristic distance. But with actions and goals its not as clear how you can measure how far you are from completing the goal, after all this is a more abstract that distance. Now with my action planner for GOAP I'm using the number of unresolved conditions - preconditions that have to be met for any actions I've chosen and the conditions to satisfy the goal that haven't been met - as the score.
The A* search works best regressively, moving from the goal to the current world state as this narrows down actions. For the goal kill_entity all the end goals are going to have the effect entityDead==true, and this will be a limited number, whereas any actions out of the action set could go before in the plan to satisfy relevant preconditions.
Now the reason I went from my finite state machines to GOAP is because the "next state" logic in GOAP is essential kept in each action, if I want to change the AI or the game by adding new behaviours or skills all I have to do is add the relevant actions and goals, there's no need to change existing classes whereas in finite state machines you would have to go through the relevant states and change the transition logic.
I'm still in the process of integrating GOAP into my game however the planner is coded, abstract classes have been created and the main leap now is to implement some real actions and goals and integrate it all into my current framework.
But as well as being very versatile GOAP is quite timely to implement but I believe it will be worthwhile and hopefully I can start testing it in some basic situations in the next few months.
For anyone who wants to learn more about GOAP you can find a lot of useful information here: http://web.media.mit.edu/~jorkin/goap.html
Nice explanation of the topic.
ReplyDeleteThanks, part of me wants to do a bigger more detailed one with graphs and everything but the literature on GOAP is already pretty intensive I feel I'd just be repeating what's been said before.
ReplyDeleteAlthough once I've got it all done I could possibly add some insights on actually creating the actions and assigning scores to goals to choose the most relevant ones etc