Artificial Intelligence and Its Applications in Games

Lecture



In video games, artificial intelligence (AI) is used to generate responsive, adaptive, or intelligent behaviors, primarily in non-player characters (NPCs), similar to human-like intelligence. Artificial intelligence has been an integral part of video games since their inception in 1948, first appearing in the game Nim. AI in video games is a distinct subfield and differs from academic AI. It serves to enhance the player's gaming experience rather than machine learning or decision-making. During the golden age of arcade video games, the idea of AI opponents was largely popularized in the form of graduated difficulty levels, distinct movement patterns, and in-game events dependent on player input. Modern games often implement existing methods such as pathfinding and decision trees to guide the actions of NPCs. AI is often used in mechanisms that are not immediately visible to the user, such as data mining and procedural content generation. One of the most notorious examples of this NPC technology and gradual difficulty levels can be found in the game Mike Tyson's Punch-Out!! (1987).

Artificial intelligence (AI) is becoming an integral part of the gaming industry, helping to create more realistic, adaptive, and engaging gameplay. Here are the main aspects that will help you understand the topic: In general, game AI does not mean, as one might think and as it is sometimes portrayed, the implementation of an artificial personality corresponding to an NPC in the style of a Turing test or artificial general intelligence.

Overview

The term «game AI» is used to refer to a broad set of algorithms that also include methods from control theory, robotics, computer graphics, and computer science in general, and therefore video game AI often cannot be considered «true AI», since such methods do not necessarily contribute to computer learning or other standard criteria, but represent merely «automated computations» or a predefined and limited set of responses to a predefined and limited set of inputs.

Many representatives of industries and corporations claim that game AI has come a long way in the sense that it has revolutionized the ways in which people interact with all forms of technology, although many expert researchers are skeptical of such claims, and especially of the idea that such technologies meet the definition of «intelligence» as standardly used in the cognitive sciences. Industry representatives claim that AI has become more versatile in how we use all technological devices not only for their direct purpose, since AI allows technology to operate in multiple ways, ostensibly developing its own personalities and executing complex user instructions.

People in the field of AI argue that video game AI is not real intelligence, but merely a trendy marketing buzzword used to describe computer programs that use simple sorting and matching algorithms to create the illusion of intelligent behavior, while endowing the software with a deceptive aura of scientific or technological sophistication and progress. Because game AI for NPCs is focused on the appearance of intelligence and good gameplay within the constraints of the environment, its approach differs greatly from that of traditional AI.

History

Games have been an area of AI research from the very beginning. One of the first examples of AI is the computer game Nim, created in 1951 and published in 1952. Despite the fact that in the year of its creation, 20 years before Pong, the game was cutting-edge technology, it took the form of a relatively small box and could regularly beat even highly skilled players of this game. In 1951, using the Ferranti Mark 1 machine of the University of Manchester, Christopher Strachey wrote a program for checkers, and Dietrich Prinz wrote a program for chess. These were some of the first computer programs ever written. Arthur Samuel's checkers program, developed in the mid-1950s and early 1960s, eventually achieved sufficient skill to challenge a respected amateur. The work on checkers and chess culminated in the defeat of Garry Kasparov by the IBM Deep Blue computer in 1997. The first video games developed in the 1960s and early 1970s, such as Spacewar!, Pong, and Gotcha (1973), were games implemented with discrete logic and based solely on competition between two players, without artificial intelligence.

Games featuring a single-player mode with enemies began to appear in the 1970s. The first notable arcade games appeared in 1974: the game Speed Race by Taito (a racing video game) and the games Qwak (a duck-hunting shooter with a light gun) and Pursuit (a fighter aircraft dogfight simulator) by Atari. Two text-based computer games, Star Trek (1971) and Hunt the Wumpus (1973), also had enemies. Enemy movement was based on stored patterns. The incorporation of microprocessors would allow more computation and random elements superimposed on movement patterns.

Artificial Intelligence and Its Applications in Games

Light cycles compete for the right to be the last to keep riding in GLtron.

It was during the golden age of arcade video games that the idea of AI opponents was largely popularized thanks to the success of Space Invaders (1978), which demonstrated increasing difficulty levels, distinct movement patterns, and in-game events dependent on hash functions based on player input. Galaxian (1979) added more complex and varied enemy movements, including maneuvers by individual enemies that break out of formation. Pac-Man (1980) introduced AI patterns to maze games with the added feature of distinct personalities for each enemy. Karate Champ (1984) later introduced AI patterns to fighting games. First Queen (1988) was a tactical role-playing game in which characters could be controlled by the computer's AI, following a leader. The role-playing video game Dragon Quest IV (1990) introduced a «Tactics» system, in which the user could adjust the AI actions of non-player characters during combat. This concept was later introduced to the role-playing game genre in the game Secret of Mana (1993).

