109
CSCE 590E Spring 2007 AI/Audio By Jijun Tang

CSCE 590E Spring 2007

  • Upload
    maris

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

CSCE 590E Spring 2007. AI/Audio. By Jijun Tang. Announcements. April 30 th : demos Show progress/difficulties Risk analysis Final Demo: May 8 th , 5:30pm, Amoco Hall No extension is possible Make sure you equipment works on site High school outreach - PowerPoint PPT Presentation

Citation preview

Page 1: CSCE 590E Spring 2007

CSCE 590E Spring 2007

AI/Audio

By Jijun Tang

Page 2: CSCE 590E Spring 2007

Announcements

April 30th: demos Show progress/difficulties Risk analysis

Final Demo: May 8th, 5:30pm, Amoco Hall No extension is possible Make sure you equipment works on site

High school outreach Anyone can contact their high school admin to ar

range direct talks to students Of course, in SC only

Page 3: CSCE 590E Spring 2007

Homework

Page 591 question 1 5 points, due on Monday Hardcopy should be turned in before

the class

Page 4: CSCE 590E Spring 2007

Artificial Intelligence

Intelligence embodied in a man-made device

Human level AI still unobtainable The difficulty is comprehension

Page 5: CSCE 590E Spring 2007

Goals of anAI Game Programmer

Different than academic or defense industry

1. AI must be intelligent, yet purposely flawed2. AI must have no unintended weaknesses3. AI must perform within the constraints4. AI must be configurable by game designers

or players5. AI must not keep the game from shipping

Page 6: CSCE 590E Spring 2007

Game Agents

May act as an Opponent Ally Neutral character

Continually loops through the

Sense-Think-Act cycle Optional learning or remembering step

Page 7: CSCE 590E Spring 2007

Sense-Think-Act Cycle:Sensing

Agent can have access to perfect information of the game world May be expensive/difficult to tease out

useful info Game World Information

Complete terrain layout Location and state of every game object Location and state of player

But isn’t this cheating???

Page 8: CSCE 590E Spring 2007

Sense-Think-Act Cycle: Thinking

Sensed information gathered Must process sensed information Two primary methods

Process using pre-coded expert knowledge

Use search to find an optimal solution

Page 9: CSCE 590E Spring 2007

Sense-Think-Act Cycle:Acting

Sensing and thinking steps invisible to player

Acting is how player witnesses intelligence Numerous agent actions, for example:

Change locations Pick up object Play animation Play sound effect Converse with player Fire weapon

Page 10: CSCE 590E Spring 2007

Extra Step in Cycle:Learning and Remembering

Optional 4th step Not necessary in many games

Agents don’t live long enough Game design might not desire it

Page 11: CSCE 590E Spring 2007

Making Agents Stupid

Sometimes very easy to trounce player Make agents faster, stronger, more accurate

Sometimes necessary to dumb down agents, for example: Make shooting less accurate Make longer reaction times Engage player only one at a time Change locations to make self more vulnerable

Page 12: CSCE 590E Spring 2007

Agent Cheating

Players don’t like agent cheating When agent given unfair advantage in speed,

strength, or knowledge Sometimes necessary

For highest difficultly levels For CPU computation reasons For development time reasons

Don’t let the player catch you cheating! Consider letting the player know upfront

Page 13: CSCE 590E Spring 2007

Common Game AI Techniques

A* Pathfinding Command Hierarchy Dead Reckoning Emergent Behavior Flocking Formations Influence Mapping …

Page 14: CSCE 590E Spring 2007

A* Pathfinding

Directed search algorithm used for finding an optimal path through the game world

Used knowledge about the destination to direct the search

A* is regarded as the best Guaranteed to find a path if one exists Will find the optimal path Very efficient and fast

Page 15: CSCE 590E Spring 2007

Command Hierarchy

Strategy for dealing with decisions at different levels From the general down to the foot soldier

Modeled after military hierarchies General directs high-level strategy Foot soldier concentrates on combat

Page 16: CSCE 590E Spring 2007

Dead Reckoning

Method for predicting object’s future position based on current position, velocity and acceleration

Works well since movement is generally close to a straight line over short time periods

Can also give guidance to how far object could have moved

Example: shooting game to estimate the leading distance

Page 17: CSCE 590E Spring 2007

