scieee AI-readable full text Open interactive document viewer

Comparison of Different Artificial Intelligence Techniques Applied in a Multiplayer Shooter

Largo Iglesias, Elisabet

Abstract

Lately, video games sector is experiencing an exponential growth based on the appearance of a great quantity of new multiplayer video games. In fact, this feature has turn basically into a requirement. Most video games provide a story mode in which all narrative action is performed and in which the player learns the mechanics and learn how to master the controls and a multiplayer mode, in which players carry out the playful or ludic action based on the competition and the showing of their skills. This duality may be caused by the fact that in multiplayer mode, players match up each other without the intervention of any agent controlled by an artificial intelligence. This supposes a greater challenge due to the fact that, usually, is very common to determine the patterns with which an enemy has been built after a few attempts to beat it. Once a player has discovered its behavior, the complexity of the battle is drastically reduced, and so, the fun degree. This paper constitutes the memory of the Final Project in the Game Design and Development degree and proposes a solution for this existent problem, by means of the design and implementation of machine learning techniques, specifically, reinforcement learning. With this solution, NPCs (non-playable characters) are able to learn from the player’s actions and modify its behavior to provide a better experience to the gameplay. In this project, two different types of enemies have been developed with Unreal Engine 4 for a shooter video game called Hive: Altenum Wars, which is expected to be released in a few months. On the one hand, there are the agents built up with predefined rule-based artificial intelligence techniques, specifically, behavior trees. On the other hand, analogous agents have been developed based on reinforcement learning to provide them the ability to adapt their behavior to the player’s gaming experience.

Full text