Games such as Madden Football, Earl Weaver Baseball, and Tony La Russa Baseball all based their AI on an attempt to reproduce on the computer the coaching or managerial style of a chosen celebrity. Madden, Weaver, and La Russa all did a great deal of work with these game development teams to maximize the accuracy of the games. Later sports games allowed users to «tune» the variables in the AI to create a player-defined managerial or coaching strategy.

The emergence of new game genres in the 1990s prompted the use of formal AI tools such as finite-state machines. Real-time strategy games burdened the AI with numerous objects, incomplete information, pathfinding problems, real-time decisions, and economic planning, among other things. The first games of the genre had notorious problems. For example, Herzog Zwei (1989) had almost broken pathfinding and very simple three-stage finite-state machines for controlling units, and Dune II (1992) attacked the player's base in a straight line and used numerous cheats. Later games in this genre demonstrated more sophisticated AI.

Later games used bottom-up AI methods such as emergent behavior and evaluation of player actions in games like Creatures or Black & White. Façade (an interactive story) was released in 2005 and used interactive multi-party dialogues and artificial intelligence as a core aspect of the game.

Artificial Intelligence and Its Applications in Games

A robot rushes after the ball and competes in Robocup.

Games have provided an environment for the development of artificial intelligence with potential applications beyond gameplay. Examples include Watson, a computer that plays Jeopardy!; and the RoboCup tournament, where robots are trained to play soccer.

Views

Many experts complain that the «AI» in the term game AI overstates its value, since game AI has nothing to do with intelligence and shares only a few of the goals of the academic field of AI. While «real AI» is concerned with the fields of machine learning, decision-making based on arbitrary inputs, and even the ultimate goal of strong AI that can reason, «game AI» often consists of half a dozen rules or heuristics that are enough to provide a good gaming experience. Historically, academic game AI projects have been relatively separate from commercial products, since academic approaches tended to be simple and non-scalable. Commercial game AI has developed its own set of tools that were sufficient to provide good performance in many cases.

The growing awareness among game developers of academic AI and the growing interest in computer games from the academic community are leading to the definition of what counts as AI in a game becoming less idiosyncratic. Nevertheless, substantial differences between the various fields of AI application mean that game AI can still be regarded as a distinct subfield of AI. In particular, the ability to legitimately solve some AI problems in games through cheating creates an important distinction. For example, determining the position of an invisible object from past observations can be a difficult problem when AI is applied to robotics, but in a computer game an NPC can simply look up the position in the game's scene graph. Such cheating can lead to unrealistic behavior and is therefore not always desirable. But its possibility serves to distinguish game AI and leads to new problems that need to be solved, such as when and how to cheat.

The main limitation of strong AI is its inherent depth of thought and the extreme complexity of the decision-making process. This means that although it is theoretically possible to create a «smart» AI, this problem would require significant computational power.

Usage

After receiving information about the player's actions, the AI determines its further tactics, relying on various algorithms:

  • Rule-based: a list of predefined conditions and reactions created by developers. This approach is used to control simple NPC behavior. For example, if the player approaches a dog, it begins to run away.

Artificial Intelligence and Its Applications in Games

  • Finite-state machine (FSM): one of the most popular algorithms in games. All possible situations and NPC reactions are scripted in advance. For example, in shooters, an enemy may attack when it sees the player and retreat if its health drops. This approach is used in the Battlefield, Call of Duty, and Tomb Raider series of games.
    The main drawback of FSM is the difficulty of scaling: the more scenarios there are in a game, the harder it is to account for all the options, increasing the likelihood of bugs. Artificial Intelligence and Its Applications in Games

  • Monte Carlo Tree Search (MCTS): an algorithm that uses a behavior tree, where all possible states of an NPC are described. At any moment, the AI evaluates the current situation and chooses an appropriate reaction. For example, an NPC may pursue the player, but if the player hides, the NPC will return to patrolling the streets. The behavior tree ensures stable operation and adaptability of the AI in the game. As shown in the figure below, Monte Carlo tree search consists of four steps: selection, playout, expansion, and backpropagation. It is designed to learn to play a game on its own, having only state information, and through multiple simulations the search gives us the best moves for a specific state. However, the drawback of this is that in many cases a large number of simulations is required to achieve decent performance. This implies the need for enormous computational power.Artificial Intelligence and Its Applications in Games

