According to Wikipedia, artificial intelligence is a multidisciplinary area which, through sciences such as computing, mathematics, logic and philosophy, studies the creation and design of systems capable of solving daily problems by themselves using as their paradigm human intelligence. So what artificial intelligence pretends is, using a code fragment, get an informatics element to interact the same way a human being would. We are going to explain one which is very easy to understand and, also, very easy to explain, which is the states machine, also called FSM due to its English initials, Finite State Machine. Finite State Machine. A states machine can be represented through a graphic. The first thing we have to do is define the states our AI is going to have. Remember we are making a FPS, so we are creating an enemy which will move through the scene and attack us. The states we are going to introduce are, the first one, which is idle, is the one we will usually begin with. But first we will list the states, first Idle. The next state we are going to create is the Attack state. The next one is the one in which the AI sees the enemy, it can attack, but it's not close enough, so it's going to get closer. This one is called Approaching. The next state I'm going to define is the one where AI can't see the enemy, so it's going to patrol the scene. Patrol state. Now I'm giving you a while so that you think about a couple of states more which, commonly, the students which don't have any knowledge on this kind of AI usually forget and which are very important. In a few seconds I'm going to tell you which are the ones missing, but apart from them we could add infinite states. The more complex our states machine is, the more "intelligent" our enemy will be. So you have a few seconds to think about the states. The typical states students usually forget, which are very important, are the following. The first one is Hit, the second one is Dead. That is, when they're hit and when they're dead. Obviously, we all know the enemy is going to die but no one takes into account what they must do in these states or they don't usually take them into account. So they are two states we are obviously going to keep. And I'm going to put some more, which will be the totally temporary state, which is the respawn state. So when our enemy dies it is going to be reborn. As I said, the states machine is represented again by a graph. A graph is a set of balls, basically, and some lines which put those nodes together. So these balls are states, nodes are states. So we are going to start setting the idle state. I'm going to put a ball. I'm going to put the attack state, the approaching state, the patrol state, and then the hit, dead and respawn states. Now all the states are represented. Now, what we have to do is joining these states together according to the requirements. To do so we will use some edges and represent each of these states. We will swap from idle state to attack state if the enemy sees the player and he's close. Right? We will swap from attack to idle if he doesn't see the player. The exclamation mark here denies this factor. If he doesn't see the player. We will go from attack to approaching if he sees the player but he's not close enough. We will go from idle to approaching if he sees the player but he's not close enough. We will go from approaching to attack if he sees the player and he's close enough. But there's something we didn't take into account, which is that we will stay in attack state while he sees the player close. OK? And we will stay in the approaching state if he sees the player but he's not close enough. We will go from approaching state to the state from approaching when I see the player. He sees the player. OK, the idle state, as you can see now, we are using it as a common point. Obviously we could directly go from approaching to patrol, however, it's easier to put it this way to avoid having so many lines inside the scene or so many conditions inside my draft. So what we are going to do is use the idle as a common point. And it's going to be the only frame. If we want to swap from approaching to patrol, through idle, we will see a frame of the game. A game frame, if the game has 30 frames per second, means that it's 1/30 second. 0.033 seconds. Almost nothing in a game. Obviously, we don't care about losing this amount of time inside the game, because, in fact, we will have to make enemies more stupid, because if we make them too intelligent it becomes too complicate. We will go from idle to patrol if he doesn't see the player. And we will go from patrol to idle if he sees player. And we will stay on patrol again if he doesn't see the player. We will get to the extremes of Hit and Dead by an external condition in our AI, which is that someone hurt us. We have been shot and wounded. We will be Dead if our HP are less than zero, after we have been shot, and we will be Hit if our HP, after being shot, is bigger than zero. So we will stay Hit as long as the end of the animation doesn't arrive, as long as it isn't over. As long as "No animation end". And we will stay Dead. "No animation end". We will go from Hit to Idle when the animation is over. Animation end. And we will go from Dead to Respawn when the animation is over. In Respawn we will place the enemy in the scene's new position, bring him back to life and once all this is done, we will swap to an Idle state in the second frame. Then, again, Respawn state will be the only frame. Only one frame or, if we want to do an animation or something, we can do it in many frames. So this would be an example of a states machine and an artificial intelligence for our enemy, when we want to apply it to our game. Well, we are going to implement what we've just seen in the graph, inside our game.