The biggest challenge faced during development of the GOAP system was keeping the planner at an acceptable level of efficiency. Planning using A* is a CPU intensive task so it was desirable to keep the number of searches to the very minimum. Recalculating the relevancies of all the goals and finding the highest goal to plan towards can also use up resources as goals query the working memory. If the working memory contains many working memory facts then this search can become time-consuming. Instead of recalculating the relevancies of all goals, it is sometimes possible to just re-build a plan towards the same goal if a previous plan has become invalidated. Suppose the current goal is KillEnemy and upon the execution of an Attack action it is discovered the agent has no ammunition. The plan becomes invalidated but instead of recalculating all goal relevancies again, a replan is triggered which requests the planner just to build a plan towards the KillEnemy goal and not search for a new goal.
Every time the relevancy of a goal is checked, a timer is set for that goal that stops it being checked again for a certain period of time. This reduces the number of goals that are checked when looking for a valid goal and thus can improve performance.
One way of limiting the amount of replanning was to ensure that actions didn’t complete or weren’t invalidated too often. Obviously this can depend on the action in the game itself but the best way of ensuring that actions weren’t invalidated too soon was to make sure that the context preconditions and world state preconditions were comprehensive enough before the action was activated. An action is only invalidated if the action can’t possibly function any more.
However, due to the fast-paced nature of the game developed and even with the optimisations listed, there was quite a lot of planning and replanning involved during the game. If actions lasted longer than they do in the Domination game, there could possibly be minutes between having to plan or replan which of course would improve performance substantially. Also, because there are relatively few actions and goals in this project there