Download Chapter 15 - Cengage Learning

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Ethics of artificial intelligence wikipedia , lookup

History of artificial intelligence wikipedia , lookup

Computer Go wikipedia , lookup

Catastrophic interference wikipedia , lookup

Gene expression programming wikipedia , lookup

Stemming wikipedia , lookup

Artificial intelligence in video games wikipedia , lookup

Genetic algorithm wikipedia , lookup

Rete algorithm wikipedia , lookup

Minimax wikipedia , lookup

Hierarchical temporal memory wikipedia , lookup

Transcript
CHAPTER 15
Artificial Intelligence
© 2008 Cengage Learning EMEA
LEARNING OBJECTIVES

In this chapter you will learn about:
–
–
–
–
–
–
–
–
–
–
–
History of AI in games
Pre-programmed AI
Scripting
Modeling AI by means of finite state machines
Autonomous behaviour: memory and planning
Pathfinding
The A* algorithm
Depth-first search
Breadth-first search
Waypoint pathfinding
More advanced AI: neural networks, expert systems and
genetic algorithms
HISTORY OF AI IN GAMES
Artificial intelligence (AI) is the design and
application of methods modeled after the
behaviour of humans and/or animals to solve
complicated problems.
 More formally, AI can be defined as the design
and application of intelligent agents.
 An intelligent agent is a piece of software that
intelligently supports the actions of a user.
 These agents are used to monitor and
intelligently act upon certain triggers present in
an environment.

HISTORY OF AI IN GAMES

So what is intelligence?
– It is a collection of logic, mathematics,
probability, and memory, all applied in an
interconnected manner that maximizes the
chances of a successful outcome.

AI in games is a variation of the abovedescribed technique to bring to ‘life’ nonplayer characters, thus creating the illusion
of a life-like computer controlled player
that is plotting, thinking and planning as a
human would.
HISTORY OF AI IN GAMES

Game AI differs substantially from
theoretical academic AI in the sense that,
even though numerous techniques exist,
there is no right or wrong way of doing
something – the end result is what
matters.
– For example, if a non-player character or ‘bot’
(an abbreviation for the word robot) is
indistinguishable from a real-life opponent
then the AI of that character can be described
as ideal.
HISTORY OF AI IN GAMES

Developers implementing AI as
showcased by the games released today,
attempt to meet as many of the following
criteria as possible (varying depending on
the type of game and its genre):
HISTORY OF AI IN GAMES
1 Cognitive model based non-player character AI
(no way-point system).
 2 ‘Intelligent’ non-combat (allies) and combat
(enemies) non-player character interaction.
 3 Interactive communication system, for
example, the player can instruct an ally to help
out in a fight or to defend some other location.
 4 Non-player characters make automatic
decision to fight, dodge, flee, hide, burrow, etc.
based on player resistance, for example,
enemies can make decision to fall back to
regroup if resistance is overwhelming.

PRE-PROGRAMMED AI

Pre-programmed or deterministic AI is the
simplest form of AI found in games. Such
algorithms add predetermined behaviour
to an object and are characterized as
minimal goal algorithms.
– For example, an object can move from one
position to another based on some randomly
calculated velocity (the only goal here is to
move in a pre-defined path).
PRE-PROGRAMMED AI
[see the textbook for an example
and detailed discussion].
SCRIPTING

Pre-programmed AI is great for adding basic
predetermined behaviour to an object, but the
associated randomness doesn’t serve us well in
situations where an object is required to perform
a specific sequence of tasks or steps.
– For instance, a bot might be required to patrol an
area between two points; using deterministic AI we
can place two objects at the ends of this path with
the bot doing simple pathtracing between them.
– This works well but becomes tedious and
computationally intensive when numerous paths need
to be traced or when additional tasks such as the
activation of a switch are required.
SCRIPTING

A deterministic algorithm would not be able to
cope with a complicated sequence of steps such
as the ones given here:
1 If the player is within MAX_ATTACK_DISTANCE:
a Break into room through air vent.
b Attack player using a combination of the following:
i Throw foreign objects such as barrels at the player.
ii Use projectile-based weaponry.
iii Use melee weapons after launching at player.
c Fight, dodge, flee, hide, or burrow based on player
resistance.
2 If the player is not within MAX_ATTACK_DISTANCE:
a Wait.
SCRIPTING