In computer simulations of board games

  • Computer chess
  • Computer shogi
  • Computer Go
  • Computer checkers
  • Computer Othello
  • Computer poker players
  • Akinator
  • Computer Arimaa
  • Logistello, which plays Reversi
  • Rog-O-Matic, which plays Rogue
  • Computer Scrabble players
  • A variety of board games at the Computer Olympiad
  • General game playing
  • Solved games have a computer strategy that is guaranteed to be optimal and in some cases results in a win or a draw.

In modern video games Video game bot

Game AI/heuristic algorithms are used in a wide variety of areas of a game. The most obvious is the control of any NPCs in the game, although «scripting» (a decision tree) is currently the most common means of control. These handwritten decision trees often lead to «artificial stupidity», such as repetitive behavior, loss of immersion, or abnormal behavior in situations that the developers did not anticipate.

Pathfinding, another common application of AI, is widespread in real-time strategy games. Pathfinding is a method for determining how to get an NPC from one point on the map to another, taking into account terrain, obstacles, and possibly the «fog of war». Commercial video games often use a fast and simple «grid-based pathfinding», in which the terrain is mapped onto a rigid grid of uniform squares, and a pathfinding algorithm such as A* or IDA* is applied to the grid. Instead of just a rigid grid, some games use irregular polygons and assemble a navigation mesh from the areas of the map that NPCs can walk on. As a third method, it is sometimes convenient for developers to manually select «waypoints» that NPCs should use to navigate; the cost is that such waypoints can create unnaturally looking movement. In addition, waypoints tend to perform worse than navigation meshes in complex environments. Besides static pathfinding, navigation is a subfield of game AI focused on enabling NPCs to navigate in a dynamic environment, finding a path to a goal while avoiding collisions with other entities (other NPCs, players...) or cooperating with them (group navigation). Navigation in dynamic strategy games with a large number of units, such as Age of Empires (1997) or Civilization V (2010), often works poorly; units often get in the way of other units.

Instead of improving the game AI to correctly solve a difficult problem in a virtual environment, it is often more economically advantageous to simply change the scenario, making it more manageable. If pathfinding gets stuck on a particular obstacle, the developer can simply move or remove the obstacle. In Half-Life (1998), the pathfinding algorithm sometimes could not find a reasonable way for all NPCs to dodge a thrown grenade; instead of letting the NPCs try to dodge out of the way and risk looking stupid, the developers instead programmed the NPCs to crouch and take cover in place in this situation.

Combat AI in video games

Many modern video games fall into the action, first-person shooter, or adventure category. Most games of this type have some level of combat. The ability of AI to be effective in combat is important in these genres. A common goal today is to make the AI more human-like, or at least appear to be so.

One of the most positive and effective features found in modern video game AI is the ability to hunt. Initially, AI reacted in a very black-and-white manner. If the player was in a certain area, then the AI reacted either completely offensively or completely defensively. In recent years, the idea of «hunting» has been introduced; in this «hunting» state the AI will search for realistic markers, such as sounds made by the character or footprints they may have left. These developments ultimately allow for a more complex form of play. With this feature, the player can actually consider how to approach or avoid an enemy. This feature is especially common in the stealth genre.

Another achievement in the recent development of game AI has been the development of a «survival instinct». In-game computers can recognize various objects in the environment and determine whether they are useful or harmful to their survival. Like the user, the AI can seek cover in a firefight before taking actions that would otherwise make it vulnerable, such as reloading a weapon or throwing a grenade. Markers can be set that tell it when to react in a certain way. For example, if the AI is given a command to check its health throughout the game, then additional commands can be set so that it reacts in a certain way at a certain percentage of health. If health is below a certain threshold, then the AI can be configured to run away from and avoid the player until another function is triggered. Another example would be if the AI notices that it has run out of ammunition, it will find cover and hide behind it until it reloads. Such actions make the AI more human-like. However, there is still a need for improvement in this area.

Another side effect of combat AI occurs when two AI-controlled characters encounter each other; first popularized in the game Doom by id Software, a so-called «monster infight» can break out in certain situations. Specifically, AI agents programmed to react to hostile attacks will sometimes attack each other if their comrades' attacks land too close to them. In the case of Doom, published gameplay guides even suggest using monster infighting to survive certain levels and difficulty settings.

Procedural content generation

