AI For Games Notes
AI For Games Notes
1) Introduction to AI in games -
https://blog.ipleaders.in/ai-in-gaming-all-you-need-to-know/
Introduction
What's Al in gaming
AI refers to the integration of artificial intelligence into the videotape game. This
primarily refers to the control of non-playing characters ( NPCs). These characters
interact with players more realistically and actively, adding to the absorption of the
game. This enhances the gameplay.
Al is also being used in game design to produce more dynamic and intriguing
situations and content. This can help inventors produce more varied and absorbing
games with less trouble. For illustration, AI might be used to design game situations
that are procedurally generated, meaning that they're created on the cover as the
player progresses through the game. This can help keep the game fresh and
intriguing for players, as they aren't simply playing through the same situations over
and over again. This makes the game more gruelling and satisfying for players, as
they feel they are playing against a good opponent.
Types of Al in gaming
Benefits of Al in gaming
1) Realistic non-player characteristics: NPCs or non-player characters, are the
characters in the game who act intelligently as if they were controlled by human
players. These characters' behaviour is determined by AI algorithms and that
adds depth & complexity to the game, making it more immersive for the players.
2) Enhanced player experience: NPCs can completely interact with the player and
make the game more real to play. Some of these characters can also make it
delicate to pass a certain level as they work on their programming so if they are
programmed to make a level feel hard to pass, it gets difficult for the player.
3) Intelligent game balancing & testing :
a)AI can be used to balance multiplayer games, ensuring fair & enjoyable
experiences for all players. Al-powered testing can simulate hundreds of
gameplay scenarios, uncovering hidden bugs & optimising game mechanics
more efficiently. AI algorithms can be employed for matchmaking to create
balanced teams or opponents based on players' skill levels and preferences.
b)Game Al can figure out the ability and emotional state of the player, and then
tailor the game according to that. This could even involve dynamic game
difficulty balancing, in which the difficulty of the game is adjusted in real-
time, depending on the player's ability. AI in gaming could even assist in
figuring out the player's next move intent.
4) Innovative and creative ideas: AI can also be used to get some out of the box
ideas for games. It is a great tool to find fresh ideas, as the games can quickly get
repetitive. The companies need to have newer ideas for the games to flourish.
5) Game stage design: AI can also be used to make better levels designed for the
game to be more playable and more enjoyable for the players. The stages can be
designed with increasing challenging levels to make them more enthralling. It has
to be challenging yet not frustrating. It is truly a great tool for designers who
have to constantly think of game design.
6) Player monitoring and well-being:
a)Behaviour analytics: AI algorithms can analyse player behaviour to identify
patterns, preferences, and areas for improvement. This information can be
used to personalise gaming experiences.
b)Health monitoring: Wearable devices or in-game sensors can be used to
monitor players' physical health indicators. Al analyses this data to detect
signs of fatigue or stress.
c) Alerts and breaks: Al can generate alerts or recommend breaks for players
based on their health data. This helps prevent extended gaming sessions that
may negatively impact well-being.
7) Cheating prevention: AI is used at large to help with infidelity, especially in
multiplayer games. These games are played by millions of players at the same
time and numerous of these players also resort to the practice of infidelity. Al is
used to find those players by assaying their gaming patterns and also giving them
warnings, either guarding or blocking them straight to make the terrain better for
the genuine players
8) Quality assurance: Numerous gaming companies also use Al to test their games.
numerous times, newer games that don't have numerous brigades and games
that are generally independent use AI to find bugs in their games and also to fix
them so that the gaming can be better by those independent gaming companies.
9) Data mining & analytics: AI can be used to understand the number of players. It's
used to check how many players are playing the game and how many are playing
a certain kidney of the game. This helps gaming companies concentrate on
what's in demand and enhance their gaming experience.
The global video game market size is projected to hit around USD 610.6 billion by
2032, growing at a CAGR of 10.5% during the forecast period of 2023-2032.
Al will be a critical contributor to redefining the future of the gaming industry. AI in
gaming is going to be transformed with more technological advancements. In the
future, with AI, the whole game can be developed within a few hours with highly
detailed levels. Newer developments, such as personalised gaming experiences, will
come out of the content to give an experience that is different for each player.
Enhanced natural language processing will make your gaming more and more real.
This language processing will make it real to interact with the characters of the
game, such as a person does with a human. The graphical rendering powered by the
AI will make the whole gaming experience look more and more real and closer to the
real world. Al is also a great option for sound design, making it better for different
levels.
Limitations
There are many limitations to AI and they will apply to the gaming industry too. With
more time invested in the development of AI, we will see whether it will be able to
overcome them or not.
◦ AI, although quite powerful, still has certain limitations. You can not give
commands to the Al in the middle of the game and change the whole mechanics of
how the game works.
◦ You can not develop a whole game just by commanding the AI. Also, there's a
bias that can come into the AI.
◦ There's also an ethical issue with AI. If not given proper instructions, Al can add
problematic stuff to the game.
https://www.developers.dev/tech-talk/video-game-design-the-history-of-ai.html
What Is AI In Gaming?
Artificial intelligence refers to programming that allows characters, including
enemies and non-playable characters, in video games to behave in a way that
makes them feel like they are being controlled by humans or have their own
minds.
This is how AI can make games more immersive. But what does it mean in
practice?
You have probably played Pacman before. It is one of the most iconic
examples of early AI. Four different coloured ghosts pursue Pacman as he
tries to collect every dot on the screen.
They do not follow Pacman, and they also seem to try to ambush him when
he is playing. How did they do this? Each ghost is programmed to respond to
Pacmans location.
One ghost is to wander, and one ghost is to follow Pacman aggressively.
Another ghost is to follow Pacman in the same direction unless Pacman is
catching up to it.
The final ghost will follow Pacman when he is far away but move to a
particular location on the map when Pacman is near.
These four behaviors make the ghosts appear to have a will, even though
they are playing a 1980 game. They feel alive.
That is why AI in video games serves its purpose.
There Were Many New Ways To Use AI In The 1990s And 2000s
Formal AI tools, such as finite state machines (FAI), were used to create new
video games in the 1990s. Real-time strategy games such as economic
planning, pathfinding and real-time decision-making were made possible by
AI.
These were the first games that had problems. Herzog Zweis' pathfinding was
hampered in the second game. To control its units, it used only three-state
state machines.
In 1992, Dune II used no cheats. These problems were quickly resolved as AI
became more sophisticated.
Later, video games utilized bottom-up AI techniques. In Creatures and
Black&White for instance, AI was used to assess player actions .
The facade was 2005s first interactive multi-way dialogue.
In just a few years, AI might play a greater role in the development of games
than it does in the game itself. Recent experiments with deep learning
technology allowed AI to learn from a sequence of images and text to
replicate the experience.
AI is being used to create works of art that look like Picassos or emails that
appear to be written by humans. The same technology is being used to
develop games.
In an experiment, artificial intelligence was able to program a level of a
playable game using only photographs.
This technology is becoming more reliable, and a wide variety of open-world
games can be generated easily by AI and then edited by developers and
designers.
This will speed up the development process. Deep fake technology and facial
recognition software are also emerging, which could play an important role
in future development cycles.
An AI can recognize and use different faces it scans with deep fake
technology.
Although it is still in its infancy, this type of AI can scan faces to create 3D
models that are impressively realistic.
Imagine if the same technology could be used to create a building or
landscape. This would save developers countless hours.
It is possible that an AI could use all of these technologies to create a
complete game without the need for developers.
These AIs may be able to create games entirely from scratch by using players
preferences and habits as a guideline.
This will allow them to create unique experiences for each player. Although
it's difficult to predict when it will reach this point, it wouldn't surprise if AI
plays a larger role in game development over the next few years.
Examples Of AI In Games
There are many ways to use AI in games. It can be used to enhance images,
automate the level generation and stories, balance in-game complexity and
add intelligence to non-playing characters.
Image Enhancement
AI engineers are at the forefront of image enhancement. They are developing
a deep learning system that transforms 3D-rendered graphics into
photorealistic images.
Grand Theft Auto 5 has seen the implementation of such a system. This
neural network can recreate LA and southern California landscap es with
great detail.
High-quality 3D synthetic images can be transformed into realistic-looking
depictions using the most advanced image enhancement AI algorithms.
Image enhancement can be used to enhance the graphics of old video games.
This job involves taking a low-resolution image and turning it into an
identical version with many more pixels.
This is known as "AI upscaling".
https://www.linkedin.com/pulse/evolution-ai-games-historical-overview-suvrajit-
sarkar-ayukf/
Introduction
The origins of AI in games can be traced back to the 1950s and 60s, with the
development of games like "Tic-Tac-Toe" and "Chess" on computers. These games,
although simple by today’s standards, laid the groundwork for AI in gaming,
demonstrating that machines could be programmed to take on human opponents in
strategy games.
The 1970s and 80s saw significant advancements in game AI. The introduction of
arcade games like "Pong" and "Space Invaders" brought AI-controlled opponents to
the mainstream audience. These games featured simple AI that could respond to
player actions, making the gaming experience more dynamic.
The 90s: The Rise of 3D Gaming and Complex AI
The 1990s ushered in a new era of 3D gaming, which demanded more sophisticated
AI to manage complex environments and narratives. Games like "Doom" (1993) and
"Half-Life" (1998) featured AI that could navigate 3D spaces and exhibit behaviours
that mimicked human tactics.
The introduction of machine learning and procedural content generation marked the
next significant phase in game AI development. Games like "The Sims" (2000), which
used AI to simulate real-life behaviours and interactions, and "No Man’s Sky" (2016),
which used procedural generation to create vast, explorable universes, showcased
the potential of AI to create more immersive and expansive gaming experiences.
AI in Mobile Gaming
With the rise of mobile gaming, AI has been instrumental in personalizing gaming
experiences for a diverse audience. AI algorithms analyse player data to tailor game
difficulty, suggest in-game purchases, and even create personalized content,
ensuring that mobile games remain engaging over time.
https://www.simplilearn.com/tutorials/artificial-intelligence-tutorial/a-star-
algorithm
Search algorithms are designed to search for or retrieve elements from a data
structure, where they are stored. They are essential to access desired elements in a
data structure and retrieve them when a need arises. A vital aspect of search
algorithms is Path Finding, which is used to find paths that can be taken to traverse
from one point to another, by finding the most optimum route.
What is an A* Algorithm?
It is a search algorithm used to find the shortest path between an initial and a final
point. It is often used for map traversal to find the shortest path. A* was initially
designed as a graph traversal problem to help build a robot that can find its own
course. It remains a widely popular algorithm for graph traversal.
It searches for shorter paths first, thus making it an optimal and complete algorithm.
An optimal algorithm will find the least cost outcome for a problem, while a
complete algorithm finds all the possible outcomes of a problem.
A major drawback of the algorithm is its space and time complexity. It takes a large
amount of space to store all possible paths and a lot of time to find them.
This ensures A* explores fewer paths than Dijkstra’s algorithm while still
guaranteeing the shortest path, provided the heuristic is admissible and consistent.
Its adaptability, efficiency, and guaranteed optimality in a wide range of scenarios
make it a go-to algorithm for applications in robotics, gaming, and navigation
systems.
Applications of A* Algorithm
The A* algorithm is widely used in various domains for pathfinding and optimization
problems. Its versatility and efficiency make it a valuable algorithm in many real-
world scenarios.
- Route planning applications use A* to find the shortest or fastest routes between
locations.
A* Search Algorithm is a simple and efficient search algorithm that can be used to
find the optimal path between two nodes in a graph. It will be used for the shortest
path finding. It is an extension of Dijkstra’s shortest path algorithm (Dijkstra’s
Algorithm). The extension here is that, instead of using a priority queue to store all
the elements, we use heaps (binary trees) to store them.
The A* Search Algorithm also uses a heuristic function that provides additional
information regarding how far away from the goal node we are. This function is used
in conjunction with the f-heap data structure in order to make searching more
efficient. Let us now look at a brief explanation of the A* algorithm.
Explanation
In the event that we have a grid with many obstacles and we want to get somewhere
as rapidly as possible, the A* Search Algorithms are our savior. From a given starting
cell, we can get to the target cell as quickly as possible. It is the sum of two variables’
values that determines the node it picks at any point in time.
At each step, it picks the node with the smallest value of ‘f’ (the sum of ‘g’ and ‘h’)
and processes that node/cell. ‘g’ and ‘h’ is defined as simply as possible below:
‘g’ is the distance it takes to get to a certain square on the grid from the starting
point, following the path we generated to get there.
‘h’ is the heuristic, which is the estimation of the distance it takes to get to the
finish line from that square on the grid.
Heuristics are basically educated guesses. It is crucial to understand that we do not
know the distance to the finish point until we find the route since there are so many
things that might get in the way (e.g., walls, water, etc.). In the coming sections, we
will dive deeper into how to calculate the heuristics.
Advantages of A* Algorithm in AI
Firstly, it guarantees finding the optimal path when used with appropriate
heuristics.
Secondly, it is efficient and can handle large search spaces by effectively pruning
unpromising paths.
Thirdly, it can be easily tailored to accommodate different problem domains and
heuristics.
Fourthly, A* is flexible and adaptable to varying terrain costs or constraints.
Additionally, it is widely implemented and has a vast amount of resources and
support available.
Overall, the advantages of A* algorithm in AI make it a popular choice for solving
pathfinding and optimization problems.
Disadvantages of A* Algorithm in AI
While the A* algorithm in AI has numerous advantages, it also has some limitations.
The A* algorithm can be applied to non-grid search spaces that are represented as
graphs. In this case, the nodes in the graph represent states or locations, and the
edges represent the connections or transitions between them. The key difference
lies in the definition of neighbors for each node, which is determined by the edges in
the graph rather than the adjacent cells in a grid. A* algorithm can still be used to
find the optimal path in such graph-based search spaces by appropriately defining
the heuristic function and implementing the necessary data structures and
algorithms to traverse the graph.
A* Algorithm Example
1. Weighted A*
3. Bidirectional A*
Bidirectional A* searches from both the starting point and the goal simultaneously,
aiming to meet in the middle. This reduces the search space and improves efficiency,
especially in large and symmetrical environments like city grids or navigation
systems. It’s widely used in applications where minimizing computational effort is
key.
4. Anytime A*
Anytime A* provides a quick, suboptimal solution and iteratively refines it over time
as more computational resources become available. This is ideal for real-time
systems like robotics and video games, where an immediate response is necessary,
and the solution can improve dynamically.
5. Dynamic A* (D*)
6. Theta*
Theta* extends A* by allowing paths to cut diagonally across grids, enabling direct
paths rather than being restricted to grid edges. This results in shorter, more realistic
paths, making it ideal for applications like drone navigation or any domain requiring
smooth and direct movement.
4) Navmesh - from book
https://canbayar91.medium.com/game-mechanics-2-path-finding-ab4f55c1d580
Today, we are going to talk about pathfinding. And not just in games, but about
pathfinding in general. We will start by discussing games and how game worlds
are represented in this context. Once we reduce our game world to the generic
pathfinding problem, we will be investigating different algorithms and compare
how well they perform under different circumstances.
Pathfinding algorithms aim to find the shortest path between two given points.
Many games include some sort of pathfinding mechanism, some are simple, and
some are much more advanced. These mechanisms are mainly utilized in agent
(characters, NPCs, animals or vehicles) movement and can be critical in terms of
realistic artificial intelligence feeling.
The first question we need to answer is how to represent the game world. The
environment is seemingly continuous (it is not but it feels like it is) with roads, hills,
valleys and obstacles along the way. We want to run some sort of search algorithm
on the game world to find the best route, but it is not a very easy task unless we find
a way to represent the world as a discrete set of locations. Luckily, we can.
Navigation Meshes
Representing the real world in a digital environment was one of the most interesting
subjects for me during my university years. You see, the entities in the real world are
continuous and can be divided into presumably infinitely smaller pieces, from atoms
to even smaller subatomic particles. In a computer environment, however, you have
limited space to represent things. No matter how realistic your game looks, you are
limited by the number of pixels on the screen.
In computer graphics (along with other study areas), we use polygonal meshes to
model real-world entities. A mesh is the subdivision of a continuous geometric space
into discrete geometric entities. Big words, huh? Just check the image below, this
bunny is very famous. The most common shapes used in the mesh generation process
are triangles and quadrilaterals. As you increase the number of subdivisions (using
smaller shapes), you get a smoother representation of your subject.
A navigation mesh is a polygonal mesh that is specifically used to represent the
traversable area to be later used in pathfinding. The traversable area is simply divided
into convex polygons. The process of dividing a surface into smaller polygons is
called tessellation. Each polygon shares an edge with the neighbouring polygons,
which means that you can walk between them.
If you take each cell (polygon) and assign a node to the centre of gravity in that cell,
you will obtain the Voronoi diagram of the mesh. You need to use convex polygons in
this process, otherwise, the assigned nodes may end up outside the corresponding
polygon. If you connect the nodes in neighbour cells, you will end up with the dual
graph of the mesh.
I know these are a terrible bunch of drawings but come on, dig deep! Now we have a
bunch of locations and paths that we can navigate between, instead of the terrain
data with no directions. All there is left to do is to find the shortest path between the
green and red nodes.
Now that we reduced our problem to a graph search, we can turn our
focus on the path-finding algorithms.
The problem at hand is no longer any different than the generic path-finding
problem. In this section, we will go through a bunch of different solutions and try to
find the most suitable one.
Let’s face it from the beginning: We will not be going with BFS or DFS. Nevertheless,
they are good for introductory reasons. Both algorithms do a very simple thing and
that is to visit every single node on the graph until the destination node is reached.
They are exhaustive algorithms, meaning they are not very efficient. In fact, using DFS
doesn’t even make sense in this context, since it does not find the shortest path.
Instead, let’s focus on the BFS algorithm. It starts from the given node and checks all
the neighbouring nodes until the destination is reached. Since it always checks the
closest nodes first, it will always return the optimum solution, as long as the edges
are not weighted (more on this later).
I am assuming that most of you are already familiar with BFS and DFS algorithms, so I
am keeping this part short. If you are unfamiliar with the algorithms though, you may
benefit from stopping here for a moment and doing a quick internet search on how
these algorithms work. Here is how you can implement BFS using a queue.
Dijkstra’s Algorithm
BFS is very simple to implement, yet it assumes that each path has the same cost. The
paths in our problem though, do not have the same cost: some take longer to
traverse than others. A good path-finding algorithm shall find the path with the
lowest cost so that you don’t get bored while travelling. Unless you like the detour…
We can overcome this issue with Dijkstra's algorithm. In Dijkstra's algorithm, we start
from the player’s current location and keep track of the reachable nodes, along with
the cost to reach that node. In the first step, only the immediate neighbours can be
reached but as you search through the neighbours, the other nodes will become
accessible.
So, we begin our search from the starting point and at each step we pick the closest
node that is reachable so far. Once a node is reached, its neighbours also become
reachable if they were not before and the distances to its unvisited neighbours are
updated with the minimum cost path we have seen so far. At the end of the
algorithm, we will have the minimum cost paths to all the nodes in the graph.
For the sake of simplicity, I assumed that nodes numbered from 1 to n. The
performance of the algorithm can be improved using a priority queue to instantly
reach the node with the lowest cost. I omitted that part since we are not interested in
the runtime analysis at the moment.
Best-First Search
Both algorithms we have seen so far suffer from the same problem: They search the
entire graph. We don’t necessarily need to do that, though. Both algorithms assume
that our search is uninformed — that we have no prior knowledge about where our
destination is. We are informed though, we know that whether our destination is to
the east or west, north or south. Think about it, would you start riding the south if
your next quest marker flashes on the northern side of your minimap?
The best first search is a greedy algorithm that utilizes this idea and it has a very
simple logic. First, we need to define a heuristic function. In our case, Euclidian
distance can be used as an estimated difference to our goal but different scenarios
work well with different heuristic functions. The algorithm chooses to move to the
node with the lowest heuristic value until the destination is reached.
The priority queue in this pseudocode is configured with a heuristic function that we
chose. Thus, the node at the front of the queue is always the one that can be reached
with the lowest cost at any given point. If you compare the pseudocode with BFS, you
can see that the only real difference is how you configure a priority queue with the
chosen heuristic function.
A* Search
Unsurprisingly, the best-first search also has a shortcoming: It doesn’t necessarily find
the shortest path. Just like its name, the A* algorithm is the star of this post and is
widely used in path-finding problems. We will continue using the Euclidian distance
heuristic from the previous algorithm. Additionally, we will use the actual costs of the
edges on the graph to create a more solid ground. So, let’s define a function f(n)
where cost(n) is the actual cost (weight of the edge) of moving from node A to node
B. h(n) is the result returning from our heuristic function, when we are at node B.
Pseudocode is not that different from the previous ones, just the heuristic function is
changed.
Introduction
Decision Theory provides a structured approach for NPCs to make rational choices. It
consists of two main types:
1.1 Normative Decision Theory
Example: An NPC in a strategy game deciding the best move based on known
enemy positions.
Maximization Principle – NPCs select the action with the highest expected
utility.
Selecting the Best Action – Choose the option with the highest expected
utility.
Utility and Decision Theory have been successfully applied in various games:
Stealth Games – Enemies dynamically decide whether to search for or ignore
the player.
RPGs & Narrative Games – NPCs make dialogue choices based on utility-
driven models.
Conclusion
Utility Theory and Decision Theory play a crucial role in intelligent NPC behavior. By
leveraging mathematical models and probability-based decision-making, NPCs
become more adaptive, engaging, and believable. As AI in games advances, these
frameworks will continue to evolve, making NPCs smarter and more immersive.