Emergent Behavior

Behavior that wasn’t explicitly programmed

Emerges from the interaction of simpler behaviors or rules Rules: seek food, avoid walls Can result in unanticipated individual or

group behavior

Page 18: CSCE 590E Spring 2007

Flocking

Example of emergent behavior Simulates flocking birds, schooling fish

Developed by Craig Reynolds 1987 SIGGRAPH paper

Three classic rules1. Separation – avoid local flockmates2. Alignment – steer toward average heading3. Cohesion – steer toward average position

Page 19: CSCE 590E Spring 2007

Formations

Group movement technique Mimics military formations

Similar to flocking, but actually distinct Each unit guided toward formation

position Flocking doesn’t dictate goal positions

Page 20: CSCE 590E Spring 2007

Influence Mapping

Method for viewing/abstracting distribution of power within game world

Typically 2D grid superimposed on land Unit influence is summed into each grid cell

Unit influences neighboring cells with falloff Facilitates decisions

Can identify the “front” of the battle Can identify unguarded areas Plan attacks Sim-city: influence of police around the city

Page 21: CSCE 590E Spring 2007

Level-of-Detail AI

Optimization technique like graphical LOD Only perform AI computations if player will

notice For example

Only compute detailed paths for visible agents Off-screen agents don’t think as often

Page 22: CSCE 590E Spring 2007

Manager Task Assignment

Manager organizes cooperation between agents Manager may be invisible in game Avoids complicated negotiation and

communication between agents Manager identifies important tasks and

assigns them to agents For example, a coach in an AI football team

Page 23: CSCE 590E Spring 2007

Terrain Analysis

Analyzes world terrain to identify strategic locations

Identify Resources Choke points Ambush points Sniper points Cover points

Page 24: CSCE 590E Spring 2007

Trigger System

Highly specialized scripting system Uses if/then rules

If condition, then response Simple for designers/players to

understand and create More robust than general scripting Tool development simpler than general

scripting

Page 25: CSCE 590E Spring 2007

Promising AI Techniques

Show potential for future Generally not used for games

May not be well known May be hard to understand May have limited use May require too much development time May require too many resources

Page 26: CSCE 590E Spring 2007

Bayesian Networks

Performs humanlike reasoning when faced with uncertainty

Potential for modeling what an AI should know about the player Alternative to cheating

RTS Example AI can infer existence or nonexistence of

player build units

Page 27: CSCE 590E Spring 2007

Blackboard Architecture

Complex problem is posted on a shared communication space Agents propose solutions Solutions scored and selected Continues until problem is solved

Alternatively, use concept to facilitate communication and cooperation

Page 28: CSCE 590E Spring 2007

Decision Tree Learning

Constructs a decision tree based on observed measurements from game world

Best known game use: Black & White Creature would learn and form “opinions” Learned what to eat in the world based

on feedback from the player and world

Page 29: CSCE 590E Spring 2007

Filtered Randomness

Filters randomness so that it appears random to players over short term

Removes undesirable events Like coin coming up heads 8 times in a row

Statistical randomness is largely preserved without gross peculiarities

Example: In an FPS, opponents should randomly spawn

from different locations (and never spawn from the same location more than 2 times in a row).

Page 30: CSCE 590E Spring 2007

Genetic Algorithms

Technique for search and optimization that uses evolutionary principles

Good at finding a solution in complex or poorly understood search spaces

Typically done offline before game ships Example:

Game may have many settings for the AI, but interaction between settings makes it hard to find an optimal combination

Page 31: CSCE 590E Spring 2007

N-Gram Statistical Prediction

Technique to predict next value in a sequence

In the sequence 18181810181, it would predict 8 as being the next value

Example In street fighting game, player just did

Low Kick followed by Low Punch Predict their next move and expect it

Page 32: CSCE 590E Spring 2007

Neural Networks

Complex non-linear functions that relate one or more inputs to an output

Must be trained with numerous examples Training is computationally expensive making

them unsuited for in-game learning Training can take place before game ships

Once fixed, extremely cheap to compute

Page 33: CSCE 590E Spring 2007

Planning

Planning is a search to find a series of actions that change the current world state into a desired world state

Increasingly desirable as game worlds become more rich and complex