Procedural content generation (PCG) is an artificial intelligence method for autonomously creating game content using algorithms with minimal designer involvement. PCG is commonly used to dynamically generate game features such as levels, NPC dialogues, and sounds. Developers input certain parameters to guide the algorithms in creating content for them. PCG offers numerous advantages both from a development standpoint and from a gaming-experience standpoint. Game studios can spend less money on artists and save time in production. Players are provided with a fresh, highly replayable experience, since the game generates new content every time they play. PCG allows game content to adapt in real time to the player's actions.

Procedurally generated levels

Generative algorithms (a rudimentary form of AI) have been used to create levels for decades. The famous 1980 computer game Rogue is a foundational example. Players are tasked with descending through increasingly difficult dungeon levels to obtain the Amulet of Yendor. The dungeon levels are algorithmically generated at the start of each game. The save file is deleted each time the player dies. The algorithmic generation of dungeons creates a unique gameplay experience that would otherwise not exist, since the goal of obtaining the amulet is the same every time.

Opinions on general level generation, as seen in games like Rogue, can vary. Some developers may be skeptical of the quality of generated content and want to create a world with a more «human» feel, so they will use PCG more sparingly. Consequently, they will use PCG only to generate certain components of an otherwise handcrafted level. A striking example of this is the tactical shooter Tom Clancy's Ghost Recon Wildlands by Ubisoft from 2017. The developers used a pathfinding algorithm trained on a dataset of real-world maps to create road networks that would run through the handcrafted villages in the game world. This is a sensible use of PCG, since the AI would have a large amount of real-world data to work with, and roads are simple to create. However, the AI would most likely miss the nuances and subtleties if it were tasked with creating a village where people live.

As AI becomes more advanced, developers' goals are shifting toward creating vast repositories of levels from datasets. In 2023, researchers from New York University and the University of the Witwatersrand trained a large language model to generate levels in the style of the 1981 puzzle game Sokoban. They found that the model excelled at creating levels with specifically requested characteristics, such as difficulty level or layout. However, current models, such as the one used in the study, require large datasets of levels to be effective. They concluded that, while promising, the high data cost of large language models currently outweighs the benefits for this application. Further advances in this area will likely lead to wider use in the future.

Procedurally generated music and sound

The musical accompaniment of a video game is an important expression of the emotional tone of a scene for the player. Sound effects, such as the noise of a weapon striking an enemy, help indicate the effect of the player's actions. Generating them in real time creates an immersive experience for the player, since the game is more responsive to their input. An example is the 2013 adventure game Proteus, where an algorithm dynamically adapts the music depending on the angle from which the player views the game landscape.

Recent breakthroughs in AI have led to the creation of advanced tools that are capable of creating music and sound based on changing factors with minimal developer involvement. One such example is the music generator MetaComposure. MetaComposure is an evolutionary algorithm designed to generate original musical compositions during gameplay in real time to match the current mood of the environment. The algorithm is able to assess the current mood of the game state using «mood tagging». Studies show that there is a significant positive statistical correlation between player-rated game engagement and dynamically generated musical compositions when they accurately match the player's current emotions.

The Monte Carlo tree search method

Game AI often comes down to pathfinding and finite-state machines. Pathfinding allows the AI to move from point A to point B, usually by the most direct route. Finite-state machines allow transitions between different behaviors. The Monte Carlo tree search method provides a more engaging gaming experience by creating additional obstacles for the player to overcome. MCTS consists of a tree diagram in which the AI essentially plays tic-tac-toe. Depending on the outcome, it selects a path leading to the next obstacle for the player. In complex video games, these trees can have more branches, provided that the player can come up with several strategies to overcome an obstacle.

Artificial Intelligence and Its Applications in Games

Comparison of MCTS improvements for the arcade game Mario (Vanilla MCTS — yellow line, Macro Actions — red line, Best combination — blue line). Figure reproduced from (Jacobsen et al., 2014).

It would seem that Minimax combined with Alpha-Beta pruning is sufficient to create complex game AI. But there is one serious problem that can render such methods useless. This is the problem of determining a reliable and reasonable evaluation function. Recall that in chess our evaluation function added up all the white pieces on the board and subtracted all the black ones. This resulted in high values when White had an advantage, and low values when the situation was favorable for Black. Although this function is a good baseline and definitely worth experimenting with, it is usually necessary to incorporate more complexity and subtlety to come up with a reliable evaluation function.

