Specialisation

Intro

At The Game Assembly at year 2 I chose to specialize in AI to try my hands at a Goal Oriented Action Planning which we had discussed but not really delved to deep into. So I wanted to make a simulation with animal AI which used GOAP as their decision making tool. I wanted to try my hands at using UNREAL ENGINE 4 for this project.

Goal

The goal of the project is to have a small group of animals trying to survive in a small gameworld where they have to make decisions based on what they know and need to do to survive. They should be using a goal oriented actionplan as their baseline for decisions and learn about the world through traveling and discovering new waypoints. You should be able to see what the parameters of a set animal is and be able to toggle between the animals to see what each one is up to.

Development Of The Actionplan

Derive Actionplan

The fox calculates a goal based on it’s parameters and sends that plus it’s status into it’s planner which will check which action fulfills the goal and then check which actions that action requires to be able to perform.

The function DeriveActionPlan is a recursive function that dosen’t stop until it finds a valid actionplan for the actor to use. First it check’s which action has the corresponding goal then runs the function CalculateOptimalPlan with that action as it’s baseline. That function checks if their is a known waypoint that can fulfill the goal.

It then uses the function ConstructActionPlan which checks what the cost of the action is going to be and adds a restaction if the cost is to high. After that it places the actions in the right order into the actionplan.

The waypoint is a location in the gameworld with some data attached to it. It contains a type and a state for the waypoint as well as an amount. Once a valid actionplan has been established the actor can then use it to perform it’s actions. The amount of resources a waypoint has gets depleted each time a fox uses it. This in turn will result in them running out, which results in them being removed from the planner. This will force the foxes to explore new areas after a certain amount of time has passed. Their are a few water sources that will take longer to deplete than others and the food points will regress to being buried if enough time has passed since last usage.

The Action

Each action is it’s own class which derives from it’s parent class ActionBase which contains the basic functionality that an action requires to be used. Like if it is a valid action, what it’s precondition actions are and what it’s goal and fallback goal is.

Using The Actionplan

Once you have received an actionplan the actor picks out the top action and places it as it’s current action which involves doing an update on it and checking if it is done.

When it’s done you execute next action and keep doing this until you have emptied the actionplan, in which case you need to calculate a new goal then request a new actionplan from the planner.

Search Action

This action is the fallback if there is no valid action that satisfy the current goal. Like if the goal is food, but the planner hasn’t discovered any food waypoints. The first fallback for this is a followtrail goal but if there is no trail waypoints either then the only action left is the search action.

The baseline for this action is a wander function which makes the actor move towards a point inside a circular area infront of it. One of the clear conditions for the search action is the discovery of a new waypoint, which will trigger the actor to request a new actionplan. If the discoverd waypoint was a food waypoint the current goal of food can now be fulfilled, leading to the search action not being needed to find food.

Result

The result of this approach is an AI which wanders around a lot when it’s parameters are high and then when one falls bellow a threshold it triggers it to derive an actionplan to increase said parameter to a desirable level. The AI is unpredictable and where it ends up depends on placed waypoints, access to food, water and shelters. The use of actions in this way proved to be quite powerfull and easy to expand. You only need to add new goals and actions to go with them and the AI will perform them when it’s suitable.

Conclusion

The project reached a point which I am quite satisfied with. The AI moves around and performs different actions based on where they are and where they have been. The foxes can help each other with excavating and building tasks but they don’t really register each other or change their behaviour based on proximity.

If I had more time I would have liked to implement different kinds of animals, like herbivores, carnivores and omnivores. Using different foodsources to match these types of animals and make them more interested in interacting with each other. Getting carnivores to use hunt actions and herbivores flee actions to create a more dynamic world, where life and death factors in.