Requires Good planning algorithm Good world representation Appropriate set of actions

Page 34: CSCE 590E Spring 2007

Player Modeling

Build a profile of the player’s behavior Continuously refine during gameplay Accumulate statistics and events

Player model then used to adapt the AI Make the game easier: player is not good at

handling some weapons, then avoid Make the game harder: player is not good at

handling some weapons, exploit this weakness

Page 35: CSCE 590E Spring 2007

Production (Expert) Systems

Formal rule-based system Database of rules Database of facts Inference engine to decide which rules trigger –

resolves conflicts between rules Example

Soar used experiment with Quake 2 bots Upwards of 800 rules for competent opponent

Page 36: CSCE 590E Spring 2007

Reputation System

Models player’s reputation within the game world

Agents learn new facts by watching player or from gossip from other agents

Based on what an agent knows Might be friendly toward player Might be hostile toward player

Affords new gameplay opportunities “Play nice OR make sure there are no

witnesses”

Page 37: CSCE 590E Spring 2007

Smart Terrain

Put intelligence into inanimate objects Agent asks object how to use it: how to

open the door, how to set clock, etc Agents can use objects for which they

weren’t originally programmed for Allows for expansion packs or user created

objects, like in The Sims Enlightened by Affordance Theory

Objects by their very design afford a very specific type of interaction

Page 38: CSCE 590E Spring 2007

Speech Recognition

Players can speak into microphone to control some aspect of gameplay

Limited recognition means only simple commands possible

Problems with different accents, different genders, different ages (child vs adult)

Page 39: CSCE 590E Spring 2007

Text-to-Speech

Turns ordinary text into synthesized speech Cheaper than hiring voice actors Quality of speech is still a problem

Not particularly natural sounding Intonation problems Algorithms not good at “voice acting”: the mouth

needs to be animated based on the text Large disc capacities make recording human

voices not that big a problem No need to resort to worse sounding solution

Page 40: CSCE 590E Spring 2007

Artificial Intelligence: Pathfinding

Page 41: CSCE 590E Spring 2007

Introduction

Almost every game requires pathfinding Agents must be able to find their way

around the game world Pathfinding is not a trivial problem The fastest and most efficient

pathfinding techniques tend to consume a great deal of resources

Page 42: CSCE 590E Spring 2007

Representing the Search Space

Agents need to know where they can move Search space should represent either

Clear routes that can be traversed Or the entire walkable surface

Search space typically doesn’t represent: Small obstacles or moving objects

Most common search space representations: Grids Waypoint graphs Navigation meshes

Page 43: CSCE 590E Spring 2007

Grids

2D grids – intuitive world representation Works well for many games including so

me 3D games such as Warcraft III Each cell is flagged

Passable or impassable Each object in the world can occupy o

ne or more cells

Page 44: CSCE 590E Spring 2007

Characteristics of Grids

Fast look-up Easy access to neighboring cells Complete representation of the level

Page 45: CSCE 590E Spring 2007

Waypoint Graph

A waypoint graph specifies lines/routes that are “safe” for traversing

Each line (or link) connects exactly two waypoints

Page 46: CSCE 590E Spring 2007

Characteristicsof Waypoint Graphs

Waypoint node can be connected to any number of other waypoint nodes

Waypoint graph can easily represent arbitrary 3D levels

Can incorporate auxiliary information Such as ladders and jump pads Radius of the path

Page 47: CSCE 590E Spring 2007

Navigation Meshes

Combination of grids and waypoint graphs Every node of a navigation mesh represents

a convex polygon (or area) As opposed to a single position in a waypoint no

de Advantage of convex polygon

Any two points inside can be connected without crossing an edge of the polygon

Navigation mesh can be thought of as a walkable surface

Page 48: CSCE 590E Spring 2007

Navigation Meshes (continued)

Page 49: CSCE 590E Spring 2007

Characteristics of Navigation Meshes

Complete representation of the level Ties pathfinding and collision detection

together Can easily be used for 2D and 3D games

Page 50: CSCE 590E Spring 2007

Searching for a Path

A path is a list of cells, points, or nodes that an agent must traverse

A pathfinding algorithm finds a path From a start position to a goal position

The following pathfinding algorithms can be used on Grids Waypoint graphs Navigation meshes

Page 51: CSCE 590E Spring 2007