Simple evaluation metrics are easy to fool and exploit once the internal mechanisms become obvious. This is especially true for more complex games, such as Go. Designing an evaluation function that is complex enough to capture most of the necessary game information requires a great deal of thought and interdisciplinary knowledge in software development, mathematics, psychology, and the game at hand.

Is there not a universally applicable evaluation function that we could use for all games, no matter how simple or complex they are?

Yes, there is! And it is called randomness. With the help of randomness, we let chance be our guide to figuring out what the next best move might be.

Next, we will look at the so-called Monte Carlo tree search algorithm (MCTS), which relies heavily on randomness (the name «Monte Carlo» comes from the gambling district in Monte Carlo) as the main component for approximating values.

As the name suggests, MCTS also builds a game tree and performs computations on it to find a path to the highest possible outcome. But there is a slight difference in how this tree is built.

The Monte Carlo (MC) method is used to model and optimize complex processes in games.

The main applications of Monte Carlo:

  • Solution search algorithms: for example, MCTS (Monte Carlo Tree Search), popular in games like chess or Go.
  • Randomization of game events: simulating random processes for procedural content generation.
  • Probability analysis: predicting the outcomes of a player's or NPC's actions.

Example: in strategy games, MCTS helps NPCs develop strategies by evaluating many possible moves.

Principles of how N-grams work for text processing

N-grams are sequences of N elements (words or characters) used to analyze texts. Applications in games:

  • Text generation: creating NPC dialogues or procedurally generated narrative.
  • Processing player input: for example, in text-based role-playing games or chatbots.
  • Estimating text probability: predicting the most likely next word or phrase based on the preceding context.

Although N-grams are simple, they are often replaced by more powerful language models, such as transformers.

Use in games beyond NPCs

Academic AI can play a role in game AI, beyond the traditional concern of controlling NPC behavior. Georgios N. Yannakakis identified four potential areas of application:

  1. Modeling the game experience: determining the abilities and emotional state of the player in order to adapt the game accordingly. This may include dynamic game-difficulty balancing, which consists of adjusting the difficulty of a video game in real time based on the player's abilities. Game AI can also help determine the player's intent (for example, gesture recognition).
  2. Procedural content generation: creating elements of the game environment, such as environmental conditions, levels, and even music, in an automated way. AI methods can generate new content or interactive stories.
  3. Analysis of user behavior data: this allows game developers to study how people use the game, which parts they play most often, and what makes them stop playing, which allows developers to fine-tune gameplay or improve monetization.
  4. Alternative approaches to NPCs: these include changing the game setting to increase the believability of NPCs and researching the social, rather than individual, behavior of NPCs.

Instead of procedural generation, some researchers have used generative adversarial networks (GANs) to create new content. In 2018, researchers from Cornwall University trained a GAN on a thousand human-created levels for Doom; after training, the neural network prototype was able to design new game levels on its own. Similarly, researchers from the University of California created a GAN prototype to generate levels for Super Mario. In 2020, Nvidia demonstrated a GAN-generated clone of Pac-Man; the GAN learned to recreate the game by observing 50,000 (mostly bot-generated) playthroughs.

Non-player characters (NPCs)

Non-player characters are entities in video games that are not controlled by players but are managed by AI systems. NPCs contribute to immersion, storytelling, and game mechanics. They often serve as companions, quest-givers, merchants, and much more. Their realism has advanced significantly over the past few years thanks to improvements in AI technologies.

Narrative and gameplay roles

NPCs are essential in both narrative and open-world games. They help convey the game's story and context, which makes them key to world-building and narrative development. For example, an NPC can provide important information, offer quests, or simply populate the world to add a sense of realism to the game. In addition, their role as quest-givers or merchants makes them an integral part of the gameplay loop, giving players access to resources, missions, or services that enable further progression.

In addition, NPCs can be designed to fulfill functional roles in games, such as a merchant or providing a service to the player. These characters play a central role in facilitating game mechanics, acting as intermediaries between the player and in-game systems. Scholars say that the interaction between players and NPCs is often designed to be simple but contextually relevant, ensuring that the player receives the necessary feedback or resources for gameplay continuity.

Advances in NPC artificial intelligence

Recent advances in artificial intelligence have significantly increased the complexity and realism of NPCs. Before these advances, AI operated on pre-programmed behavior, making it predictable and repetitive. With the development of AI, NPCs have become more adaptive and capable of dynamically responding to players. Experts believe that the integration of deep learning and reinforcement learning methods has allowed NPCs to adjust their behavior in response to player actions, creating a more interactive and personalized gameplay experience.

