This article relates to work performed within lectures and lab sessions of an AI module as part of the Games Technology undergraduate course at Coventry University (2016/2017).
This week’s lab tasks consisted of making diagrams for both a decision tree and a state machine. Both of these are methods of creating algorithms for AI behaviour.
Decision Tree
As covered in the Duel Links article, a decision tree, in it’s simplest form, works by giving a balanced, binary hierarchy of decisions for the AI to follow. For example, can the AI see the player might be at the top and it either can or can’t see them. If it can, it should only then be able to perform actions regarding interaction with the player, such as moving to their position. As conditions increase and there are more data variables fed to the AI, this may not necessarily be the case, offering more than 2 options at any stage. In this post on GameDev.net, there are examples of three choices at the first level and of also unbalanced hierarchy, meaning that they don’t have to follow this perfectly.
So let’s take this knowledge and create a decision tree for an AI trying to attack the player:

Creating a tree like this requires the AI to be able to process information passed to it. Therefore, data should be established and updated either globally or individually to the AI entity. In order to see the player, the AI needs to know their position and have a way off detecting what’s in front it i.e. raycasting and then have a field of vision variable to determine if it’s viable for the AI to see (can’t see if it’s a human as no eyes in the back of the head). It will also need to know the player’s current health by passing that variable when called and then have the ability to call orders for trying to attack the player, as well as suitable animations, should the AI have more health (check by if statement) or flee if it has less. It should also be able to self assess it’s own health to determine if it needs to heal itself in the process.
Finite State Machine
A Finite State Machine (FSM) is a different way of creating AI logic, making them in a permanent ‘state’ when a certain action or requirement is fulfilled. For example, if the enemy can see the player, they should always be in a state of trying to attack the player. If there is nothing out of the ordinary, it should be in a calm state. These states can be moved through if conditions are met and then switch back if the condition is not met anymore or another takes its place. Visualisation of this kind of behaviour involves circles to represent the states and arrows to represent transitions. It can also be considered as a hierarchy as there should always be a state that the FSM should revert to. Below is an example FSM:

This basic FSM can switch between each of it’s different states based on whether a single condition is met, such as the player is in sight or there was a sound somewhere. Much like the decision tree example, it requires knowledge about the world and the player entity within it to determine it’s results. Are sounds played nearby? Is the player in sight? Are they captured? In these cases, a location for the sound origin, a boolean for present sound, captured/killed state and line of sight and the ability to raycast for line of sight.
Both of these diagrams can easily be expanded upon, with further depth in determining what should be done through each design’s conditioning. For the Decision tree, making questions like “How far away is the player?” when the AI has decided to attack could determine if they need to use a shorter range weapon or a longer one. For the FSM, it could be expanded into a hierarchical state machine (HSM), adding a layer above rest of the system, each with it’s own constraints. By expanding though, their limitations need to be considered. A decision tree works fine in smaller scale operations and with binary choices instead of multiple choice. The FSM can become very large very quickly and makes for a large, sprawling system. A game that requires a vast amount of unpredictable actions makes this a good choice but this also means that there has to eventually be a good balance between behaviour and unpredictability.