Criteria for Evaluating Pathfinding Algorithms

Quality of final path Resource consumption during search

CPU and memory Whether it is a complete algorithm

A complete algorithm guarantees to find a path if one exists

Page 52: CSCE 590E Spring 2007

Random Trace

Simple algorithm Agent moves towards goal If goal reached, then done If obstacle

Trace around the obstacle clockwise or counter-clockwise (pick randomly) until free path towards goal

Repeat procedure until goal reached

Page 53: CSCE 590E Spring 2007

Random Trace (continued)

How will Random Trace do on the following maps?

Page 54: CSCE 590E Spring 2007

Random Trace Characteristics

Not a complete algorithm Found paths are unlikely to be optimal Consumes very little memory

Page 55: CSCE 590E Spring 2007

Understanding A*

To understand A* First understand Breadth-First, Best-First,

and Dijkstra algorithms These algorithms use nodes to

represent candidate paths

Page 56: CSCE 590E Spring 2007

Understanding A*

class PlannerNode

{

public:

PlannerNode *m_pParent;

int m_cellX, m_cellY;

...

};

The m_pParent member is used to chain nodes sequentially together to represent a path

Page 57: CSCE 590E Spring 2007

Understanding A*

All of the following algorithms use two lists The open list The closed list

Open list keeps track of promising nodes When a node is examined from open list

Taken off open list and checked to see whether it has reached the goal

If it has not reached the goal Used to create additional nodes Then placed on the closed list

Page 58: CSCE 590E Spring 2007

Overall Structure of the Algorithms

1. Create start point node – push onto open list2. While open list is not empty

A. Pop node from open list (call it currentNode)B. If currentNode corresponds to goal, break from step 2C. Create new nodes (successors nodes) for cells around currentNode and push them onto open listD. Put currentNode onto closed list

Page 59: CSCE 590E Spring 2007

Breadth-First

Finds a path from the start to the goal by examining the search space ply-by-ply

Page 60: CSCE 590E Spring 2007

Breadth-First Characteristics

Exhaustive search Systematic, but not clever

Consumes substantial amount of CPU and memory

Guarantees to find paths that have fewest number of nodes in them Not necessarily the shortest distance!

Complete algorithm

Page 61: CSCE 590E Spring 2007

Best-First

Uses problem specific knowledge to speed up the search process

Head straight for the goal Computes the distance of every node

to the goal Uses the distance (or heuristic cost) as a

priority value to determine the next node that should be brought out of the open list

Page 62: CSCE 590E Spring 2007

Best-First (continued)

Page 63: CSCE 590E Spring 2007

Best-First (continued)

Situation where Best-First finds a suboptimal path

Page 64: CSCE 590E Spring 2007

Best-First Characteristics

Heuristic search Uses fewer resources than Breadth-

First Tends to find good paths

No guarantee to find most optimal path Complete algorithm

Page 65: CSCE 590E Spring 2007

Dijkstra

Disregards distance to goal Keeps track of the cost of every path No guessing

Computes accumulated cost paid to reach a node from the start Uses the cost (called the given cost) as a

priority value to determine the next node that should be brought out of the open list

Page 66: CSCE 590E Spring 2007

Dijkstra Characteristics

Exhaustive search At least as resource intensive as

Breadth-First Always finds the most optimal path Complete algorithm

Page 67: CSCE 590E Spring 2007

A*

Uses both heuristic cost and given cost to order the open list

Final Cost = Given Cost + (Heuristic Cost * Heuristic Weight)

Page 68: CSCE 590E Spring 2007

A* (continued)

Avoids Best-First trap!

Page 69: CSCE 590E Spring 2007

A* Characteristics

Heuristic search On average, uses fewer resources than

Dijkstra and Breadth-First Admissible heuristic guarantees it will find

the most optimal path Complete algorithm

Page 70: CSCE 590E Spring 2007

Summary

Two key aspects of pathfinding: Representing the search space Searching for a path

Page 71: CSCE 590E Spring 2007

Audio Programming

Page 72: CSCE 590E Spring 2007

Audio Programming

Audio in games is more important than ever before

Page 73: CSCE 590E Spring 2007

Programming Basic Audio

Most gaming hardware has similar capabilities (on similar platforms) Mostly programming interfaces differ