One such development is the use of adaptive behavior models. They allow NPCs to analyze and learn from the player's decisions in real time. Such behavior makes it possible to make the gameplay much more immersive. For example, as experts in this field say, NPCs in modern video games can now respond to the player's actions with greater complexity, such as adjusting their tactics in combat or changing their dialogue based on past interactions. Using deep learning algorithms, these systems simulate human-like decision-making, thereby making NPCs seem more like real people rather than static game elements.

Another advance in the field of NPC AI is the use of natural language processing, which allows NPCs to have more realistic conversations with players. Before this, NPC dialogues were limited to a fixed set of responses. It is said that NLP has improved the fluidity of NPC conversations, allowing them to respond more contextually to the player's actions. This development has increased the depth and immersion of the player's interaction with NPCs, since players can now have more complex dialogues that affect the storyline and gameplay outcomes.

In addition, deep learning models have allowed NPCs to become more capable of predicting player behavior. Deep learning allows NPCs to process large amounts of data and adapt to player strategies, making interaction with them less predictable and more varied. This creates a more immersive experience, since NPCs can now «learn» from player behavior, which provides a greater sense of realism in the game.

Deep learning models in AI

Deep Learning is actively used to create complex AI systems. The main directions:

  • Pattern recognition: used to analyze the game world, for example, to detect objects or faces.
  • Recommender systems: adapting game content to the user's preferences.
  • Reinforcement Learning: training the AI based on interaction with the game environment.

In games, deep learning is used to create adaptive game bots, procedural content generation, and analysis of player behavior.

AI for improving LiveOps in games

LiveOps (live operations) is the management of a game's life cycle after its release. AI helps to:

  • Analyze player behavior: identifying "bottlenecks" or zones where players lose interest.
  • Maintain engagement: personalization of game events, promotions, or content.
  • Ensure security: detection of cheaters or bots.
  • Automate support: chatbots and player assistance systems.

Example: with the help of AI, it is possible to automatically launch in-game events that match the interests of a specific audience.

Challenges in NPC development

Despite all these advances in the field of NPC AI, developers still face significant challenges in designing NPCs. They need to balance realism, functionality, and player expectations. The main challenge is to ensure that NPCs enhance the gaming experience rather than interfere with gameplay. Overly realistic NPCs that behave unpredictably can frustrate players by hindering progress or breaking immersion. Conversely, NPCs that are too predictable or simplistic may fail to engage players, which reduces the overall effectiveness of the game's storytelling and mechanics.

Another factor to consider is the computational cost of implementing advanced AI for NPCs. Using these advanced AI methods requires a large amount of computational power, which can limit its use. Balancing the performance of AI-controlled NPCs with the game's overall technical constraints is critical to ensuring smooth gameplay. Experts have mentioned that developers must allocate resources efficiently to avoid overloading game systems, especially in large open-world games where numerous NPCs must interact with the player simultaneously.

Finally, creating NPCs capable of dynamically responding to a wide range of player behaviors remains a difficult task. NPCs must be able to handle both scripted interactions and unscripted scenarios in which players may behave in unexpected ways. Developing NPCs capable of adapting to such variability requires complex AI models that can account for numerous possible interactions, which can be resource-intensive and time-consuming for developers.

Cheating using artificial intelligence

Gamers always ask whether the AI cheats (probably so they can complain in the event of a loss)

Terry Lee Coleman of Computer Gaming World, 1994

In the context of artificial intelligence in video games, cheating means that the programmer gives agents actions and access to information that would be unavailable to the player in the same situation. Believing that the Atari 8-bit could not compete with a human player, Chris Crawford did not fix a bug in Eastern Front (1941) that benefited the computer-controlled Russian side. Computer Gaming World in 1994 reported that «It is well known that many AIs «cheat» (or at least «fudge») in order to be able to keep up with human players».

For example, if agents want to know whether the player is nearby, they can either be provided with complex, human-like sensors (sight, hearing, etc.), or they can cheat by simply asking the game engine about the player's location. Common variants include giving the AI higher speeds in racing games to catch up with the player, or spawning them in advantageous positions in first-person shooters. The use of cheating in AI shows the limitations of the «intelligence» achievable artificially; generally speaking, in games where strategic creativity is important, humans could easily beat the AI after a minimum of trial and error, if it were not for this advantage. Cheating is often implemented for performance reasons, where in many cases it can be considered acceptable as long as the effect is not obvious to the player. Although cheating refers only to privileges granted specifically to the AI — it does not include the non-human quickness and precision natural to a computer — the player may call a computer's inherent advantages «cheating» if they cause the agent to act differently from a human player. Sid Meier stated that he excluded multiplayer alliances in Civilization, because he found that the computer was almost as good at using them as humans, which made players think the computer was cheating. Developers say that most game AIs are fair, but they dislike it when players mistakenly complain about the AI «cheating». In addition, humans use tactics against computers that they would not use against other humans.