This is the reason for scripted AI; it provides us with a
convenient and accurate way of controlling the
behaviour of non-player characters.
Returning to our example, we can now script its actions
using the following scripted sequence:
1 Move forward.
2 If END_OF_BRIDGE is reached, stop.
a Turn around (180-degree rotation).
b Move forward.
c If START_OF_BRIDGE is reached, stop.
i Turn around (180-degree rotation)
[see the textbook for an example
and detailed discussion].
MODELING AI BY MEANS OF
FINITE STATE MACHINES

Using FSMs, we can model the actions of
AI controlled computer opponents through
a number of states.
MODELING AI BY MEANS OF
FINITE STATE MACHINES

As an example of developing an FSA for a bot,
as found in common first-person shooter games
such as Quake III and Unreal Tournament, we
can start with a number of master states as
listed here:
1
2
3
4
Attack the player and other bots in sight.
Hide when under heavy attack.
Roam the game level if no target in sight.
Collect game items like health boosters, weapons, and
armour.
5 Select an attack pattern based on the movement of
the player.
[see the textbook for an example
6 Stop the current action.
and detailed discussion].
AUTONOMOUS BEHAVIOUR:
MEMORY AND PLANNING
Up to this point we have not really dealt
with any real AI.
 Pre-programmed AI and scripting are
great ways to create seemingly intelligent
opponents but a truly intelligent opponent
must have the ability to learn, remember,
and adapt in much the same way as
expected from a human being.

AUTONOMOUS BEHAVIOUR:
MEMORY AND PLANNING


The simplest solution to the memory problem involves
creating tables with information about the items stored
at a specific location.
These tables can then be updated by the bot on an areaby-area basis.
AUTONOMOUS BEHAVIOUR:
MEMORY AND PLANNING
The next step towards the goal of creating more
realistic AI is to implement planning and decision
trees.
 Planning is used to solve problems where a
series of actions must be performed to reach
some goal.
 An action is a specific step performed towards
the successful completion of a goal.
 Actions are in turn governed by conditionals, i.e.
states that must be reached before a particular
action can be executed.

[see the textbook for an example
and detailed discussion].
AUTONOMOUS BEHAVIOUR:
MEMORY AND PLANNING
PATHFINDING

Pathfinding is an AI technique used to determine
a route from point A to point B, as shown in
Figure 15-12.
PATHFINDING

If obstacle avoidance wasn’t a
primary concern, we could
simply have calculated a vector
from the start point to end
point.
– For example, Figure 15-13 shows
two points (A and B) in threedimensional space with the AI
technique of vectoring being used
to determine the path.
The A* Algorithm
The A* algorithm (pronounced ‘A star’) is one of the most
commonly used path finding algorithms.
 It is basically a tree-based search algorithm that
calculates the path from one node to some pre-specified
goal node.
 The A* algorithm starts at the root node, progressively
writing the nodes to a list in order of accessibility.

– Written nodes are each assigned a heuristic which is used to sort
them in a manner that should reveal the optimal route to the
goal node – i.e. the algorithm continuously extends the path by
moving to the node that seems to be closest to the goal.

The A* algorithm will thus not only find the path, but it
will find the shortest path if it exists.
The A* Algorithm
The A* Algorithm

The following pseudocode example details the A* algorithm’s basic
operation:
1
2
3
4
Initialize the goal state node.
Initialize the start state node.
Add the start state node to the open list.
While the open list has items in it:
a Determine the node with the lowest f(node) weight and initialize it as the
current node – this node is removed from the open list.
b Generate all the nodes possible from the current node.
c For each of these generated nodes:
i Calculate the cost of the generated node by taking the cost of the current node
plus the cost to go from the generated node to the current node.
ii Search for the next generated node on the open list.
 If the weight of the current generated node is as good as or better than this
located node, then disregard the found node and continue.
iii Search for the next generated node on the closed list.
 If the weight of the current generated node is as good as or better than this