Learning fundamental concepts of audio programming is important

Page 74: CSCE 590E Spring 2007

API Choices

DirectSound (part of DirectX API) Only available on Windows platforms

OpenAL Newer API Available on multiple platforms

Proprietary APIs Typically available on consoles

3rd Party Licensable APIs Can offer broad cross-platform solutions

Page 75: CSCE 590E Spring 2007

Analog Sound Wave

Page 76: CSCE 590E Spring 2007

Basic Audio Terminology and Physics

Amplitude Measurement of a sound wave’s pressure

Frequency Measurement of the interval between wave cycles,

typically measured in Hertz Pitch

The perception of frequency Tuning

Musical distribution of frequencies over keys Decibel

Measures sound amplitude

Page 77: CSCE 590E Spring 2007

Digital Representation of a Sound Wave

Page 78: CSCE 590E Spring 2007

Digital Representationof a Sound Wave

Most common technique known as sampling Sampling involves measuring the amplitude of

the analog wave file at discrete intervals The frequency of sampling is known as sampling

rate Each sample is typically stored in a value ranging

from 4 to 24 bits in size The size of the sample value in bits is known as

the ‘bit depth’ Music CDs have a sample rate and bit depth of

44.1 kHz (samples/sec) and 16 bits (sample size)

Page 79: CSCE 590E Spring 2007

Quantization Error in Sampling

Page 80: CSCE 590E Spring 2007

Bit Depth and Signal Noise

Bit depth of sample data affects signal noise Signal to noise ratio = number of available bits /

1 For example, 8-bit samples have a 256:1 SNR

(~48 dB), and 16-bit samples have a 65,536:1 SNR (~96 dB)

Decibel ratio is calculated using 10 x log10 (ratio) or 8.685890 x log e (ratio)

Page 81: CSCE 590E Spring 2007

Sampling Frequency and Frequency Reproduction

Sampling frequency affects range and quality of high-frequency reproduction

Nyquist Limit Frequencies up to one-half the sampling

rate can be reproduced Audio quality degrades as frequency

approaches this limit

Page 82: CSCE 590E Spring 2007

Sampling Errors vs. Sampling Frequency

Page 83: CSCE 590E Spring 2007

Modern Audio Hardware

Samples are piped into sound “channels” Often a hardware pipeline from this point

Various operations, such as volume, pan, and pitch may be applied

3D sounds may apply HRTF algorithms and/or mix the sound into final output buffers.

Page 84: CSCE 590E Spring 2007

Sound Playback Techniques

Two basic playback methods:1. Play sample entirely from memory buffer2. Stream data in real-time from storage

medium Streaming is more memory efficient for very

large audio files, such as music tracks, dialogue, etc

Streaming systems use either a circular buffer with read-write pointers, or a double-buffering algorithm

Page 85: CSCE 590E Spring 2007

Playback

Page 86: CSCE 590E Spring 2007

Sample Playback and Manipulation

Three basic operations you should know Panning is the attenuation of left and right

channels of a mixed sound Results in spatial positioning within the aural stereo

field

Pitch allows the adjustment of a sample’s playback frequency in real-time

Volume control typically attenuates the volume of a sound Amplification is generally never supported

Page 87: CSCE 590E Spring 2007

Compressed Audio Format

Compressed audio formats allow sound and music to be stored more compactly Bit reduction codecs generally are lightweight

ADPCM compression is implemented in hardware on all the major current video game console systems

Psycho-acoustic codecs often have better compression Discard sounds our ears would not typically be able to

hear Require substantially more computational horsepower

to decode

Page 88: CSCE 590E Spring 2007

MP3, Ogg Vorbis,Licensing & Patent Issues

The MP3 format is patented Any commercial game is subject to licensing term

s as determined by Fraunhofer & Thompson Multimedia, the holders of the patents

Ogg Vorbis is similar to MP3 in many ways Open source and patent-free (royalty-free)

Be aware of patent and license restrictions when using 3rd party software

Page 89: CSCE 590E Spring 2007

3D Audio

Two sets of data required when working in world coordinates: Listener Data

Composed of world position and orientation (virtual microphone in the world)

Source Data Composed of sound position, orientation,

velocity, etc (virtual sound source in the world)

Page 90: CSCE 590E Spring 2007