Examples

In the 1996 game Creatures, the user «hatches» small furry creatures and teaches them how to behave. These «Norns» can talk, feed themselves, and defend themselves against malicious creatures. This was the first popular application of machine learning in an interactive simulation. Neural networks are used by the creatures to learn what to do. The game is considered a breakthrough in artificial life research, the goal of which is to model the behavior of creatures interacting with their environment.

In the 2001 first-person shooter Halo: Combat Evolved, the player takes on the role of Master Chief, fighting various aliens on foot or in vehicles. Enemies very wisely use cover and employ suppressive fire and grenades. The squad situation affects individuals, so some enemies flee when their leader dies. Attention is paid to small details, in particular, enemies throwing grenades or team members reacting to anxiety. The underlying «behavior tree» technology has become very popular in the gaming industry since Halo 2.

The 2005 psychological horror first-person shooter F.E.A.R. makes the player characters fight a battalion of cloned super-soldiers, robots, and paranormal creatures. The AI uses a planner to generate context-sensitive behavior, a first in a popular game. This technology is still used as a benchmark by many studios. The Replicas are able to use the game environment to their advantage, for example, tipping over tables and shelves to create cover, opening doors, breaking through windows, or even noticing (and warning the rest of their comrades about) the player's flashlight. In addition, the AI is also able to perform flanking maneuvers, use suppressive fire, throw grenades to lure the player out of cover, and even play dead. Most of these actions, in particular flanking, are the result of emergent behavior.

The survival horror series STALKER (2007–) pits the player against artificial experiments, military soldiers, and mercenaries known as stalkers. The various enemies encountered (if the difficulty level is set to the highest) use combat tactics and behaviors such as healing wounded allies, giving orders, flanking the player, and using weapons with pinpoint accuracy.

The 2010 real-time strategy game StarCraft II: Wings of Liberty gives the player the ability to control one of three factions in a 1v1, 2v2, or 3v3 battle arena. The player must defeat their opponents by destroying all of their units and bases. This is achieved by creating units that effectively counter the opponent's units. Players can play against several different AI difficulty levels, ranging from very easy to Cheater 3 (insane). The AI can cheat at the Cheater 1 (vision) difficulty level, where it can see units and bases when the player in the same situation could not. Cheater 2 gives the AI additional resources, while Cheater 3 gives a huge advantage over the opponent.

Red Dead Redemption 2, released by Rockstar Games in 2018, is an example of the advanced use of AI in modern video games. The game features a highly detailed AI system that manages NPC behavior and a dynamic game world. NPCs in the game exhibit complex and varied behavior based on a wide range of factors, including their environment, interaction with the player, and time of day. This level of AI integration creates a rich, immersive experience in which characters react to players in a realistic way, contributing to the game's reputation as one of the most advanced open-world games ever created.

The 2024 browser-based sandbox game Infinite Craft uses generative AI software, including LLaMA. When two elements are combined, the AI generates a new element.

The 2024 browser game Oasis uses generative AI to simulate the video game Minecraft. Oasis is trained on millions of hours of video footage from Minecraft and predicts what the next frame of gameplay will look like using this dataset. Oasis has no object permanence, since it does not store any data.

Generative artificial intelligence in video games

Generative artificial intelligence, an AI system that can respond to prompts and create text, images, audio, and video clips, emerged in 2023 with systems such as ChatGPT and Stable Diffusion. In video games, these systems can create the potential for generating game assets infinitely, bypassing the typical limitations of human creations. However, there are concerns similar to those in other fields, in particular, the potential loss of jobs typically dedicated to creating these assets.

In January 2024, SAG-AFTRA, a US union representing actors, signed a contract with Replica Studios that would allow Replica to capture the voice acting of union actors to create AI voice systems based on their voices for use in video games, with the contract guaranteeing pay and rights protection. Although the contract was negotiated by a SAG-AFTRA committee, many members expressed criticism of the move, since they were not informed of it until it was finalized, and that the deal did not do enough to protect actors.

Advances in AI