Comparison of Different Artificial Intelligence Techniques Applied in a Multiplayer Shooter Final project of video games’ design and development degree Author: Elisabet Largo Iglesias Tutor: Raúl Montoliu Colás July 3, 2017 Abstract Lately, video games sector is experiencing an exponential growth based on the appearance of a great quantity of new multiplayer video games. In fact, this feature has turn basically into a requirement. Most video games provide a story mode in which all narrative action is performed and in which the player learns the mechanics and learn how to master the controls and a multiplayer mode, in which players carry out the playful or ludic action based on the competition and the showing of their skills. This duality may be caused by the fact that in multiplayer mode, players match up each other without the intervention of any agent controlled by an artificial intelligence. This supposes a greater challenge due to the fact that, usually, is very common to determine the patterns with which an enemy has been built after a few attempts to beat it. Once a player has discovered its behavior, the complexity of the battle is drastically reduced, and so, the fun degree. This paper constitutes the memory of the Final Project in the Game Design and Development degree and proposes a solution for this existent problem, by means of the design and implementation of machine learning techniques, specifically, reinforcement learning. With this solution, NPCs (non-playable characters) are able to learn from the player’s actions and modify its behavior to provide a better experience to the gameplay. In this project, two different types of enemies have been developed with Unreal Engine 4 for a shooter video game called Hive: Altenum Wars, which is expected to be released in a few months. On the one hand, there are the agents built up with predefined rule-based artificial intelligence techniques, specifically, behavior trees. On the other hand, analogous agents have been developed based on reinforcement learning to provide them the ability to adapt their behavior to the player’s gaming experience. Keywords: Artificial Intelligence, Machine Learning, Reinforcement Learning, Q-Learning Contents IChapter 1 1Technical Proposal ........................................ 15 1.1 Introduction 15 1.2 Related subjects and justification 16 1.2.1 VJ1203, VJ1208 - Programming I, II . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.2.2 VJ1231 - Artificial intelligence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.2.3 VJ1234 - Advanced interaction techniques . . . . . . . . . . . . . . . . . . . . . 16 1.2.4 VJ1227-GameEngines ...................................... 17 1.2.5 VJ1224 - Software engineering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.2.6 VJ1215 - Algorithms and data structures . . . . . . . . . . . . . . . . . . . . . . . . 17 1.3 Tools 17 1.3.1 Programming ............................................... 17 1.3.2 Debugging, Testing and Profiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.3.3 Documents ................................................. 18 1.3.4 VersionControlSystem ....................................... 18 1.3.5 Video ...................................................... 18 1.4 Objectives 18 1.5 Project Planning 19 1.5.1 ProjectSchedule ............................................ 19 1.6 Expected Results 22 II Chapter 2 2State of art ................................................. 25 2.1 Classical Artificial Intelligence Techniques 25 2.1.1 Unreal Engine 4 Artificial Intelligence System . . . . . . . . . . . . . . . . . . . . . 27 2.2 Machine Learning Techniques 28 2.2.1 PredictiveLearning .......................................... 28 2.2.2 DescriptiveLearning ......................................... 29 2.2.3 ReinforcementLearning ...................................... 30 2.3 Video games and Machine Learning 34 2.3.1 Off-lineLearning............................................. 34 2.3.2 On-lineLearning............................................. 35 2.4 Hive: Altenum Wars 36 III Chapter 3 3Design ...................................................... 41 3.1 Speeders 41 3.1.1 ConceptDesign............................................. 41 3.1.2 BehaviorTrees............................................... 42 3.1.3 Q-Learning ................................................. 45 3.2 Dyggers 48 3.2.1 ConceptDesign............................................. 48 3.2.2 BehaviorTrees............................................... 49 3.2.3 Q-Learning ................................................. 51 IV Chapter 4 4Development .............................................. 59 4.1 Speeders 59 4.1.1 SpeedersBehaviorTree....................................... 59 4.1.2 SpeedersQ-Learning......................................... 65 4.2 Dyggers 69 4.2.1 DyggersBehaviorTree........................................ 69 4.2.2 DyggersQ-learning .......................................... 72 VChapter 5 5Results, Testing and Evaluation ........................... 77 5.1 Results Speeders 77 5.1.1 Speeders: Results Behavior Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 5.1.2 Speeders: Results Q-Learning Reward Pair Action-State . . . . . . . . . . . 77 5.1.3 Speeders: Results Q-Learning with Reward per State . . . . . . . . . . . . . . 79 5.1.4 Speeders: Results Random Agents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 5.1.5 Speeders: Results Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 5.2 Results Dyggers 81 5.2.1 Dyggers: Results Behavior Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 5.2.2 Dyggers: Results Random Agents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 5.2.3 Dyggers: Results Q-Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 5.2.4 Dyggers: Results Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 5.3 Comparison of both agents 83 5.4 Videos 83 5.5 Testing 84 5.6 Evaluation of the project 84 5.6.1 Phase1-Documentation..................................... 84 5.6.2 Phase2-Research .......................................... 84 5.6.3 Phase 3- Design of the agents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 5.6.4 Phase 4- Development of the agents . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 5.6.5 Phase5-Results ............................................. 85 VI Chapter 6 6Conclusions ................................................ 89 Bibliography ............................................... 90 List of Figures 1.1 ProjectGanttDiagram ........................................... 21 2.1 Depth-first search VS Breadth-first search . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 2.2 SARSAalgorithm................................................. 33 2.3 Q-learningalgorithm ............................................. 34 2.4 Cityconquestscreenshot ......................................... 35 2.5 BlackandWhitecapture ......................................... 36 2.6 HelloNeighbor .................................................. 36 3.1 Speederappearance............................................ 42 3.2 Speedersbehaviortree .......................................... 44 3.3 Dyggerappearance............................................. 48 3.4 Dyggersbehaviortree ........................................... 56 4.1 SpeederBTclassdiagramm ....................................... 61 4.2 Speeder finite state machine for animations . . . . . . . . . . . . . . . . . . . . . . . . . 64 4.3 SpeederMLclassdiagramm....................................... 66 4.4 Core of speeder learning process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 4.5 Dyggersclassdiagram ........................................... 69 4.6 Dyggers finite state machine for animations . . . . . . . . . . . . . . . . . . . . . . . . . 71 4.7 DyggersMLclassdiagram......................................... 73 16 Chapter 1. Technical Proposal created, because the number of players at that moment is not enough to make a team. This problem can be solved by introducing NPCs to the teams. Furthermore, when a someone plays a game for the first time, it is essential that he or she had available a suitable training mode in order to avoid the issues which happen when the matchmaking system makes unbalanced teams, that is when the algorithm selects users with different experience to play the same battle. In this cases, the most probable option is that the player could not enjoy his first experience, existing the possibility that he leaves the game and would not play it anymore. To prevent this from happening the second part of this project is proposed, the creation of enemies which could learn by themselves and be capable of modifying their actions so that the learning curve of the player could be as most satisfying as possible. 1.2 Related subjects and justification In this Section, a justification of the project is presented relative to different competences obtained during the study of specific subjects taught in the video games’ design and development degree. 1.2.1 VJ1203, VJ1208 - Programming I, II Programming is a fundamental aspect which is learned in different subjects throughout this bachelor’s degree. Programming skills such as problem solving, algorithm understanding and translation of algorithms expressed in natural languages into specific functions are taught in both subjects. As this proposal consists of designing and implementing different NPCs, programming is the core of the project, so proficiency in all these aspects is indispensable and justified with the skills acquired during the degree. Applied competences: • IB03 - Capacity to understand and domain the basic concepts of discrete maths, logic, algorithmic and computational complexity, and their application for the resolution of problems in the field of engineering. • IB04 - Basic knowledge about the use and programming of computers, operating systems, databases and computer programs with applications in the field of engineering. 1.2.2 VJ1231 - Artificial intelligence This project is oriented to program different intelligent agents, so is essential to know how artificial intelligence works and the keys and limitations of different techniques to program rule-based NPCs, such as decision trees, behavior trees, state machines, etc. to achieve the best goals in this project. Applied competences: • IR06 - Knowledge and application of basic algorithmic procedures to design solutions to problems, analyzing the suitability and complexity of the proposed algorithms. • IR15 - Knowledge and application of fundamental principles and basic techniques of intelligent systems. 1.2.3 VJ1234 - Advanced interaction techniques One of the aims of this subject was to explain different techniques of machine learning, so it has been a useful introduction to be able to go into detail in this area of artificial intelligence. This aspect is a fundamental basis of the research addressed in this paper. 1.3 Tools 17 1.2.4 VJ1227 - Game Engines Although this subject focused on the use of Unity, the principles and inner functioning of a game engine can be applied to Unreal Engine 4, as well. Auto-didactic capacity was enhanced with this subject and it is an essential generic skill which has been applied in the learning process of Unreal Engine 4, during my stay in Catness, company developer of Hive. Applied competences: •E12 - Capacity to evaluate, manage and understand game engines. •G09 - Autonomous learning. • IR07 - Knowledge, design and utilization of the most suitable data structures to problem solving. 1.2.5 VJ1224 - Software engineering At this subject, project planning has been learned together with class design techniques, use cases, activity diagrams, etc. Applied competences: •G01 - Ability to analyze and synthesize. • IR01 - Ability to design, develop, select and evaluate applications and computer systems and ensure its own reliability, security and quality. •IR02 - Ability to plan projects and computer systems in the video games scope. 1.2.6 VJ1215 - Algorithms and data structures This subject teaches different complex algorithms and data structures and provides knowledge about their performance, such as their computational cost. Applied competences: •IB01 - Capacity to solve mathematical problems that can appear in the engineering. •IB03 - To use maps and understand its implementation by means of trees. 1.3 Tools This Section lists the tools that will be used during the design and development of this application, grouped by its function. 1.3.1 Programming 1. Unreal Engine 4 This is the game engine employed to develop the video game Hive, in which the results of the agents will be tested. It allows the combination of visual scripting in blueprints and C++ scripting. This provides a wide flexibility to create complex behaviors for the agents. 2. Visual Studio It is the main integrated development environment (IDE) used to program scripts in C++. The reason to use it is that it is considered the best IDE for UE4 due to the fact that its building system is based around it. 1.3.2 Debugging, Testing and Profiling 1. Unreal Engine 4 Developer Tools Unreal Engine 4 provides several information gathering tools such as debuggers, analyzers and profilers. 18 Chapter 1. Technical Proposal 1.3.3 Documents 1. Overleaf Overleaf is an online LaTeX and Rich Text tool. 2. Google Slides It is an online application for creating and editing slide show presentations. 3. Creately This is a free online tool to make different diagrams. In this case, it has been used to create the UML diagrams. 1.3.4 Version Control System 1. Git It is a free and open source distributed version control system which handles large projects with efficiency. 2. GitHub It is the repository hosting service used to manage the project. 1.3.5 Video 1. Action! This tool captures any area of the screen. Its use its justified due to it is very intuitive and offers several options for professional screen capture. 2. Adobe Premiere Pro It is a powerful video editing application. 1.4 Objectives The main objective of this project is to compare different techniques from rule-based systems to machine learning methods to develop intelligent agents while implementing them to create NPCs which simulate a human behavior. This large objective can be broken down in the implementation of behavior trees and Q-learning, with the purpose of being compared, testing both in a shooter video game called Hive in order to determine the viability of implementing machine learning in video games. This analysis will indicate if machine learning would solve all the problems mentioned previously related to the ease of discovering the patterns in which the enemies are built around. In fact, this goal includes the creation of different NPCs capable of interacting with their environment and with other agents and the development of NPCs capable of modifying and adapting their behavior to the player skills during the gaming session which means developing an online training. Concretely, all the objectives can be listed in the following way: •Comparison of the different artificial intelligence techniques. • Implementation of artificial intelligence techniques to create NPCs which simulate a human behavior. •Creation of NPCs capable to interact with different agents and environment elements. • Development of enemies which modify their behavior to adapt to the player skills and his playing style. 1.5 Project Planning 19 1.5 Project Planning 1.5.1 Project Schedule This Section presents all the phases and its planning for the development of two intelligent agents, both including two versions, one rule-based and other with machine learning. The totality of the project can be divided into five different phases, each one containing a different set of tasks. Figure 1.1 summarizes the contents of this Section in a Gantt chart. •Phase 1 - Documentation All the project is documented in different papers, including a technical proposal, a technical memory and a presentation which contains different videos for the defense before the evaluation court. The planning of this phase is shown in Table 1.1. Table 1.1: Documentation phase - Tasks Breakdown ID Task Period Hours TPC Technical Proposal Courses 30-01-2017 to 02-02-2017 8 TP Technical Proposal 07-02-2017 to 10-02-2017 6 TM Technical Memory 20-05-2017 to 11-06-2017 40 PDV Project Defense Video 12-06-2017 2 PDP Project Defense Presentation 13-06-2017 4 Total Hours 60 •Phase 2 - Research As this project is a comparison between different artificial intelligence techniques, a thoughtful research is essential, specially, a study in machine learning methods to select the most suitable one for this project. In total, 60 hours should be spent in this research. Its breakdown is shown in Table 1.2. Table 1.2: Research phase - Tasks Breakdown ID Task Period Hours BT Behavior Trees and UE4 AI System 13-02-2017 to 18-02-2017 10 ML Machine Learning Techniques 19-02-2017 to 05-03-2017 40 MLV Machine Learning and video games 19-02-2017 to 05-03-2017 10 Total Hours 60 •Phase 3 - Design Once the appropriate method of machine learning is selected, the design of the different NPCs takes part. This phase can be divided into 3 sub-phases for each enemy to develop as shown in Table 1.3. First, the conceptual design of two agents will be carried out. Next, it is time to the design of the rule system based version and to design the proper machine learning method. •Phase 4 - Development The implementation of each of the sub-phases designed in the previous Section and a system to gather information about the game state so the agents can recognize it and a mechanism to save that information in a server. Table 1.4 shows a breakdown of the development phase. 20 Chapter 1. Technical Proposal Table 1.3: Design phase - Tasks Breakdown ID Task Period Hours CD1 Conceptual Design enemy 1 06-03-2017 to 07-03-2017 4 CD2 Conceptual Design enemy 2 07-03-2017 to 08-03-2017 4 R1 rule-based enemy 1 09-03-2017 to 11-03-2017 10 R2 rule-based enemy 2 12-03-2017 to 15-03-2017 15 ML1 Machine Learning enemy 1 19-03-2017 to 23-03-2017 15 ML2 Machine Learning enemy 2 24-03-2017 to 05-04-2017 20 Total Hours 68 Table 1.4: Development phase - Tasks Breakdown ID Task Period Hours IR1 Implementation rule-based enemy 1 06-04-2017 to 09-04-2017 15 IR2 Implementation rule-based enemy 2 10-04-2017 to 17-04-2017 25 SGS System to get game state 27-04-2017 to 29-04-2017 10 IML1 Implementation Machine Learning enemy 1 30-04-2017 to 06-05-2017 20 IML2 Implementation Machine Learning enemy 2 06-05-2017 to 13-05-2017 30 S Saving information in server 20-05-2017 to 25-05-2017 15 Total Hours 120 •Phase 5 - Testing and Results Once, the agents are developed, they will be tested in the video game Hive, which is under development for the moment. At this phase, different experiments will be performed in order to compare the results of the different techniques implemented. Table 1.5 shows the planning for this phase. Table 1.5: Results phase - Tasks Breakdown ID Task Period Hours TR1 Testing rule-based enemy 1 15-05-2017 3 TR2 Testing rule-based enemy 2 16-05-2017 3 TML1 Testing Machine Learning enemy 1 15-05-2017 to 16-05-2017 5 TML2 Testing Machine Learning enemy 2 16-05-2017 to 17-05-2017 5 RA Results analysis 18-05-2017 to 19-05-2017 5 Total Hours 21 1.5 Project Planning 21 Figure 1.1: Project Gantt Diagram 22 Chapter 1. Technical Proposal 1.6 Expected Results With this project it is expected to design and develop different NPCs to be able to contrast results between classic artificial intelligence techniques and machine learning, so that this investigation could be a reference to decide if the application of machine learning techniques would be suitable for the development of a video game. In particular, it is expected to develop a rule-based behavior tree system and machine learning techniques, with a previous deep investigation about different algorithms. II 2State of art .......................... 25 2.1 Classical Artificial Intelligence Techniques Unreal Engine 4 Artificial Intelligence System 2.2 Machine Learning Techniques Predictive Learning 2.2.1.1 Classification . . . . . . . . . . . . . . . . . . . . 29 2.2.1.2 Regression ...................... 29 Descriptive Learning 2.2.2.1 Clustering....................... 29 Reinforcement Learning 2.2.3.1 Policy ...........................31 2.2.3.2 Reward Function . . . . . . . . . . . . . . . . . . 31 2.2.3.3 Value Function . . . . . . . . . . . . . . . . . . . . 31 2.2.3.4 State Space . . . . . . . . . . . . . . . . . . . . . 32 2.2.3.5 Action Space . . . . . . . . . . . . . . . . . . . . 32 2.2.3.6 Markov Property . . . . . . . . . . . . . . . . . 33 2.2.3.7 Markov Decision Process . . . . . . . . . . . 33 2.2.3.8 SARSA.......................... 33 2.2.3.9 Q-learning .......................34 2.3 Video games and Machine Learning Off-line Learning On-line Learning 2.4 Hive: Altenum Wars Chapter 2 2. State of art John McCarthy [11], one of the fathers of artificial intelligence (AI) defines it as: "It is the science and engineering of making intelligent machines, especially intelligent computer programs." On his behalf, Millington [ AIvideo games ] specifies that intelligent machines should be able to perform the thinking tasks that humans and animals are capable of. Even so, Stuart Russell and Peter Norvig [19] defend that AI concept can be defined around four categories, shown in Table 2.1, combining the reasoning and behavior processes dimension with the fidelity to human acting and a perception of ideal rationality. Having these definitions of AI in mind, as video games developers, it has to be differentiated academic AI and game AI. The first one tries to solve a problem optimally with less emphasis on hardware and time limitations, so it is flexible in terms of performance. On the other hand, game programmers have to work with limited resources and the real goal is to simulate intelligent behavior. In addition, video games are a battlefield for academic AI, due to the fact that advancements in research might be tested there. Since the 90s, progress in AI is so immense that the leap from classical rule-based procedures to systems which can learn by themselves, has been taken. This is the point in which this project is focused, due to the fact that it deals with a comparison between techniques of both milestones for developing the decision-making of an NPC for a shooter video game. The explanation above justifies the following Sections. At first, definitions of classical AI techniques and Machine Learning techniques are provided. Secondly, state of art of ML in video games is summarized. 2.1 Classical Artificial Intelligence Techniques This division refers to systems which are mainly based on rules. It includes the majority of techniques used at this moment to develop autonomous agents for video games. Despite the existence of a wide variety of techniques, behavior trees (BT) have been selected for the development of the decision-making in this project, due to the fact that they are a very powerful, flexible and intuitive methods to create complex behaviors. 32 Chapter 2. State of art •Qπ(s,a): this is the value of taking action ain state sunder πpolicy. To define these value functions, there are two methods: Monte Carlo Method and Temporal Difference Method. • Monte Carlo Method requires experience from states, actions and rewards got by the interaction with the environment. This technique divides the experience into episodes, which will finish independently of which actions were taken. MC updates the values only when an episode is completed, getting the final reward and taking the path back from the final state to the first one. this is the reason why MC method is incremental in an episode-by-episode sense, but not in a step-by-step sense [21]. MC method is expressed as: V(st)←V(st)+α[Rt−V(st)] [8] • Temporal Difference Method is a combination of Monte Carlo ideas and dynamic programming. TD methods update estimations based in part on other learned estimates, without waiting for an outcome. The difference with the method above is that TD estimate the value functions after each step. An estimate of the final reward is calculated at each state and the state-action value updated for every step. This reflects a more realistic assignment of rewards to actions compared to MC, which updates all actions at the end directly. [21] TD method is expressed as: V(st)←V(st)+α[rt+1+γV(st+1)−V(st)] [8], where rt+1is the reward at time rt+1. In these functions, there are different parameters that are really important in the learning process: • Learning Rate α : This parameter defines the proportion of the old estimation that will be replaced with the new value. If α is 0, the agent will not learn anything, because it relies on its decisions in the old estimation, which is 0 from the start. On the contrary, values near to 1 will completely change the previous value. • Discount Factor γ : It defines what fraction of the new reward is taken into consideration for the updating. If γ is 0, the new rewards will be ignored and for values near to 1 the agent will consider the reward as equal weight as the learnt value. • Exploration Rate ε : This parameter appears in the policy and it determines the proportion of exploration and exploitation. 2.2.3.4 State Space The set of states Sconsists of all the states that can take part in the environment of the problem. In the next chapter, we will see that for a video game this can become really huge, so discretization of the state space is a key task to develop autonomous agents for video games by means of reinforcement learning. 2.2.3.5 Action Space The set of all actions Athe agent would be able to perform in the environment. 2.2 Machine Learning Techniques 33 2.2.3.6 Markov Property Previously, it has been set that in RL an agent bases its decisions in the environment’s states, so it is essential to know what kind of information should provide the state signal, which is called the Markov property. This property states that a state signal should include immediate sensations, but at the same time they should not provide everything about the environment, only the useful information to take decisions. On the other hand, the information provided by a state signal must be something that the agent could have received by its sensations. Summarizing, a signal which can be accepted by Markov property is the one which represents relevant past sensations. Markov property dictates that if an environment model has this feature, given a state and an action, is possible to predict the next state, so this is a key in reinforcement learning problems. 2.2.3.7 Markov Decision Process In 1960, Ronald A. Howard’s published the book Dynamic Programming and Markov Processes [1], where he treated the Markov decision processes. when a RL problem satisfies the Markov property, it is called Markov decision process. A Markov Decision Process is defined by the state and action sets and the dynamics of the environment. The probability of each possible next state are called transition probabilities. 2.2.3.8 SARSA This algorithm for learning a Markov decision process policy works with an action-value called Q-value, Q ( s,a ) , where sis a state and a, the best action possible for the state s. These values represent the possible reward received in the next state s’ taking the action ain the state s. The name of this algorithm summarizes itself, because it is formed by the quintuple ( s,a,r,s’,a’ ) , being rthe reward associated to the next state s’ and the best action a’ for s’. SARSA algorithm is called an on-policy learning algorithm, because the agent updates the policy π based on the interaction with the environment at the same time it calculates the Q-value. As shown in Figure 2.2, the Q-value is updated taking the learning rate α into account. This update is done after every state transition when the state is not the final state. Figure 2.2: SARSA algorithm 34 Chapter 2. State of art 2.2.3.9 Q-learning Q-learning was introduced by Watkins [21] in 1989. This algorithm differs from SARSA by not using the action-value of the next state. It uses the value of the action with the highest value and Q-learning does not wait until a second action is chosen before updating the value. Furthermore, it is an off-policy algorithm, because it works independently of π ; this means that the policy is given directly instead of obtaining by itself by means of the model parameters of a transition and reward functions. As shown in Figure 2.3 Q-learning updates the Q-value of a state-action pair after the action has been taken and an immediate reward has been received. Literature shows that Q-learning converges earlier than SARSA, because it utilizes a greedy method determining the action-value rather than selecting a random action with a certain probability [21]. Figure 2.3: Q-learning algorithm 2.3 Video games and Machine Learning After describing what machine learning is, its principles and some techniques, let’s see how ML is being done in video games today. First, ML has to be divided in two areas: off-line learning and on-line learning. 2.3.1 Off-line Learning This type of ML refers to the techniques which are applied during the design phase of the video game, to find the best behavior for the agents and, then, the results of this techniques are applied before releasing the game, by means of other traditional techniques. In this case, reinforcement learning is used during the development of several video games, specifically during the testing phase, to balance properly the enemies. Also, it is during this phase when the agents have the most information possible to learn. When the learning algorithms converge, developers find the strategies of those results, and then, hard-code them. One example of a game with off-line learning is City Conquest [20] ( Figure 2.4 ) , a real time strategy game and tower defense, developed in 2011 by Intelligence Engine Design Systems. It is defined by its developers as: "City Conquest is an epic mobile strategy game that combines innovative strategy with classic tower defense gameplay. It evolves the core tower defense concept by adding an offensive gameplay element and territorial expansion and control mechanics..." During the development phase, they used genetic optimization techniques and evolutionary algorithms for gameplay balancing and design optimization. They developed a tool named Evolver [3] that played 1-2 million missions against itself per day, to find patterns and then balance the game elements such as buildings of buildings updates. 2.3 Video games and Machine Learning 35 Figure 2.4: City conquest screenshot 2.3.2 On-line Learning In this case, learning process happens during the game session, so it adjusts itself to the player. Reinforcement learning is hardly ever used for online learning due to two main reasons: •CPU resources Usually, reinforcement learning tends to require a lot of CPU power. This issue is disappearing as technology advances so fast. •Control Reinforcement learning puts the agents out of control for the programmers and this is the most drawback of implementing RL techniques in video games since it requires a shift in the video game’s design paradigm. Game developers and players are used to agents that can not take unexpected paths, for instance, because they have not been programmed to it, but RL can break this rule. Already in 2001, Lionhead Studios released a video game with on-line learning called Black and White ( Figure 2.5 ) . It used a variety of techniques, integrating them into an impressive overall AI system. Belief–desire–intention models, rule-based systems, decision trees and neural networks. [22] The video game was a god simulator, where the player teaches the creatures how to act, by interacting with them. It was based on the concept of good and evil, so the behavior and personality of the creatures were shaped by the player. Although Belief-Desire-Intention is not a ML technique, it can be expanded to incorporate learning. The BDI technique is like a bunch of complex if-then-else sentences. In Black and White, BDI is used to determine if certain thresholds have been exceeded and thereby expressing the desire of the creature. The agent then reviews its desire and choose actions to satisfy them. Black and White used a simple feedback learning technique in order for the creature to learn which actions were the most appropriate to take. Next summer, Hello Neighbor [15] will be released (Figure 2.6). It is a first-person tactical puzzle developed by Dynamic Pixels, which is programmed with machine learning. The agent observes the player’s actions, learning where they succeed and where they make mistakes on any given level and he reacts to that information, so the more one plays, the smarter and harder the 36 Chapter 2. State of art Figure 2.5: Black and White capture enemy becomes. Figure 2.6: Hello Neighbor 2.4 Hive: Altenum Wars Hive [2] is a horizontal scroll shooter video game which is in development at the moment, by the video games studio Catness. This video game has two modes: multiplayer and survival. Regarding the first mode, an online battle of two teams takes part. Each team is formed by five players, who control different characters. Depending on the character selected, the players can choose among a wide variety of weapons and special abilities, including bombs, lasers... In the survival mode, one single player or a team fight against hordes formed by different enemies, that will appear during the game, which lasts until the player dies. The scoring consists of as more time the player survives and more hordes defeat, the more score he will achieve. One distinctive feature of this game before other video games of the same genre is the environment. The maps, settled into a futuristic atmosphere, consist of one or more interconnected hexagons divided into six sectors, each one with different gravity. This feature is a key in the 2.4 Hive: Altenum Wars 37 development of the agents. As it will be explained later, the gravity affects their movement and their axis are exchanged. III 3Design .............................. 41 3.1 Speeders Concept Design Behavior Trees 3.1.2.1 FLEE FROM THE PLAYER . . . . . . . . . . . . . 43 3.1.2.2 TOXICBITE ...................... 43 3.1.2.3 SAWJUMP ...................... 43 3.1.2.4 MOVE TO PLAYER . . . . . . . . . . . . . . . . . 45 3.1.2.5 MOVE RANDOMLY . . . . . . . . . . . . . . . . 45 Q-Learning 3.1.3.1 Action Space . . . . . . . . . . . . . . . . . . . . 45 3.1.3.2 State Space . . . . . . . . . . . . . . . . . . . . . 45 3.1.3.3 Value Function and Reward Function . 46 3.1.3.4 Policy ...........................47 3.2 Dyggers Concept Design Behavior Trees 3.2.2.1 UNDIG ......................... 49 3.2.2.2 DIG............................ 49 3.2.2.3 JUMP ATTACK . . . . . . . . . . . . . . . . . . . . 49 3.2.2.4 BREAK HUMANS ATTACK . . . . . . . . . . . . 49 3.2.2.5 TUSK ATTACK . . . . . . . . . . . . . . . . . . . . . 49 3.2.2.6 FLEE FROM PLAYER . . . . . . . . . . . . . . . . 50 3.2.2.7 MOVE RANDOMLY . . . . . . . . . . . . . . . . 50 Q-Learning 3.2.3.1 Action Space . . . . . . . . . . . . . . . . . . . . . 51 3.2.3.2 StateSpace......................51 3.2.3.3 Value function and Reward function . . 51 3.2.3.4 Policy ...........................51 Chapter 3 3. Design In this chapter, the design phase of the agents is addressed. In relation to traditional techniques, Unreal Engine 4 behavior trees have been employed, using the editor presented previously. The machine learning agents have been implemented with Q-learning, comparing two value functions Q(s,a) and (s). Furthermore, as the game in which the agents are introduced is a survival shooter with the apparition of different hordes, it has been decided that the learning process will be on-line, so each horde should be more complex than the previous ones because they will learn from them. As a premise for the development of our enemies, we need to remember that to embrace the fun processes of the player, the agents must be: •Intelligible: The AI should be easy to understand. •Interactive: All in-game actors should focus on the player •Unpredictable: Gameplay should not become repetitive. 3.1 Speeders 3.1.1 Concept Design Firstly, a basic physical and behavioral description is approached in this Section. Lately, the tasks this type of agent must perform will be introduced. Speeders are a type of futuristic spider, covered by an exoskeleton. They have three pairs of limbs, with powerful claws. These agents have the skill of jumping and its main feature is their high speed and their ability to move in groups. Once they have reached their target, part of the group tries to catch the prey. Also, the bite of these enemies is toxic, so it makes damage per time. The rest of group will jump to reach the upper parts of the victim. If the speeder reaches the target in the jump, it sticks its claws on the skin of the prey, to tear it up and cause a plentiful hemorrhage. When they attack in a group there is no hierarchy, they have no leaders or followers, all the members behave in the same way. The model and some animations have been provided by the artist of the game Hive. The physical appearance of speeders is shown in Figure 3.1. 48 Chapter 3. Design 3.2 Dyggers 3.2.1 Concept Design Regarding their physical appearance, which is shown in Figure 3.3, this type of agents is greater than the speeders, more than the double of its size. They have a heavy shield, which allows them to Figure 3.3: Dygger appearance resist the pressure under the ground. Regarding its physiognomy, two parts can be differentiated: its exterior thick shield and the weak structure covered by it. Furthermore, its head counts with its own protection, which seems to be like a helmet for them. They have three pairs of armored legs. The dygger’s tusks are the most highlighted feature of their physic. These have disproportionately dimensions, so they offer the dyggers, a lot of attack power. Furthermore, these agents can move with facility under the ground. That is the reason why when they feel threatened, they prefer to dig and protect themselves. Also, they can attack from the ground, taking advantage of the surprise factor. When they perceive the player over their position, they make a powerful attack, which consists in drilling the ground and jumping vertically to catch him. This type of enemies try to work together to destroy their victim, so when one dygger finds a human, if it is alone, it will immobilize him to make time for other diggers to arrive at that position. Despite its powerful ability to dig, their tusks can only resist rock. This means that dyggers can only dig where the floor is rocky, not when it is made of metal. Dyggers statistics are presented in Table 3.5: Table 3.5: Dyggers - Statistics Dyggers Feature Level DAMAGE From 20 to 40 AI LEVEL Advance MOVEMENT Slow SPAWN NUMBER Groups from 4 to 8 HEALTH POINTS 500 BASIC ATTACK Tusk attack ATTACK SPEED Slow 3.2 Dyggers 49 Regarding its abilities, they are summarized in Table 3.6. Dyggers have five abilities. Its basic attack is the TUSK ATTACK, it is fast and has a small cooldown. As said previously, these agents can dig and undig, but only when they are over a rocky floor, so they can not trespass metal floor. When they are underground, they are invulnerable to the player’s attacks. By this mean, they have a special ability, the JUMP ATTACK, which lets the dygger to impulse vertically from the ground to reach and hit the player. Furthermore, dyggers behavior complexity is greater than the speeders, because they try to work together and coordinate to catch the player, so if one dygger is alone and it catches the player, it will execute its BREAK HUMAN attack which will immobilize the player so other dyggers can reach and attack him. 3.2.2 Behavior Trees In this Section, the dygger’s behavior tree and tasks are presented. As it has been done previously with speeders, the basic movement and flee tasks are out of the scope of this chapter. Also, dyggers need a blackboard which updates its values constantly the same way speeders do. Each agent contains one blackboard with the following information: a reference to the player, the distance between them, a counter for the dyggers near the player, a boolean to determine if the dygger is over or under the ground, the time it has been in that mode, three booleans for the abilities availability and other three more to store the time they were executed. As in the speeders’ blackboard, these values are updated each 0.5 ± 0.1 seconds, in a service placed in the BT root. Now is time to explain all the branches of the dyggers’ BT, which is shown in Figure 10. 3.2.2.1 UNDIG This branch triggers when the dygger is already under the ground, so here, the two possibilities for the agent to execute the undig task to go over the ground are either the time has expired or the point towards it is moving is located in a metallic floor, which it can be perforated by the dygger, so it must leave the ground. With the first option, it is being referred to the fact that dyggers have a timer of 20 seconds, which means that each 20 seconds they have to change its mode from under the ground to over the ground or vice-versa. 3.2.2.2 DIG This branch is like the previous branch, but in the opposite way. If the dygger is over the ground and its time has expired, it has to dig as long as the floor is made of rock. 3.2.2.3 JUMP ATTACK Once the dygger has targeted the player and knows its position, if it is under the ground and near him (about 250 units), he will execute this attack. This task has two different effects. If at the moment of the execution of this task, the player is flying or jumping, the dygger will run under the ground to a predicted position for the player, and then jump vertically to try to hit him. If the player is on the floor, the dygger will just do its attack in that location. 3.2.2.4 BREAK HUMANS ATTACK This type of attack is performed when the dygger is outside the ground and it catches the player, when any other agent is near. As said before, this ability is about immobilizing the player, so other dyggers can run to catch him in a group. 3.2.2.5 TUSK ATTACK This is the basic attack, with no range, so it is executed when the dygger is near the player and other agents are near him, too. 50 Chapter 3. Design 3.2.2.6 FLEE FROM PLAYER When the dygger has been hurt, he must flee from the player, to avoid more damage. To do so, there is a branch with a decorator which checks its health level, followed by a sequence which consists of a task that calculates a point in the opposite direction of the player and the task moveTo that point. After reaching that point, the agent will dig to protect himself under the ground. 3.2.2.7 MOVE RANDOMLY At the moment when the agent has not detected the player, it should move randomly. Therefore, the BT contains a branch set up with a sequence with a task which gets a random point beneath a radius and the function moveTo to reach that. Summarizing, we have to implement the following nodes: •TASKS –DIG –UNDIG –JUMP ATTACK –BREAK HUMANS ATTACK –TUSCK BASIC ATTACK –MOVE TO PLAYER –FLEE FROM PLAYER –MOVE RANDOMLY •DECORATORS –IS TARGET SET? –IS UNDER THE GROUND? –IS UNDER ROCK GROUND? –IS TIMER COMPLETED? –IS NEAR DISTANCE? –IS MEDIUM DISTANCE? –ARE THERE NO DYGGERS NEAR THE PLAYER? –IS DYGGER HURT? –IS RANDOM POINT REACHED? •SERVICES –BLACKBOARD UPDATE VALUES 3.2 Dyggers 51 3.2.3 Q-Learning As it has been done for the speeders, the five elements of a reinforcement learning system have to be designed for this second agent: a policy, a reward function, a value function, states space and an actions space, but this time they will be more complex, because in this case, the agents will not get their tasks reduced, so reinforcement learning techniques in both simple and complex agents can be compared. 3.2.3.1 Action Space The unique ease this type of dygger has among the previously mentioned one is that this has a constant tracking of the player position, so it will always know where he is. As with the BT dyggers, this will have seven actions: MOVE TO PLAYER, FLEE FROM PLAYER, DIG, UNDIG, JUMP ATTACK, BREAK HUMANS ATTACK and TUSK ATTACK. 3.2.3.2 State Space As this enemy is more complex, the environment state model has to be constituted by five features: the speeder-player health proportion, the distance between them, the type of the floor where the dygger is, the mode (under or above) of the ground and the number of dyggers which are near the player. The two first features are the same as for the speeders, so the health proportion can be: dygger has health advantage, dygger and player have the same health proportion, dygger has less health than player and the player is almost dead; and the distance: the dygger is near, they are at Med. distance or the dygger is far away from the player. The last feature, number of dyggers, has been discretized due to the fact that it only matters if that is zero or different to zero, the dygger is the only enemy near the player or not. The combination of these features leads to 96 different states which can be seen in Table 3.7. This change in the environment has led to an exponential increment of the complexity of the states space, with a difference of 84 states between the two types of enemies. This fundamental rising of complexity, will let us compare both agents in terms of usability of reinforcement learning depending on the complexity of the agent. 3.2.3.3 Value function and Reward function Again, these two functions are presented together, due to the fact that the reward function depends on the value one. The reward function for the value function Q(s,a), is shown in Table 3.7. 3.2.3.4 Policy A ε -greedy policy has been used, with ε equal to 0.2, which means that 2 from 10 actions will be randomly taken, so exploration can discover better choices. Table 3.7: Dyggers - Q(s,a) STATE ACTIONS Move Flee Dig Undig Jump A. Break A. Tusk A. Near, more h., rock, over g. 0 -1 1 -1 -1 10 5 Near, more h., rock, over g. 0 -1 1 -1 -1 -1 10 Near, more h., rock, under g. 0 -1 -1 1 1 -1 -1 Near, more h., rock, under g. 0 -1 -1 1 1 -1 -1 Near, more h., metal, over g. 0 -1 -1 -1 -1 10 5 Near, more h., metal, over g. 0 -1 -1 -1 -1 -1 10 Near, more h., metal, under g. 0 -1 -1 -1 -1 -1 -1 Near, more h., metal, under g. 0 -1 -1 -1 -1 -1 -1 Continued on next page 52 Chapter 3. Design Table 3.7 – continued from previous page STATE ACTIONS Move Flee Dig Undig Jump A. Break A. Tusk A. Near, same h., rock, over g. 0 1 1 -1 -1 10 5 Near, same h., rock, over g. 0 0 1 -1 -1 -1 5 Near, same h., rock, under g. 0 -1 -1 1 1 -1 -1 Near, same h., rock, under g. 0 -1 -1 1 1 -1 -1 Near, same h., metal, over g. 0 1 -1 -1 -1 5 5 Near, same h., metal, over g. 0 0 -1 -1 -1 -1 5 Near, same h., metal, under g. 0 -1 -1 -1 -1 -1 -1 Near, same h., metal, under g. 0 -1 -1 -1 -1 -1 -1 Near, less h., rock, over g. -1 1 1 -1 -1 1 0 Near, less h., rock, over g. -1 1 1 -1 -1 -1 1 Near, less h., rock, under g. -1 1 -1 0 0 -1 -1 Near, less h., rock, under g. -1 1 -1 0 1 -1 -1 Near, less h., metal, over g. -1 1 -1 -1 -1 1 0 Near, less h., metal, over g. -1 1 -1 -1 -1 -1 1 Near, less h., metal, under g. -1 1 -1 -1 -1 -1 -1 Near, less h., metal, under g. -1 1 -1 -1 -1 -1 -1 Near, P. dead, rock, over g. 0 -1 0 -1 -1 20 50 Near, P. dead, rock, over g. 0 -1 0 -1 -1 -1 100 Near, P. dead, rock, under g. 0 -1 -1 0 20 -1 -1 Near, P. dead, rock, under g. 0 -1 -1 0 20 -1 -1 Near, P. dead, metal, over g. 0 -1 -1 -1 -1 20 50 Near, P. dead, metal, over g. 0 -1 -1 -1 -1 -1 100 Near, P. dead, metal, under g. 0 -1 -1 -1 -1 -1 -1 Near, P. dead, metal, under g. 0 -1 -1 -1 -1 -1 -1 Med., more h., rock, over g. 1 -1 0 -1 -1 5 1 Med., more h., rock, over g. 1 -1 0 -1 -1 -1 5 Med., more h., rock, under g. 1 -1 -1 0 1 -1 -1 Med., more h., rock, under g. 1 -1 -1 0 1 -1 -1 Med., more h., metal, over g. 1 -1 -1 -1 -1 5 1 Med., more h., metal, over g. 1 -1 -1 -1 -1 -1 5 Med., more h., metal, under g. 1 -1 -1 -1 -1 -1 -1 Med., more h., metal, under g. 1 -1 -1 -1 -1 -1 -1 Med., same h., rock, over g. 1 0 0 -1 -1 5 1 Med., same h., rock, over g. 1 0 0 -1 -1 -1 1 Med., same h., rock, under g. 1 0 -1 0 1 -1 -1 Med., same h., rock, under g. 1 0 -1 0 1 -1 -1 Med., same h., metal, over g. 1 0 -1 -1 -1 5 1 Med., same h., metal, over g. 1 0 -1 -1 -1 -1 1 Med., same h., metal, under g. 1 0 -1 -1 -1 -1 -1 Med., same h., metal, under g. 1 0 -1 -1 -1 -1 -1 Continued on next page 3.2 Dyggers 53 Table 3.7 – continued from previous page STATE ACTIONS Move Flee Dig Undig Jump A. Break A. Tusk A. Med., less h., rock, over g. 0 1 1 -1 -1 1 0 Med., less h., rock, over g. 0 1 1 -1 -1 -1 0 Med., less h., rock, under g. -1 1 -1 0 0 -1 -1 Med., less h., rock, under g. -1 1 -1 0 0 -1 -1 Med., less h., metal, over g. 0 1 -1 -1 -1 1 0 Med., less h., metal, over g. 0 1 -1 -1 -1 -1 0 Med., less h., metal, under g. -1 1 -1 -1 -1 -1 -1 Med., less h., metal, under g. -1 1 -1 -1 -1 -1 -1 Med., P. dead, rock, over g. 5 -1 0 -1 -1 5 1 Med., P. dead, rock, over g. 5 -1 0 -1 -1 -1 5 Med., P. dead, rock, under g. 5 -1 -1 0 1 -1 -1 Med., P. dead, rock, under g. 5 -1 -1 0 1 -1 -1 Med., P. dead, metal, over g. 1 -1 -1 -1 -1 5 1 Med., P. dead, metal, over g. 1 -1 -1 -1 -1 -1 5 Med., P. dead, metal, under g. 1 -1 -1 -1 -1 -1 -1 Med., P. dead, metal, under g. 1 -1 -1 -1 -1 -1 -1 Near, more h., rock, over g. 10 -1 1 -1 -1 0 0 Near, more h., rock, over g. 10 -1 1 -1 -1 -1 0 Near, more h., rock, under g. 10 -1 -1 1 0 -1 -1 Near, more h., rock, under g. 10 -1 -1 1 0 -1 -1 Near, more h., metal, over g. 10 -1 -1 -1 -1 0 0 Near, more h., metal, over g. 10 -1 -1 -1 -1 -1 0 Near, more h., metal, under g. 10 -1 -1 -1 -1 -1 -1 Near, more h., metal, under g. 10 -1 -1 -1 -1 -1 -1 Near, same h., rock, over g. 10 -1 1 -1 -1 0 0 Near, same h., rock, over g. 10 -1 1 -1 -1 -1 0 Near, same h., rock, under g. 10 -1 -1 1 0 -1 -1 Near, same h., rock, under g. 10 -1 -1 1 0 -1 -1 Near, same h., metal, over g. 10 -1 -1 -1 -1 0 0 Near, same h., metal, over g. 10 -1 -1 -1 -1 -1 0 Near, same h., metal, under g. 10 -1 -1 -1 -1 -1 -1 Near, same h., metal, under g. 10 -1 -1 -1 -1 -1 -1 Near, less h., rock, over g. 1 0 1 -1 -1 0 0 Near, less h., rock, over g. 1 0 1 -1 -1 -1 0 Near, less h., rock, under g. 1 0 -1 1 0 -1 -1 Near, less h., rock, under g. 1 0 -1 1 0 -1 -1 Near, less h., metal, over g. 1 0 -1 -1 -1 0 0 Near, less h., metal, over g. 1 0 -1 -1 -1 -1 0 Near, less h., metal, under g. 1 0 -1 -1 -1 -1 -1 Near, less h., metal, under g. 1 0 -1 -1 -1 -1 -1 Near, P. dead, rock, over g. 10 -1 1 -1 -1 1 1 Near, P. dead, rock, over g. 10 -1 1 -1 -1 -1 1 Continued on next page 54 Chapter 3. Design Table 3.7 – continued from previous page STATE ACTIONS Move Flee Dig Undig Jump A. Break A. Tusk A. Near, P. dead, rock, under g. 10 -1 -1 1 0 -1 -1 Near, P. dead, rock, under g. 10 -1 -1 1 0 -1 -1 Near, P. dead, metal, over g. 10 -1 -1 -1 -1 1 1 Near, P. dead, metal, over g. 10 -1 -1 -1 -1 -1 1 Near, P. dead, metal, under g. 10 -1 -1 -1 -1 -1 -1 Near, P. dead, metal, under g. 10 -1 -1 -1 -1 -1 -1 3.2 Dyggers 55 Table 3.6: Dyggers - Abilities DIG TYPE No damage skill EFFECT Invulnerability under the floor COOLDOWN 20 sec UNDIG TYPE No damage skill EFFECT To go from underground to over the floor COOLDOWN 20 sec JUMP ATTACK TYPE Vertical jump from underground IMMEDIATE DAMAGE From 30 to 50 EFFECT Positioned over the floor, next to the player COOLDOWN 20 sec BREAK HUMANS ATTACK TYPE Immobilization IMMEDIATE DAMAGE 0 EFFECT Immobilization: From 15 to 30 DPS/5 sec COOLDOWN 9 sec TUSCK BASIC ATTACK TYPE Basic attack IMMEDIATE DAMAGE From 20 to 40 EFFECT COOLDOWN 2 sec 56 Chapter 3. Design Figure 3.4: Dyggers behavior tree IV 4Development ....................... 59 4.1 Speeders Speeders Behavior Tree 4.1.1.1 Movement Dimension . . . . . . . . . . . . . 60 4.1.1.2 Decision Dimension . . . . . . . . . . . . . . . 63 Speeders Q-Learning 4.1.2.1 Main Core Function . . . . . . . . . . . . . . . 65 4.1.2.2 State Identification . . . . . . . . . . . . . . . 65 4.1.2.3 Action Selection and Performance . . . . 67 4.1.2.4 Obtaining Values and Updating Q Matrix 68 4.1.2.5 Problems ....................... 68 4.2 Dyggers Dyggers Behavior Tree 4.2.1.1 Movement Dimension . . . . . . . . . . . . . 70 4.2.1.2 Decision Dimension . . . . . . . . . . . . . . . 70 Dyggers Q-learning 4.2.2.1 Main core function . . . . . . . . . . . . . . . 72 4.2.2.2 State identification . . . . . . . . . . . . . . . 72 4.2.2.3 Action selection, performance, Obtaining values and updating Q matrix . . . . . . . . 74 4.2.2.4 Problems ........................74 Chapter 4 64 Chapter 4. Development Figure 4.2: Speeder finite state machine for animations taken into account in the planning of the project. To make this impulse, three different methods were implemented: ∗Parabolic jump A: The parabolic jump is calculated taking the distance between the actors into account. The jump angle is got with it and its arctangent. Lately, with the cosine between that angle and the distance, the impulse velocity is calculated, and can be split up in its components, Z (height) and Y (horizontal), to apply the impulse with them. This is made with the UE4 function AddImpulse which gives the agent an instantaneous force. This solution did not work properly because the gravity did interfere with the velocities and the final jump was not suitable. ∗Parabolic jump B: In this case, the gravity is employed with a parabolic function which works with the maximum time of the jump. The time of the jump in air and the falling time are calculated with the gravity and the maximum height of the jump. With them, we get the total time of the jump, which can be used with the gravity to get the velocity vector needed for the AddImpulse function. As this solution requires several calculations, another third one has been implemented. ∗ Final jump: This method gets the impulse vector with the direction vector from the speeder to the player and the up vector of the speeder multiplied by an offset that determines the strength of the jump. Despite this jump is the less realistic, it provides a suitable result and it is not resources consumer, so this has been the one method selected finally. – FLEE FROM PLAYER and MOVE RANDOMLY These functions are used together with the movement of the agents. Basically, each one returns a point either a random point, inside a radius, or a point in the opposite direction from the player to the speeder. With all the processes explained previously, the development of the speeders with behavior trees is settled. To summarize, the base class of the speeder, its controller, its BT, its blackboard and a C++ script that inherits from a class which controls the interaction between player-enemy, has been implemented for this type of agent. 4.1 Speeders 65 4.1.2 Speeders Q-Learning The class diagram for the learning speeders is shown in Figure 4.3. There, it can be appreciated that the structure of the main blueprint is similar to the one of the previous case, due to the fact that it inherits from the same C++ class Speeder, so we are not going to highlight them, because they have been explained in Section before. This blueprint has a reference to its controller blueprint (SpeederMLController), which inherits from a C++ class called SpeederML, which is the class in charge of making all the agent’s learning process. this class has direct access to another one named SpeedersSharedBrainMatrix, which collects the value and reward functions in form of matrix, so there is only one instance of them in the game, which is shared by all the agents, saving, this way, memory resources. For the development of this agent, it has been necessary to implement the interaction between blueprints and c++ scripts, due to the fact that it is precise to create the actions functions (move, attack and flee) in the class SpeederML. Furthermore, all of them have to be implemented in the son blueprint, SpeederMLController, because it is easier to implement this kind of actions via the UE4 visual blueprint editor. To do so, in the parent class, the functions should be declared as Unreal functions, specifying that they are going to be implemented in blueprints: UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Speeder_ML") void Flee() ; UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Speeder_ML") void MoveToPlayer() ; UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Speeder_ML") void ApplySaltoSierra(); The next step is to implement those functions in the blueprints as events. Once the communication between scripts and blueprints is clear, emphasize that the core of the learning process is done in the script SpeederML. In this class, the identification of the state and the action selection depending on the policy is realized. Most part of these functions access to the SpeedersSharedBrainMatrix script to get and update the values of the Q matrix. 4.1.2.1 Main Core Function All the learning process is made inside the Tick function, which is executed once per frame continuously. This learning core is shown in Figure 4.4. This function works in what can be called learning cycles. Each cycle consists in identifying the state, selecting an action depending on the followed policy which will determine if the agent has to chose a random action of the one that best results had provided up to the moment. After that, the action is performed and one timer starts depending on the action default time. After that time, the new state is identified and the Q matrix is updated with the obtained results, closing the cycle that way and starting the following one immediately. 4.1.2.2 State Identification The state is identified in this case by the combination of two enumerations: •Distance To Player –NEAR: If the distance is less or equal to 100 units. –MEDIUM: If the distance is between 101 and 400 units. –FAR: If distance is greater than 400. •Speeder Health Proportion To Player – PLAYER_ALMOST_DEAD: If the player’s health is the 10 % of its maximum health. For the next states, we need to calculate the proportions of the player’s health and the agent’s health, dividing its current health between the maximum. 66 Chapter 4. Development Figure 4.3: SpeederML class diagramm 4.1 Speeders 67 Figure 4.4: Core of speeder learning process – MORE_HEALTH_PROPORTION: The difference between the speeder’s health proportion and the player’s one is greater or equal than 0.25. – LESS_HEALTH_PROPORTION: The opposite of the previous one. The difference between the player’s health proportion and the agent’s one is greater or equal than 0.2. –SAME_HEALTH_PROPORTION: The rest of the states. It has to be remembered, that the value and reward functions have been implemented as two matrices with the same number of rows as states in the environment, and columns like actions as explained in the chapter before. Once these enumerations have been determined according to the game state, the function stateParsing is called, to convert that combination of enumerations into an integer that identifies the state row in the matrix. In this case, as the possible combinations are 12 states, it is acceptable to implement a state recognition mechanism with the combination of different switch statements. Nevertheless, this is possible only because this number is not too big, fact which occurs with the second agent and which solution will be discussed later. 4.1.2.3 Action Selection and Performance To determine the resolution of the policy, a threshold value of 0.2 has been employed, so as before determining the action, a random is performed. If this is lower than the threshold, the exploration is performed by means of the selection of a random action. Otherwise, the best learned action for the current state is selected. the function which performs this, accesses to the value Q matrix int the SpeederSharedMatrix, getting the value of the row that identifies the state. In this row, the column with the greater value is chosen, determining that way, the best action. Once the action has been selected, it is performed by triggering the events of those tasks in the SpeederML blueprint and the timer is started. 68 Chapter 4. Development 4.1.2.4 Obtaining Values and Updating Q Matrix Once the timer has finished, the Q matrix is updated depending on the last state, the selected action, the current state and the action’s reward. furthermore, to test whether the matrix was updating correctly, a writing to file mechanism has been developed to store the current time, the state, the action selected and the values of the Q matrix, which has been really useful to debug the learning process. This issue will be discussed in the testing chapter. 4.1.2.5 Problems In this Section, we are going to address all the problems that have appeared during the development of this learning system. The main drawback is caused by two features related to the game genre: real time and shooter. On the first place, aim that previous researches about reinforcement learning by experts in this area, which have been mentioned at the state of art Section were tested in games by turns, such as strategy games. In this case, Hive is a real time game, which means that both the player and the autonomous agents take decisions simultaneously and continuously. This causes a problem because decisions can overlap, so after the agents chooses an action for the current state, it does not always lead into the same state, due to the fact that in that decision period, the player has taken his own actions. for example, if the state is that they are near and the player is about to die, the most effective action for the speeder is to attack him, because it would probably kill the player, which is the desirable state. Nevertheless, in hat decision period, the player could have moved, changing the game state, so the result of the same action in a determined state will be different each time. This provokes the learning process to be slow and, also, it complicates the convergence of the value Q matrix. On the other hand, as the game is a shooter, there is a main feature that affects the learning process. This is the fact that the player can aim with the mouse to shoot to different points of the map, to destroy the speeders. In an ideal learning system, this should be taken into account so as the agent could avoid the player’s attacks. Nevertheless, checking these cases, would lead to an exponential increment of the state space, due to the fact that it should register the weapon’s type, its states (with ammunition or not and making a shoot or not) and the trajectory of the projectiles to check whether they are going to collide with the autonomous agent. To solve this issue, each time that the agent is reached by a player’s projectile, its Q value matrix is accessed at the row of the state in which the last action was taken and in the column of that action and is reduced by one unit, to decrease the probability of taking that action again in the same state. This is very useful, for instance, in the case where the actors are at medium distance so the agent alternates between the actions move towards the player, flee from him and jump (attack), which generates the feeling that it is trying to avoid the player’s attacks. The last issue to outline about the learning process is that it needs a player. As this is an online learning approach its not such problem, because it makes sense inside the technique employed. Nevertheless, if the learning was off-line, this would be a problem because it would require lots of human resources who were taking continuous games with the machine, fact that is a expense of time and financial resources. One possible solution, would be to make the agents learn by fighting with the speeders which have a behavior tree, but as the player’s actions differ from the speeders’ ones, this would not be a suitable learning. Another solution could be to implement an artificial intelligence likeness the humans with a behavior tree, but this idea has been discarded due to the fact that the project’s dimensions are too large, that it would be practically impossible to consider all the possible actions of the player. 4.2 Dyggers 69 Figure 4.5: Dyggers class diagram 4.2 Dyggers In this Section, the implementation process of the second enemy, the dygger, is described. 4.2.1 Dyggers Behavior Tree The class diagram developed for this type of agent is shown in Figure 4.5. the inheritance is very similar to the speeder’s one (Section 4.1.1), so only the two main classes will be focused: the dygger’s blueprint and its controller. The blueprint dygger is the one which forms the agent, its mesh, its movement and the implementation of its actions. Furthermore, in this class, the management of the animations is performed by a finite state machine. In this case, the actions dig, undig and the jump attack have been implemented as events, specifically, two events for each attack. The first one is the action’s start and this event is triggered from the leaf node of this task in the BT. At this moment, all the animation’s control variables are set and it is determined if the agent is under the ground or over it (function SetUnderground). As mentioned before, this event controls the start of the animations, which also call the second event when the animation’s execution has 70 Chapter 4. Development finished. At that event, all the variables are re-set, so the agent can go back to its IdleRun state (Figure 4.6). To illustrate this sequence, we are going to see a clear example. Let’s suppose that the BT determines that the dig node has to be executed. At the first moment, it checks whether the floor is rocky, because if it was the case that the floor is made of metal, the dygger could not perform the dig action and the node would return false to its selector, so the branch failed. If the raycast employed to check the floor’s material determines that it is rock, the node triggers the event OnstartDig. This event sets the proper parameters to indicate the FSM that the state is going to change from IdleRun to Dig, which would provoke the animation to start its execution. This animation is linked to the OnEndDig event, which is triggered when the animation reaches its last frame. Finally, this event re-sets that variables again and calls the controller’s SetUnderGround function to determine that now the agent in under the floor. There, the blackboard is updated and the collisions and visibility of the agent are managed, to make the dygger invulnerable under the ground. 4.2.1.1 Movement Dimension In this agent, the movement problem has been solved the same way we did in the previous enemy: the agent has a movement component controlled by a pathfinding which avoids collisions with static obstacles and the player. To make the dyggers avoid each other and not overlapping, the AI DetourCrowdController has been employed, because it manages dynamic collisions in an optimal way, so computing resources are not wasted. On the other hand, as we mentioned previously, these enemies have two mechanisms to move: above the ground and under it. The first one consists of the normal movement, but to achieve the feeling that the agent is moving under the ground a hack has been implemented. Instead of moving the agent in its vertical axis to set it under the ground and then move it by means of projections of its navigation mesh positions, its visibility, collisions and animations are modified in order to give the feeling that the dygger is moving under the ground, when it is, in fact, moving normally. 4.2.1.2 Decision Dimension Specifically, the following nodes and functions have been implemented. •DECORATORS – IS TARGET SET? It consists of accessing the blackboard to check the reference to the player. –IS UNDER THE GROUND? Access to the blackboard to check the boolean that determines whether the dygger is under or over the ground. – IS UNDER ROCK GROUND? this condition has been implemented in a node, in which a raycast is projected from the agent towards its down vector, to check if the floor which it is colliding is the type of rock or metal, accessing its tag. – IS TIMER COMPLETED? For this node, the dyggers have a timer that indicates if they have to change their movement mode. It accesses the blackboard and checks the float which stores the last time is changed from one mode to the current mode, and it is compared with the maximum allowed value. – ARE THERE NO DYGGERS NEAR THE PLAYER? In this verification, the class of all the actors which are at a distance less or equal to 400 from the player is checked, to determine the number of dyggers near the player. •TASKS Most part of the tasks require an animation, so it is essential the use of a finite state machine which controls the transitions between that states. It is shown at Figure 16. In this Section only the specific tasks of the dyggers are focused, because movement and blackboard 4.2 Dyggers 71 Figure 4.6: Dyggers finite state machine for animations updating is made the same way that in the speeders. –DIG The conditions to enter in this node are the dygger to be over the ground and its timer had expired. In this BT task, at first place, one raycast is launched from the dygger downwards to check whether the floor is rocky. If the process is satisfactory, in the blackboard, the value which stores the time under the ground is set to the current time. Lately, OnstartDig event is triggered and the animation is set. After that, OnEndDig event starts, to change again the animation and to update the blackboard boolean which stores the dygger movement state to underground, and modifies the collisions and visibility of the agent to ignore the player’s projectiles. There is another dig node in the BT with minor priority located in a branch that checks if the dygger has been hurt. If so, it will flee from the player and dig in a safer place. –UNDIG There are two reasons that will make the agent undig: to be under the ground with an expired timer or to be under the ground and its forward floor is metallic, which is impassable, so it must exit from the ground. Regarding the actions flow, it is very similar to the complementary previous action. the node triggers the event OnStartUndDig which launches the animation, and manages its collisions and visibility. –JUMP ATTACK This attack is made when the dygger is under the ground and is near the player. This 72 Chapter 4. Development attack has two different modes whether the player is over the ground or on the air. If it is on air, the dygger predicts the player’s next position based on his velocity and direction, and then, projects that point to the navigation plane to move toward it. Whenever it reaches that predicted position, it is triggered an event that controls the jumping animation and also, an impulse is added to the agent in the vertical axis. If during this attack the distance between both actors is small enough to consider they have collided, the dygger damages the player. If the player is over the ground, the dygger just jumps from below him to hurt him. – BREAK HUMANS ATTACK This task constitutes a constrictor attack, which is executed if and then the agent is located over the ground, at a near distance from the player and with no other dyggers near them. Then, it performs an attack of type constrictor which hurts the player and immobilizes him during a couple of seconds to allow other agents reach them and attack. – TUSK BASIC ATTACK Finally, the basic attack is triggered if the agent is over the ground and there are more dyggers near. As we can see, the dyggers behavior is far more complex than the speeders, because they have different cooperative strategies. 4.2.2 Dyggers Q-learning The diagram class for this agents is shown in Figure 4.7. As we can see, the structure is very similar to the speeders one. The most meaningful differences are located in the class DyggersSharedBrain- Matrix, in the reward and value functions and in the identifying state system. The class DyggerML is responsible for the learning process and it has direct access to DyggersSharedBrainMatrix to get the values of the learning matrix. Note that there is only one instance of this class, so all the dyggers share the same knowledge, which is a save in terms of space resources. 4.2.2.1 Main core function The learning algorithm is exactly the same as in the other type of agents. As said previously, this algorithm takes place in the tick function, each frame. 4.2.2.2 State identification This case, the agent has 96 states which are identified by the combination of different enumerations: •Distance To Player –NEAR: If the distance is less or equal to 100 units. –MEDIUM: If the distance is between 101 and 400 units. –FAR: If distance is greater than 400. •Speeder Health Proportion To Player – PLAYER_ALMOST_DEAD: If the player’s health is the 10 % of its maximum health. For the next states, we need to calculate the proportions of the player’s health and the agent’s health, dividing its current health between the maximum. – MORE_HEALTH_PROPORTION: The difference between the speeder’s health proportion and the player’s one is greater or equal than 0.25. 4.2 Dyggers 73 Figure 4.7: DyggersML class diagram 80 Chapter 5. Results, Testing and Evaluation Table 5.4: Speeders - results speeders Q-learning with reward per state GAME ID Killed speeders Player deaths min 1 min 2 min 3 min 4 min 5 G6 5 9 15 22 30 2 G7 8 19 24 27 32 1 G8 7 20 17 38 46 1 Avg. 6.67 16 18.66 29 36 - Increment 6.67 9.33 2.66 10.34 7 - Average Speeders/Minute 7.2 Deaths/Game 1.33 Table 5.5: Speeders - convergence for reward per state Game 6 Game 7 Game 8 Avg. M A F M A F M A F M A F 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 -0.33 0 0 -3 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 11 0 -1 43 0 -1 -1 1 -1 17.66 0.33 0 0 0 -3 0 0 -1 0 0 -1.33 0 0 118 70 91 71 71 93 48 0 63 79 47 82.33 -1 114 0 0 118 0 0 0 0 -0.33 77.33 0 -2 15 0 -1 0 29 -1 -2 18 -1.33 4.33 15.66 -8 2 0 -6 0 0 -4 0 0 -6 0.67 0 77 32 39 66 50 52 0 33 38 47.67 38.33 43 5.1.4 Speeders: Results Random Agents In Table 5.6, the results of different games with speeders which take random actions are shown. The average of kills of this agent is 8.5 per minute and the player has a probability to die around the 30% each game with a duration of 5 minutes. Table 5.6: Speeders - results random agents GAME ID Killed speeders Player deaths G9 42 0 G10 46 0 G11 39 1 Speeders/Minute 8.5 Deaths/Game 0.33 5.2 Results Dyggers 81 5.1.5 Speeders: Results Conclusion At this Section, a comparison of the results obtained with each type of speeder is presented. Regarding the average number of killed enemies per minute, the BT produced a result of 6.68 speeders per minute. The Q-learning system leads to 5.4 agents per minute. On the other side, the attempt of using Q-learning with a reward function that only had values per state, gives an average of 7.2 speeders per minute. Finally, random artificial intelligence produces an average of 8.5 killed speeders per minute. In order from the most useful method to the less one, it has been determined that: Q-learning >the behavior tree >our custom Q-learning >random agents On the other hand, regarding the times that the player had died per game: Q-learning (1.4) >custom Q-learning (1.3) >random (0.33) >Behavior tree (0.2) With these results, it can be confirmed that applying reinforcement learning via the Q-learning algorithm can be useful in video games, at least, in those where the enemies are not too complex. 5.2 Results Dyggers At this section, we will compare the results of the second enemy implemented. It must be said, that as the attempt to use a reward matrix to only states failed in the previous agent, it has not been implemented in this type of enemy. For each type of dygger, another five games of five minutes have been carried through. 5.2.1 Dyggers: Results Behavior Tree First, Table 5.7 shows the results of the implementation of a complex behavior tree. The average of killed dyggers is 2.88 per minute and also, the player dies 2 times per game. Table 5.7: Dyggers - results behavior trees GAME ID Killed dyggers Player deaths G12 15 1 G13 12 2 G14 13 3 G15 17 2 G16 15 2 Dyggers/Minute 2.88 Deaths/Game 2 5.2.2 Dyggers: Results Random Agents Random agents (Table 5.8) provide unacceptable results for a video game, as the player does not die during the game, and he can kill about 14 enemies per minute, which is a really big amount in this case. 5.2.3 Dyggers: Results Q-Learning Table 22 shows the results of applying Q-learning to the dyggers. As we can see, the average of dyggers per minute is 5.8. Furthermore, regarding to the dyggers killed at each minute, we can see 82 Chapter 5. Results, Testing and Evaluation Table 5.8: Dyggers - results random agents GAME ID Killed dyggers Player deaths G17 70 0 G18 68 0 G19 69 0 G20 70 0 G21 72 0 Dyggers/Minute 13.96 Deaths/Game 0 that despite there is an increase from the first minute to the second, from that moment to the final of the game, there is a great decrease of killed dyggers, an average of almost 7 dyggers less, which is a significant prove to show that the dyggers are learning from the players actions, because as time passes it is more difficult to the player kill them. Especial attention to passing from minute 3 to 4, in which the average indicates that not any dygger was killed in that transition, fact which is the first time to appear. Table 5.9: Dyggers - results Q-learning GAME ID Killed dyggers Player deaths min 1 min 2 min 3 min 4 min 5 G22 5 12 17 23 30 0 G23 5 11 14 23 29 0 G24 8 15 22 28 33 1 G25 3 10 12 19 23 1 G26 4 12 18 25 30 1 Avg. 5 17.13 23.6 23.6 29 - Increment 5 12.13 6.47 0 5.4 - Average Dyggers/Minute 5.8 Deaths/Game 0.6 5.2.4 Dyggers: Results Conclusions The testing process has determined that behavior trees provide an average of 2.88 dyggers per minute, nearly 14 random agents are killed each time and with Q-learning the player kills almost 6 dyggers per minute, so in this case, the order is: Behavior tree > Q-learning > random agents Despite behavior trees offer a better solution in this case, it is not arguable that the agents have learned from the interaction with the player, as they have become more resistant with time. Furthermore, there is the possibility this type of agents need more time to learn as they have complex behavior. 5.3 Comparison of both agents 83 5.3 Comparison of both agents All the results above, justify that Q-learning can be used in online learning for real time video games. In this case, it seems that it works better in simple agents, but it is essential to remark that the state space for both agents has been discretized as much as possible, instead of working with thousands of states as it is usually done in the training process. Apart from observing that the number of killed agents per minute was decreasing as the time passed, determining that the agents were learning, we have seen that one of our agents has discovered a new function for a task which was not designed for: the speeder attacks to use the jump for trying to avoid getting hit by the player’s projectiles. Another advantage that provides reinforcement learning is this type of games is that hordes are more dynamic. For example, in hordes made with 10 speeders implemented with behavior trees, as they follow the same rules, when certain states are accomplished in the game all of them decide to make the same action such as attacking simultaneously. This was partially solved, by using randoms and delays to avoid them make the animation at the same time, but they did one after other. On the contrary, this issue does not happen when employing reinforcement learning, because despite the agents use the same matrix, they have their own process of action selection following the policy, which leads to a more realistic result. Finally, despite behavior trees have a great performance regarding the number of agents destroyed per minute, they do not progress over time. From the start until the end of a game, the NPCs stay the same, so the solution to increase the difficulty of the agents in this case is to modify their attributes such as health or attack power, which can moderately complicate the game for the player. Nevertheless, this alternative does not modify the agents’ behavior unless new rules are implemented. However, machine learning provides the solution to this problem, without the need of designing and programming different behaviors. 5.4 Videos In this Section, different videos of the agents are shown. Each video is constituted by several clips that have been selected by its importance in the study. •Speeders Behavior Trees: This video is named SpeedersBT and shows a horde compound by various speeders controlled by the behavior tree. The collision avoidance and the poisonous attack, which makes the player’s health decrease during a couple of seconds can be observed during the fist part of the clip. Also, the simultaneity issue is shown. •Speeders Q-learning Reward per pair action-state: SpeedersRL_RperActionState shows Q-learning working with the reward matrix per pairs action-state. During the first seconds, the agent is exploring random actions: It goes back and forth to the player, it stays near the player without attacking, etc. In minute 0:34, the agent tries to attack the player for the first time and, after that, it tries to reach the player and attack him another time. Even, it kills the player at minute 1:07. Once the player starts to shoot the agent more precisely, it discovers that the jump of the attack can be useful to avoid getting hit by the projectiles (minute 2:22). At the last part of the video, some speeders are put together and it can be seen that the horde is more dynamic than the one controlled by BT, because each agent takes the most suitable action for its state. •Dyggers Behavior Trees: This clip is named DyggersBT shows the ferocity of this type of agents, as they make the player to be continually jumping to avoid their attacks and shooting them when they are over the ground. •Dyggers Q-learning Reward per pair action-state: The last video DyggersRL shows the same agent implemented with reinforcement learning. It can be seen that the learning process is slower than for the speeders, as they have more states. After trying different options, the 84 Chapter 5. Results, Testing and Evaluation first thing it learns is to cover itself by digging. This can be observed by the fact that after dying several times during 2 minutes, the first thing the dygger does when respawning, is digging, so it can avoid getting killed by the player. Nevertheless, it needs a lot more time to learn to attack from underground. At the last part of the video, some dyggers are put together with the player and it can be seen that they are not as difficult to beat as the dyggers controlled by a behavior tree. Probably, because they have not achieved the convergence for their value function in only five minutes. 5.5 Testing The testing has been a great part of the project, as it has been an iterative process until their behavior was completely satisfactory. This has been an arduous task due to the fact that the game Hive is still under development, so it has been subjected to several modifications which directly have an impact on the proper functioning of the agents, which have caused several bugs that had to been solved. Once this was achieved, the second testing process was carried out to get the results of the different agents. This has been a really tedious process, as several games have been performed, and on top of that, much more games should have been played in order to get more realistic results and results from different people are needed, but this has not been possible due to the nature of the project. Despite having only five samples of each agent, as we have shown previously it has been possible to extract some conclusions. Also, for Q-learning agents, a testing method has been implemented by means of storing the value Q matrix in a file, which has been really useful to analyze the learning process. 5.6 Evaluation of the project In this chapter, the development process of the final project of the degree in video games’ design and development is exposed. To clarify that, an overview task to task from the planning section in the first chapter is going to be detailed, to contrast if all of the tasks have been accomplished. 5.6.1 Phase 1 - Documentation This phase consists of all the tasks needed to document the research done in this paper. •TPC At the Technical Proposal Courses, which took place in the last week of January, the structure of that article was presented. Also, different tips for how to approach the project were provided. •TP During the week after the assistance to that courses, the technical proposal was elaborated. The motivation of the selected theme was that I wanted to do a research in a currently open issue as machine learning in video games, because it was a greater challenge to try to implement online learning in a real time game, which has not been exploited in the industry than simply making another video game. •TM The task related with the elaboration of this paper, has taken the month of June. To remark that this process duration has exceeded the estimated time in twenty more hours. •PDV and PDP The project defense videos and presentation have been realized together, the las week of June. 5.6.2 Phase 2 - Research As said previously, one of the largest processes has been the research, due to my lack of experience in the field, also the planning for this task has been suitable, because it has needed around the predicted 60 hours. The results of this phase have been exposed in the second chapter of this paper, state of art and it consists of different tasks: 5.6 Evaluation of the project 85 •BT Despite having theoretical knowledge in behavior trees, as they were part of the set of themes in the artificial intelligence subject, I had not the chance to implement them before, so I needed to document about them. Also, as this project has been developed in Unreal Engine 4, a game engine which I had never used before an underlying learning process about this tool has been done in a short period of time. This process has been shown in Section 2.1. •ML The most part of the research has treated machine learning, specifically, reinforcement learning, due to the fact that this was a completely new area for me. •MLV The last part of the process was to investigate how video games deal with machine learning nowadays. For my astonishment, there are only a few video games which make use of learning techniques and if they do, the most part is for offline training. This matter magnified my interest in investigating if online learning can be useful to games. 5.6.3 Phase 3- Design of the agents Once the different techniques to implement selected, it was time to design how to implement them in the agents. This issue is shown in chapter three, design. The process was divided into three subtasks for each type of enemy. The followed steps have been to decide the desirable behavior (CD1) for the first enemy, the speeder, and then design it with behavior trees (R1) and implement it. When the result was acceptable, it was turn to design the Q-learning (ML1) one and implement it. At the same time, improvements in the design of the behavior took place. After I was satisfied with the result of both agents I repeated the same process for the second enemy, the dygger. This time, the Q-learning design process (ML2) was easier, because I based it on the work I had previously done, but the conceptual design (CD2) and the design of the behavior tree needed more time, due to the wanted complexity searched for the behavior. As we can see, the order of this phase has differed from the planning, but in this way, we have taken benefit from time, because as we waited to have one complete enemy in all its forms, before designing the second one, a lot of problems have been avoided, because of the experience. This can be proved because the process took less than the estimated time, between 15 to 20 hours less. 5.6.4 Phase 4- Development of the agents Just like it has said previously, this process has supposed a great effort, due to my inexperience with Unreal Engine 4. As this engine is far more complex than the one I had used before (Unity) at the same time I was implementing the agents, I was getting over a heavy learning curve of the tool in a very short time, because I could not delay the development of the agents. Also, a programming language that I had not too much experience with was used. Both reasons made that the implementation of the autonomous agents have taken about 40 hours more than I had predicted. Another drawback was that I had to familiarize with a large project such as Hive. All the tasks have been thoroughly explained in Section 4. As we said in Section before, their order has been different from the planning one. The actual order has been: development of behavior trees for speeders (IR1), implementation of the learning one (IML1) at the same time with the system to get the game state for it (SGS, which had resulted different for both enemies), implementation of BT for dyggers (IR2) and implementation of the learning dyggers (IML2) and its state identifying system (SGS). In the planning for this phase, which is shown in Table 4, another task was proposed: saving the learned information in a server (S). It has not been possible to achieve this task, because I needed to master network processes and I run out of time to learn it. Nevertheless, I have it prepared for future work, by saving the value matrix in a file, which could then be uploaded to the server. 5.6.5 Phase 5- Results All the tasks related to the testing and results phase have been explained previously in this chapter. VI 6Conclusions ......................... 89 Bibliography ........................ 90 Chapter 6 6. Conclusions This paper presented the comparison between the artificial intelligence behavior trees technique and Q-learning. This project not only included a deep research on the techniques and a comparison of them by means of related works, but it also covered the design and implementation of two different agents employing both techniques, extracting results and comparing them. All of this, made under a tight time schedule around about 300 hours. First, we presented the Technical Proposal which described the work meticulously task by task to be done during this project. As we have seen in the chapter before all those tasks have been accomplished except the server storing mechanism. Also, objectives were described, so let’s check if they have been achieved: •Comparison the different artificial intelligence techniques. In chapter 5, results and comparison between behavior trees and Q-learning are shown. •Implementation of artificial intelligence techniques to create NPCs which simulate a human behavior. This consists in a really ambitious and abstract objective, but if we consider that human behavior is not predictable by simple patterns as traditional AI is, we can aim that our learning agents accomplish at least in part, this objective. •Creation NPCs capable of interacting with different agents and environment elements. Both agents interact with the environment and other agents, for instance, they interact with the player by attacking him, they also are capable of avoiding each other to avoid collisions between them and between static objects, dyggers can detect the floor in which they are over, to decide whether they can dig or not, etc. •Development enemies which modify their behavior to adapt to the player skills and his playing style. This objective was related to the implementation of machine learning techniques, so this has been properly accomplished with the Q-learning as we have analyzed their value functions to determine the strategies that the agents had learned. With all of this, we can conclude that the objectives of the project have been successfully accomplished.