CHAPTER 15 Artificial Intelligence © 2008 Cengage Learning EMEA.

Slides:



Advertisements
Similar presentations
Heuristic Search techniques
Advertisements

AI Pathfinding Representing the Search Space
Problem Solving by Searching Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 3 Spring 2007.
Review Binary Search Trees Operations on Binary Search Tree
Part2 AI as Representation and Search
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.4) January, 14, 2009.
Abstract Data Types and Subprograms
CSE 380 – Computer Game Programming Pathfinding AI
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
CSC 423 ARTIFICIAL INTELLIGENCE
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Uninformed Search Jim Little UBC CS 322 – Search 2 September 12, 2014
Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees.
Planning under Uncertainty
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
Chapter 4 DECISION SUPPORT AND ARTIFICIAL INTELLIGENCE
Problem Solving by Searching Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 3 Spring 2004.
And Just Games etc.. EVOLUTION OF COMPUTER GAMES PongOdyssey Beginning of the use of microprocessors ATARI VCS system bit.
Intelligent Agents What is the basic framework we use to construct intelligent programs?
Robotics Versus Artificial Intelligence. Search. SearchSearch “All AI is search” “All AI is search”  Game theory  Problem spaces Every problem is a.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Chapter 5.4 Artificial Intelligence: Pathfinding.
McGraw-Hill/Irwin ©2005 The McGraw-Hill Companies, All rights reserved ©2005 The McGraw-Hill Companies, All rights reserved McGraw-Hill/Irwin.
CHAPTER 12 ADVANCED INTELLIGENT SYSTEMS © 2005 Prentice Hall, Decision Support Systems and Intelligent Systems, 7th Edition, Turban, Aronson, and Liang.
Chapter 5.4 Artificial Intelligence: Pathfinding.
Chapter 11: Artificial Intelligence
Artificial Intelligence Dr. Paul Wagner Department of Computer Science University of Wisconsin – Eau Claire.
Chapter 14: Artificial Intelligence Invitation to Computer Science, C++ Version, Third Edition.
Artificial Intelligence Lecture 9. Outline Search in State Space State Space Graphs Decision Trees Backtracking in Decision Trees.
Presentation on Neural Networks.. Basics Of Neural Networks Neural networks refers to a connectionist model that simulates the biophysical information.
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
1 CO Games Development 1 Week 6 Introduction To Pathfinding + Crash and Turn + Breadth-first Search Gareth Bellaby.
NEURAL NETWORKS FOR DATA MINING
Representing and Using Graphs
+ Simulation Design. + Types event-advance and unit-time advance. Both these designs are event-based but utilize different ways of advancing the time.
CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.
State-Space Searches. 2 State spaces A state space consists of A (possibly infinite) set of states The start state represents the initial problem Each.
Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Chapter 4 Decision Support System & Artificial Intelligence.
Local Search and Optimization Presented by Collin Kanaley.
Basic Problem Solving Search strategy  Problem can be solved by searching for a solution. An attempt is to transform initial state of a problem into some.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
An Introduction Student Name: Riaz Ahmad Program: MSIT( ) Subject: Data warehouse & Data Mining.
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
Knowledge Representation Fall 2013 COMP3710 Artificial Intelligence Computing Science Thompson Rivers University.
Search in State Spaces Problem solving as search Search consists of –state space –operators –start state –goal states A Search Tree is an efficient way.
DATA STRUCTURES (CS212D) Overview & Review Instructor Information 2  Instructor Information:  Dr. Radwa El Shawi  Room: 
Graph Search II GAM 376 Robin Burke. Outline Homework #3 Graph search review DFS, BFS A* search Iterative beam search IA* search Search in turn-based.
CSCE 552 Spring 2010 AI (III) By Jijun Tang. A* Pathfinding Directed search algorithm used for finding an optimal path through the game world Used knowledge.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 13, 2013.
Artificial Intelligence, simulation and modelling.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
CSCE 552 Fall 2012 AI By Jijun Tang. Homework 3 List of AI techniques in games you have played; Select one game and discuss how AI enhances its game play.
Teaching Computers to Think:
Network Management Lecture 13. MACHINE LEARNING TECHNIQUES 2 Dr. Atiq Ahmed Université de Balouchistan.
The Game Development Process: Artificial Intelligence.
Knowledge Representation
Data Structures Graphs - Terminology
Introduction to Artificial Intelligence
Problem Solving by Searching
Announcements Homework 3 due today (grace period through Friday)
Haskell Tips You can turn any function that takes two inputs into an infix operator: mod 7 3 is the same as 7 `mod` 3 takeWhile returns all initial.
Knowledge Representation
Search.
Search.
Unit II Game Playing.
Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -
Presentation 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 above- described technique to bring to ‘life’ non- player 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). 1 Cognitive model based non-player character AI (no way-point system). 2 ‘Intelligent’ non-combat (allies) and combat (enemies) non-player character interaction. 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. 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. 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 Attack the player and other bots in sight. 2 Hide when under heavy attack. 3 Roam the game level if no target in sight. 4 Collect game items like health boosters, weapons, and armour. 5 Select an attack pattern based on the movement of the player. 6 Stop the current action. [see the textbook for an example 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 area- by-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

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 shows two points (A and B) in three- dimensional 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 following pseudocode example details the A* algorithm’s basic operation: 1 Initialize the goal state node. 2 Initialize the start state node. 3 Add the start state node to the open list. 4 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.