Recent advances in AI for video games have led to more complex and adaptive behavior of non-player characters (NPCs). For example, AI systems now use sophisticated methods, such as decision trees and finite-state machines, to improve the interaction and realism of NPCs, as discussed in «Artificial Intelligence in Games». Recent advances in AI for video games have also focused on improving the dynamic and adaptive behavior of NPCs. For example, recent research has explored the use of complex neural networks to allow NPCs to learn and adapt their behavior based on player actions, improving the overall gaming experience. This approach is described in detail in the IEEE article «AI Methods for Interactive Game Systems».

Examples of using AI in Unity

Unity widely supports the use of artificial intelligence (AI) to create interactive and adaptive games. Developers can use Unity's built-in tools, third-party plugins, and custom solutions to implement AI in their projects. Here are the main directions for using AI in Unity:

1. Managing NPCs (non-player characters)

AI in Unity is often used to create NPC behavior, including movement, reactions to player actions, and interaction with the environment.

  • NavMesh: Unity's built-in navigation system, allowing NPCs to move across complex surfaces, avoid obstacles, and find optimal routes.
    • NavMeshAgent: a component that controls the character's movement across the NavMesh.
    • NavMeshObstacle: allows NPCs to take obstacles in their path into account.
  • State Machines: finite-state machines for implementing simple behavior (for example, "patrol", "attack", "flee").
    • Tools: Animator or custom C# scripts.

2. Advanced decision-making algorithms

  • Behavior Trees: used for complex hierarchical NPC behavior. For example, they can be useful for implementing strategy in an RTS or interaction with the player in an RPG.
    • Plugins: NodeCanvas, Panda BT, Behavior Designer.
  • Utility AI: an approach in which NPC behavior is determined based on evaluating the value of certain actions (for example, an NPC chooses the action with the highest "utility").

3. Content generation using AI

Unity supports procedural content generation, which makes the game more diverse:

  • Generation of levels (landscapes, buildings) using algorithms, for example, Perlin Noise or Wave Function Collapse.
  • Creation of unique dialogues or texts through the integration of language models (for example, the OpenAI or ChatGPT API).

4. Processing player data

With the help of AI, it is possible to analyze player behavior and adapt the gameplay:

  • Adaptive difficulty: changing the difficulty level in real time depending on the player's skill.
  • Recommendations: suggesting missions or items suitable for the player's current level.

5. Integration of machine learning models

Unity provides several tools for integrating AI models:

  • Unity ML-Agents (Machine Learning Agents): a framework for training agents through Reinforcement Learning.
    • Example: training a bot in racing to find optimal routes.
    • Uses Python and TensorFlow to train models.
  • Integration of third-party libraries: Unity supports APIs for working with trained models (ONNX, PyTorch, TensorFlow).
    • Example: using neural networks to recognize player gestures from a camera.

6. AI for LiveOps and analytics

AI can process data on player behavior, helping to optimize the gameplay:

  • Analytics: Unity Analytics tools or integration with AI services for data analysis.
  • Chatbots: creating bots to communicate with players in multiplayer games.
  • Anti-cheat systems: analyzing suspicious behavior and detecting cheaters.

7. AI for visual and sound effects

Unity allows AI to be used to create unique effects:

  • Shaders and visualization: generating textures or effects based on AI.
  • Audio: synthesizing sounds or adaptive music (for example, through integration with AI services such as Wwise).

Example: AI in practice

Creating a simple NPC using NavMesh:

  1. Set up a surface as a NavMesh in Unity.
  2. Add the NavMeshAgent component to the NPC.
  3. Write a C# script to control the NPC's movement:
using UnityEngine;
using UnityEngine.AI;
public class NPCController : MonoBehaviour
{
  public Transform target;
  private NavMeshAgent agent;

  void Start()
  {
   agent = GetComponent();
  }

  void Update()
  {
    if (target != null)
      {
        agent.SetDestination(target.position);
      }
   }
 } 
  1. Place a target object (for example, the player) on the scene so that the NPC follows it.

See also

  • Applications of artificial intelligence
  • Behavior selection algorithm – an algorithm that selects actions for intelligent agents.
  • Machine learning in video games – An overview of the use of machine learning in several video games.
  • Video game bot – a type of AI-based expert system
  • Simulated reality – the concept of a false version of reality.
  • Utility system – a reliable decision-making technique in video games
  • Kynapse – game AI middleware specializing in pathfinding and spatial reasoning.
  • AiLive – a set of game AI middleware
  • Artificial intelligence in architecture
  • xaitment – graphical game AI software

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Computer games developming, game-design"

Terms: Computer games developming, game-design