visit
Let’s take a look at games we all know. A good example here would be chess and Go. This type of game can use artificial intelligence based on neural networks. Since the primary goal of AI is to defeat the player at all costs, it does not need to imitate human behavior. The actions of such an AI often look incomprehensible and sometimes even frighteningly unnatural. Even now, a human cannot defeat AI (AlphaZero) in the same chess and Go.
These are games, the main cycle of which is the confrontation of players or teams with each other (player versus player). One might wonder what the role artificial intelligence is in this scenario? But there are several areas where AI is used in such games:
Bots for beginners
They are used both in the initial training and as opponents in the game's early stages. If there is no matchmaker according to the player's skills or when it is impossible to balance the teams, bots allow you to increase the level of difficulty for the players smoothly. And eliminate frequent losses against players with much better skills. Bot training modes in World of Tanks and Hearthstone are good examples.
Launching a project or opening new game regions
PUBG Mobile used such a trick at launch. When it was impossible to assemble teams of 100 people, bots threw themselves into battle. Battlefield 2042's 128-player mode uses bots with up to 64 opponents. When the server covers a large territory with different time zones, bots can smooth out the online drawdown for remote regions. For example, when one server covers Europe and Asia.
Training mode
It is often needed in games that have been released for a long time and in which there are a lot of pro players, which are challenging to play against without good preparation. In addition, such games do not always separate beginners and pros in a matchmaker, and playing with bots become almost the only way to gain a skill. A good example here would be Escape from Tarkov. While playing with bots, you will not be able to complete missions, but at the same time, you will not lose your equipment, learn the level, and practice equipment combinations and shooting skills.
In the main cycle for these games, the player's interaction is with the environment and AI (player versus environment). These can be both purely single-player offline games (Witcher 3) and online PVE (Genshin Impact), as well as special events and modes in PVP games (Mirny-13 for Halloween in World of Tanks). In such games, AI does not have the goal of defeating the player at any cost. Even vice versa. One excellent game designer said: "The main goal of AI is to give up beautifully." So that a human player can get positive emotions from victory, in this case, AI is one of the elements of setting the complexity of the game.
In addition to gameplay, artificial intelligence aids in game development in several areas:
Level design and testing - For example, bots can walk or drive across the entire level and thereby reveal impassable areas, jams, and other nuances in the design of the level geometry.
Level balance testing - If you fight bots against each other, then by collecting statistics, you can understand how good the new level balance changes are. An essential condition for such a test is the skill of bots. To get the most relevant statistics, bots should play at the level of the average player. The absence of the need for a large team of level testers dramatically speeds up the balance polishing process.
Testing new items and skills - The developer can use Bots as test opponents when creating new equipment, items, etc., in the game. For example, you can add bots to the map when introducing a new rifle and check how well it performs its task.
Functional and load testing - AI helps to test different game components and even test itself 😀. For example, you can create a scenario in which a bot from each type of weapon will shoot at all types of surfaces and collect statistics on which surface, how it breaks through, and whether the damage is done to the enemy behind the surface. You can load test the client. Send bots to walk around the map and see if there are FPS drops or even the whole game. And for the server, you can perform load testing and thereby check how the server will behave during an “unexpected” peak load.
AI works in a cycle: Sense >> Think >> Act to achieve its goals. Whenever new information about the environment appears, it is impossible to make a decision, or the execution of the action is completed/interrupted, AI enters a new round of the Sense >> Think >> Act cycle.
Let's look at each of the major steps in the AI action cycle.
Collection of information (Sense)
First step. AI (agent or bot) collects information about the environment to make any decision. For example, it can be information about opponents and allies. Their positions, condition, equipment, etc.
Decision making (Think)
The next step is the most complex and resource-intensive part of AI. Since all the information collected by the AI agent is processed and analyzed at this stage. Depending on the elective decision-making principle, the complexity of calculations and the accuracy of the result will increase. Consider the main approaches to decision-making:
Decision Trees - Jokingly, you can call it "if" driven development. The easiest way to build AI is as it creates many "if-then" checks. It can also be called a method that instantly reacts to external events. From such checks, a tree is created through the nodes that the AI agent passes until it finds a node in which there will be an action. Usually, the information gathering and analysis steps are combined into one block and are usually an "if" test condition. In this approach, if the check result is "False," then both the transition to the next check and the execution of the action are possible.
Finite state machine - A case when the AI agent is in one of the possible states and has information on which of the states it can go. For example, the bot was in a patrol state. He can go into the state of enemy attack or retreat from this state. The choice of which state to go to may depend on how many hit points the bot has and the ratio of allies/enemies within a radius of X meters. The number of states and transition conditions is not limited. In each new state update cycle, usually every frame (sometimes, to optimize resource consumption, the transition conditions are recalculated less often), the transition conditions for each state are checked. And if the conditions are met, the transition is activated. The advantage of this approach is that we have a clear state transition logic.
Utility System - A system is based on assessing the usefulness of a particular action or transition. The logic is that the AI agent has a set of actions. He chooses which one to perform depending on the current situation on the battlefield, on the inherent priority coefficients for performing an action or transition from one state to another. For example, a bot met the enemy while patrolling the area. It will be more important for this bot not to attack the enemy but to hide, raise the alarm, and call for help from other bots. In this case, his coefficient for avoiding a direct collision will be higher than the desire to attack the enemy. And if the bot does not have a critical advantage over the enemy, it will not choose the behavior branch associated with the attack.
Behavior Trees - It is a convenient add-on for state machines. It allows you to take out state management for the state machines themselves. Thus, we can create a tree of conditions by which we will switch state machines for the AI agent.
Goal-Oriented Behavior - It is a concept that allows bots to play, focusing on the most appropriate role and goal for the AI agent and, depending on this, choosing which Behavior Tree to work on. That Behavior Tree determines the conditions for the transition of the bot to different states and the execution of actions.
Action (Act) - Final step. It is the implementation of the task. Usually, this includes finding a path and moving along the path, implementing shooting, taking cover, etc.
Collection of information (Sense) - n this part of the cycle, the AI programmer is responsible for collecting and storing information about the situation on the battlefield. Together with the game designer, the developer determines what information is collected, how often it is updated, and how it is distributed between AI agents of the same team in the case of a team game.
The other layer tells you how well the area is hidden from detection, which allows you to understand if those bushes are good for a recon tank or not. The other layer is the NavMesh, which allows the bots to move around the map. It is only part of the data created in advance, and in addition to that, we also can do pre-calculations. For example, we can store not only a map of shelters but also against which directions they protect.
Decision making (Think) - The developer usually does not implement the logic of the bot behavior on his own. He does this together with the game designer.
Action (Act) - In this part, the developer implements mechanisms that allow the AI agent to execute instructions after making a decision. Implementing modules responsible for navigation (for example, adapting A * to the game's features), shooting, etc. For example, you can take the A * algorithm and use it in your product. But most often, you will have additional conditions, such as cliffs. If not optimized, then the path for a heavy unit can be built too close to the cliff, leading to its fall. In this case, it is necessary to introduce additional coefficients for approaching a cliff or other inconvenient type of terrain and implement a smooth smoothing of the route. Otherwise, the bots will walk the "ladder." This area is very close to the gameplay, as it uses its mechanics to complete the tasks.
Tools The AI developer, in addition to the implementation of the cycle (Sense >> Think >> Act), creates tools for himself, the game designer, and QA. Sometimes, to implement a particular mechanic, it is easier to create a tool with which you can configure and use the functionality and only then proceed directly to implementing the task itself. A game designer needs to be able to analyze the logic and sequence of AI decisions. For these purposes, we at World of Tanks have created tools that allow you to record all the actions of bots in battle and then create replays that visualize the steps of bots, the sequence of decisions made, and the data based on which these decisions were made.
Let's use a real example from World of Tanks to look at the complete cycle of creating new functionality using AI. We will also be able to observe how a programmer, game designer, and QA interact with each other.
First, love the games! Seriously, if you don't love games, why even do it?
Second - it's essential to play your product a lot because only by putting yourself in the player's shoes will you understand how he plays and how bots should play.
Otherwise, you'll be "coding" the tasks of a game designer, and you won't be able to become an AI developer that way. Last is the desire to understand why something works this way or that way. AI for complex games doesn't use clear logic, and the result of the Sense >> Think >> Act cycle won't always be 100% predictable and understandable. It's not rare that the developer, together with the game designer and QA must analyze the data on the decisions made by bots to understand whether the AI acted correctly or not. And there's no need for Hard Skills and Soft Skills.
Hard Skills (this is a set of technical knowledge). And the first on the list is knowledge of scripting programming languages, usually written gameplay game logic. For example, in World of Tanks, it is Python, and for Unity, it will be C#. The second essential item will be C++. Without it, it won't be easy because most optimizations are made on it.
Soft Skills (skills that allow you to work in a team and engage in constructive dialogue). There are quite a few valuable Soft Skills, but in AI development, I would like to single out one:
Teamwork!