located node, then disregard the found node and continue.
iv Remove all instances of the generated node from the open and closed list.
v Set the generated node as a child node of the current node.
vi Calculate the traversal cost from the current node to the goal and add the
generated node to the open list.
d Add the current node to the closed list
Depth-First Search
Depth-first search is a commonly used search
algorithm that follows each path to its greatest
depth before moving on to the next.
 This algorithm is extremely rudimentary when
compared to A*; for example, it needs a
stopping limit to halt the search if a goal isn’t
found in say the first 200 nodes.
 Depth-first search is an example of brute-force
search/exhaustive search, that is, all nodes are
traversed until the goal node is found.

Depth-First Search

The following pseudocode example details the depth-first
search algorithm’s basic operation:
1 Start at the given node (initially at root):
a Mark it as visited.
2 For all the vertices adjacent to the initial node:
a If the vertex is unvisited:
i Recursively jump to step 1 with this node as input.
Breadth-First Search
Breadth-first search is an alternative to the
depth-first search path-finding algorithm that
traverses a tree by breadth rather than depth.
 The algorithm terminates the moment the goal
state is reached and is much more efficient than
depth-first search where the tree has very deep
paths and particularly where the goal node is in
a shallower part of the tree.

Breadth-First Search

The following pseudocode example details the depth-first
search algorithm’s basic operation:
1 Start at the given node (initially at root):
a Mark it as visited.
b Add it to a queue.
2 While the queue isn’t empty:
a Access the node at the beginning of the queue:
i If this node is the goal node, quit and return this result.
ii Otherwise add all the subsequent unmarked child nodes of
this node to the end of the queue.
3 If the queue is empty then no path has been found.
4 Jump to step 2 and repeat.
Waypoint Pathfinding

Searching and pathfinding algorithms are great
techniques for creating computer controlled opponents
with enough intelligence to navigate complex
environments themselves.
– This isn’t, however, always necessary and by connecting various
points of interest we can utilize vectoring to produce accurate
bot movement.



A waypoint system is thus a collection of nodes (points
of interest) connected via directional links.
Each node or waypoint represents a spatial position that
can be visited.
Each directional link consists of a vector and length to
the next node in the network.
Waypoint Pathfinding
[see the textbook for an example and detailed discussion].
MORE ADVANCED AI: NEURAL
NETWORKS, EXPERT SYSTEMS
AND GENETIC ALGORITHMS

A neural network is a mathematical model
based on human brain cells or neurons.





MORE ADVANCED AI: NEURAL
NETWORKS, EXPERT SYSTEMS
AND GENETIC ALGORITHMS
Another technique often employed to facilitate the storage of
and access to human expertise, accumulated through training,
is that of expert systems (also called ‘knowledge systems’).
An expert system is based on three concepts, namely, the
knowledge of facts, data about the relationship among these
facts and a method to store and access this data.
An expert system is created by extracting facts from human
knowledge, such as routines, historic events, relationships,
and transforming these data so that they can be used to
influence the reasoning of a computer controlled opponent,
for example.
The most basic expert system is defined by a set of
production rules which is in turn used to analyse information.
This mathematical analysis yields a recommendation with
regards to the course of action that should be taken by the
user or bot.
MORE ADVANCED AI: NEURAL
NETWORKS, EXPERT SYSTEMS
AND GENETIC ALGORITHMS


A genetic algorithm (GA) is an advanced search technique based on
the principles of genetics such as inheritance, crossover, mutation,
and natural selection.
The following process outlines the execution of a genetic algorithm:
1 Start by generating a population of chromosomes.
2 Define some termination or goal criteria which can be used to terminate
the algorithm when satisfied, for example, by limiting the number of
generations.
3 Test whether the termination criteria are satisfied:
 a If they are, terminate.
 b If they are not, jump to step 4.
4 Ascertain the fitness of all the chromosomes (for example how far a
specific node is located from the goal node).
5 Generate a new population (the next generation) of chromosomes by
selecting chromosomes based on their fitness and applying mutation
and crossover to them.
6 Jump to step 3.