Listener/Source

Page 91: CSCE 590E Spring 2007

Environmental Effects

Environmental effects nearly always implemented in hardware

Sound transmission is categorized in three ways Direct transmission Early reflections (echo) Late reflections (reverberation)

Page 92: CSCE 590E Spring 2007

Sound Transmission Categories

Page 93: CSCE 590E Spring 2007

EnvironmentalEffects Standards

EAX 2.0 and beyond EAX 2.0 developed by Creative Labs and

released as an open standard EAX 3.0 and 4.0 remain proprietary

Creative Labs standards I3DL2

Open standard developed by IA-SIG, similar to EAX 2.0 in functionality

Page 94: CSCE 590E Spring 2007

Programming Music Systems

Two common music systems MIDI-based systems

(Musical Instrument Digital Interface) Digital audio streaming systems

(CD audio, MP3 playback, etc)

Page 95: CSCE 590E Spring 2007

Advantages and Disadvantages of MIDI

Actual music data size is negligible Easy to control, alter, and even

generate in real-time High quality music is more difficult to

compose and program Only effective if you can guarantee

playback of a common instrument set

Page 96: CSCE 590E Spring 2007

Example

Page 97: CSCE 590E Spring 2007

Other MIDI-based technologies to be aware of

DLS (DownLoadable Sound) Format A standardized format for instrument defi

nition files iXMF (Interactive eXtensible Music For

mat) New proposed standard for a container fo

rmat for interactive music

Page 98: CSCE 590E Spring 2007

Advantages / Disadvantages of Digital Audio Streams

Superb musical reproduction is guaranteed

Allows composers to work with any compositional techniques

Some potential interactivity is sacrificed for expediency and musical quality

Generally high storage requirements

Page 99: CSCE 590E Spring 2007

A Conceptual Interactive Music Playback System

Divide music into small two to eight-bar chunks that we’ll call segments.

A network of transitions from segment to segment (including loops and branches) is called a theme.

Playing music is now as simple as choosing a theme to play. The transition map tracks the details.

Page 100: CSCE 590E Spring 2007

Advanced Audio Programming

3D Audio Environmental Effects Integration

Audio Scripting and Engine Integration Lip-sync Technology Advanced Voice Playback Voice Recognition

Page 101: CSCE 590E Spring 2007

3D Audio Environmental Effects Integration

Environmental effects should be driven by a room’s shape and material composition. Can determining the optimal effect

settings be done automatically? This may be important as game worlds

become larger and more complex

Page 102: CSCE 590E Spring 2007

3D Audio Environmental Effects Integration (cont)

Sound occlusion and damping is a particularly difficult problem to solve This is essentially a pathfinding problem

for audio. Doors can dynamically affect a sound’s

properties Very few titles have even attempted a

robust, general-purpose, and automated solution to these problems.

Page 103: CSCE 590E Spring 2007

Room Acoustics

Page 104: CSCE 590E Spring 2007

Dynamic Occlusion

Page 105: CSCE 590E Spring 2007

Audio Scripting and Engine Integration

Very little audio programming should be done by general game programmers

Game Engine should offer robust support for audio triggers and scripts

Engine should deal with audio scripts, not “sound files”

Why is this so important?

Page 106: CSCE 590E Spring 2007

Audio Scripting

Many situations require much more information than can be embedded in a linear audio file Sound Variation Sound Repetition Complex Sound Looping Background Ambience

Page 107: CSCE 590E Spring 2007

Lip-sync Technology

Lip-sync technology is a blending of audio and visual techniques to create realistic-looking speech by in-game actors. Simple techniques such as waveform amplitude

measurement has worked previously, but… In future titles, it will be considered inadequate. Much work can still be done in this field.

Page 108: CSCE 590E Spring 2007

Advanced Voice Playback

Real-time spoken feedback is especially important in sports titles (simulated announcers)

Game are reaching the limits of what current techniques (canned, prerecorded phrases combined in series) can provide.

Again, this is an opportunity for future groundbreaking audio work.

Page 109: CSCE 590E Spring 2007

Voice Recognition

Spoken commands are much easier to deliver in certain situations.

A great example of this? Squad-based tactical shooters.

Current generation systems are still very error prone. A great opportunity for breakout audio technology.