game programming game ai technologies n.
Skip this Video
Loading SlideShow in 5 Seconds..
Game Programming (Game AI Technologies) PowerPoint Presentation
Download Presentation
Game Programming (Game AI Technologies)

Game Programming (Game AI Technologies)

321 Views Download Presentation
Download Presentation

Game Programming (Game AI Technologies)

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Game Programming(Game AI Technologies) 2011. Spring

  2. What is AI? • Artificial Intelligence (AI) • The computer simulation of intelligent behavior • What is Intelligence? • Behavior that exhibits great ability to adapt and solve complex problems • Produce results that are completely unrealistic • Behavior that is close to that of human • Humans are not always brilliant Game AIs are not just “problem solving robots” but lifelike entities

  3. Roles of AI in Games • Opponents • Teammates • Strategic Opponents • Support Characters • Autonomous Characters • Commentators • Camera Control • Plot and Story Guides/Directors

  4. AI Entity • AI entity • Agent • A virtual character in the game world • Ex) enemies, NPCs, sidekicks, an animated cow in a field • These are structured in a way similar to our brain • Abstract controller • A structure quite similar to the agent, but each subsystem works on a higher level than an individual • Ex) strategy game  The entity that acts like the master controller of the CPU side of the battle

  5. Goals of AI action game opponent • Provide a challenging opponent • Not always as challenging as a human -- Quake monsters. • What ways should it be subhuman? • Not too challenging. • Should not be superhuman in accuracy, precision, sensing, ... • Should not be too predictable. • Through randomness. • Through multiple, fine-grained responses. • Through adaptation and learning.

  6. Structure of an Intelligent Agent • Sensing: perceive features of the environment. • Thinking: decide what action to take to achieve its goals, given the current situation and its knowledge. • Acting: doing things in the world. • Thinking has to make up for limitations in sensing and acting. • The more accurate the models of sensing and acting, the more realistic the behavior.

  7. Simple Behavior • Random motion • Just roll the dice to pick when and which direction to move • Simple pattern • Follow invisible tracks: Galaxians • Tracking • Pure Pursuit • Move toward agent’s current position • Ex) Head seeking missile • Lead Pursuit • Move to position in front of agent • Collision • Move toward where agent will be • Evasive – opposite of any tracking • Delay in sensing gives different effects

  8. Moving in the World: Path Following • Just try moving toward goal. Goal Source

  9. Problem Goal Source

  10. Create Avoidance Regions Goal Source

  11. Path Finding • A* Algorithm • find a shortest-path between two points on a map • Starting with the base node • Expand nodes using the valid moves • Each expanded node is assigned a “score” • Iterate this process • until these paths prove invalid or one of these paths reach the target

  12. Path Finding • The overall score for a state • f(node) = g(node) + h(node) • f(node): the total score (the sum of g and h) • g(node): the cost to get from the starting node to this node(측정치) • A component that accounts for our past behavior • h(node): the estimated cost to get from this node to the goal(추정치) • A component that estimate our future behavior • The Manhattan distance (4-connected game world) • Manhattan(p1, p2) = | p2.x – p1.x | + | p2.z – p1.z | Ex) p1 (2,2), p2 (1,0)  h = 3 • Euclidean distance (8-connected)

  13. Game AI • Game AI • A* algorithm • Quite smart, but not very realistic • Need to keep a reasonable degree of imperfection built into the AI design • A balance between generating • behavior that is both highly evolved and sophisticated • And behavior that is more or less human Game AIs are not just “problem solving robots” but lifelike entities Comparison between A* and a human path finder

  14. Can be extremely expensive Can be modulated by “think” Finite-state machines Decision trees Neural nets Fuzzy logic Rule-based systems Planning systems Execution Flow of an AI Engine Sense Environment Think Act

  15. Structure of an AI System • Sensing the world (The slowest part of the AI) • All AIs need to be aware of their surroundings • use that information in the reason/analysis phase • What is sensed and how largely depend on the type of game • Ex) an individual enemy in Quake • Where is the player and where is he looking? • What is the geometry of the surroundings? • Which weapons am I using and which is he using? • Ex) master controller in a strategy game (Age of Empires) • What is the balance of power in each subarea of the map? • How much of each type of resource do I have? • What is the breakdown of unit types: infantry, cavalry, … • What is my status in terms of the technology tree? • What is the geometry of the game world?

  16. Structure of an AI System • Memory • Storing AI data is often complex • the concepts being stored are not straightforward • In an individual level AI (the less of a problem) • Store points, orientations • and use numeric values to depict the “state” the AI is in • A master controller • These data structures are nontrivial • Ex) how do we store the balance of power, a path? • Case-by-case solutions Can it remember prior events? For how long? How does it forget?

  17. Structure of an AI System • Analysis/Reasoning Core (= Think) • Uses the sensory data and the memory • to analyze the current configuration • Make a decision • Can be slow or fast depending on the number of alternatives and the sensory data to evaluate • Slow process  Chess playing • Fast process  moving a character in Quake

  18. Structure of an AI System • Action/Output System • Permeate actions and responses • Many games exaggerate the action system • Personality and perceive intelligence was enhanced • The character’s intensions are obvious • Personality is conveyed • Ex) Super Mario Bros (creatures similar AIs)

  19. Game Programming(Action Oriented AI) 2011. Spring

  20. Action Oriented AI • Action Oriented AI • Overview of AI methods used in fast-paced action games. • Action: intelligent activity that involves changes of behavior at a fast speed. • Locomotion behaviors • Ex) a character runs in Mario • Simple aggression or defense • Ex) enemies shooting or ducking in Quake

  21. Object Tracking • Object Tracking • Eye contact (aim at a target: 조준하기) • Given an orientation, a point in space • Computing the best rotation to align the orientation with the point • Solution • 2D Hemiplane Test • 3D Version: Semispaces

  22. Eye Contact: 2D Hemiplane Test • 2D Hemiplane Test • Top-down view, overseeing the X,Z plane point mypos; // position of the AI float myyaw; // yaw angle in radians. I assume top-down view point hispos; // position of the moving target • The line formed by mypos and myyaw X = mypos.x + cos(myyaw) * t Z = mypos.z + sin(myyaw) * t • Solving for t (X – mypos.x)/cos(myyaw) - (Z – mypos.z)/sin(myyaw) = 0 • Which side ? F(X,Z)= (X – mypos.x)/cos(myyaw) - (Z – mypos.z)/sin(myyaw) F(X,Z) > 0 (it lies to one side of the line) F(X,Z) = 0 (it lies exactly on the line) F(X,Z) < 0 (it lies to the opposite side) 3 sub, 2 div, 1 comparison

  23. 3D version: Semispaces • 3D version: Semispaces • Need to work with the pitch and yaw angles • The equation of a unit sphere x = cos(pitch) cos(yaw) y = sin(pitch) z = cos(pitch) sin(yaw) • Use two plane to detect both left-right and the above-below test • Which side? if (vertplane.eval(target)>0) yaw-=0.01; else yaw+=0.01; if (horzplane.eval(target)>0) pitch-=0.01; else pitch+=0.01;

  24. Chasing • Chasing • Moving forward while keeping eye contact with the target • Chase 2D: Constant speed • Depends on the relationship between • our speed, the target’s speed, and our turning ability void chase(point mypos, float myyaw, point hispos) { reaim(mypos, myyaw, hispos); mypos.x = mypos.x + cos(myyaw) * speed; mypos.z = mypos.z + sin(myyaw) * speed; } aiming and advancing

  25. Chasing • Predictive chasing • Not aim at the target directly • but try to anticipate his movement and guess his intensions • Tree step approach (instead of aiming and advancing) • Calculate a projected position • Aim at that position • Advance • void chase(point mypos, float myyaw, point hispos,point prevpos) • { • point vec=hispos-prevpos; // vec is the 1-frame position difference • vec=vec*N; // we project N frames into the future • point futurepos=hispos+vec; // and build the future projection • reaim(mypos,myyaw,futurepos); • mypos.x = mypos.x + cos(myyaw) * speed; • mypos.z = mypos.z + sin(myyaw) * speed; • }

  26. Evasion • Evasion • The opposite of chasing • In stead of trying to decrease the distance to the target • Try to maximize it void evade(point mypos, float myyaw, point hispos) { reaim(mypos, myyaw, hispos); negated mypos.x = mypos.x + cos(myyaw) * speed; mypos.z = mypos.z + sin(myyaw) * speed; }

  27. Patrolling • Patrolling • Store a set of waypoints that will determine the path followed by the AI • Two configurations (waypoints) • Cyclic: W1 W2 W3 W4 W5 W1 W2 W3 W4 W5 … • Ping-pong: W1 W2 W3 W4 W5 W4 W3 W2 W1 W2 … • Implementation • Two state finite machine • Advance toward the next waypoint • Update next waypoint • Adding a third state • Chase behavior • Triggered by using a view cone for the AI • Ex) Commandos

  28. Hiding and Taking Cover • Hiding and Taking Cover • AIs to run for cover and remain unnoticed by the player • Taking cover • Find a good hiding spot • Move there quickly (= chase routine) • Three data items • Position and orientation of the player • Our position and orientation • The geometry of the level

  29. Hiding and Taking Cover • Actual algorithm • Finding the closest object to the AI’s location • Using the scene graph • Computing a hiding position for that object • Shoot one ray from the player position to the barycenter of object • Compute a point along the ray that’s actually behind the object • Ex) Medal of Honor

  30. Shooting • Shooting • Infinite-Speed Targeting • Very high speed compared to the speed of the target (virtually zero) • Aligned with the target at the moment of shooting • Abuse infinite-speed weapon (Ex: laser gun) • Unbalance your game • Solution • The firing rate: very low • The ammunition: limited • The weapon: hard to get

  31. Shooting • Real-World Targeting • Shoots projectiles at a limited speed • Shooting fast moving target is harder than shooting one that stand still • Finite-speed devices (sniper-type AI) • The Still Shooter • Only shoots whenever the enemy is standing still for a certain period of time • Disadvantage : Shooter will have very few opportunities to actually shoot • The Tracker • Shoot moving target • Compute the distance from the sniper to the target • Use projectile velocity • Predict where the target will be Single-shot firing devices

  32. Shooting • Machine Guns • Fast firing rates at the cost of inferior precision • Target not people but areas • hardly ever moved • Did not have a lot of autonomy • Short firing burst

  33. Putting It All Together • Putting It All Together • Blend these simple behaviors into a AI system • Parallel automata • AI synchronization • Parallel automata • The locomotion AI • Control locomotion • Chasing, evading, patrolling, hiding • The gunner AI • Evaluate the firing opportunities • Targeting and shooting down enemies

  34. Putting It All Together • AI Synchronization • Using shared memory • Ex) group of enemy (half-life) • Synchronization become more complex • more sophisticated interaction • Better use artificial life techniques

  35. Action Based Game • Platform Games • Platform/jump’n run games • Ex) Mario or Jak and Daxter • AIs are not very complex • Easily coded using finite-state machine • Chasers • Get activated whenever the player is within a certain range • The turret • A fixed entity that rotates, and when aiming at the player, shoots at him • Examples • Gorilla (in Jak and Daxter) • Chase the player and kill on contact • Make game too boring  add chest-hitting routine • Weak point  can attack the gorilla whenever he is hitting his chest • Bosses • Not much different than basic chaser • Complex, long-spanning choreographies • Ex) Jak and Daxter: The boss flower • Fixed to the ground • Spawn small spider  become chaser

  36. Action Based Game • Shooters • A bit more complex than platform • because the illusion of realistic combat must be conveyed • Usually built around FSMs • Need a logical way to layout the scenario • Use a graph structure with graph nodes for every room/zone • Group behavior (Ex: Half-Life)

  37. Action Based Game • Fighting Games • State machine • States: attack, stand, retreat, advance, block, duck, jump • Compute the distance to the player • Decide which behavior to trigger • Adding a timer  dose not stay in the same state forever • Predictive AI • Enemy learn to detect action sequences as he fights us • FSM plus correlation approach • Higher-difficulty enemies • State-space search • Build a graph with all the movement possibilities • Search optimal move sequence • Tabulated representation • A table with a simple attack moves and their associated damage • Ex) Distance = 3 meters, high kick, jump, punch, Damage = 5

  38. Action Based Game • Racing Titles • Implemented by Rule based system • If we are behind another vehicle and moving ->faster advance • If we are in front of another vehicle and moving slower -> block his way • Else -> follow the track • Advance behavior • Using prerecorded trajectory • Plug-in • Analyze the track and generate the ideal trajectory

  39. GameAI(Finite State Machines)

  40. Finite State Machines • Finite State Machines (FSMs) • Also called deterministic finite automata (DFA) or state machine or automata • Definition • A set of states • Represent the scenarios or configurations the AI can be immersed in • A set of transitions • Conditions that connect two states in a directed way • Advantages • Intuitive to understand, Easy to code • Perform well, and represent a broad range of behaviors

  41. Give him a born HENGRY QUIET After 4 hours Finite State Machines • Example • A dog is HUNGRY • If you give him a bone, he will not be hungry anymore • He’ll be QUIET after eating the bone • And he’ll become hungry after four hours of being quiet • States (using circles)  1 and 3 • Transitions (using lines) 2 and 4

  42. Attack E, -D E E -E E D Chase S, -E, -D Wander -E, -S, -D S -S D D -E S Code … … Action (callback) performed when a transition occurs Example FSM Events: E=Enemy Seen S=Sound Heard D=Die Problem: No transition from attack to chase Spawn D

  43. Attack-S E, -D, S Attack E, -D, -S S -S -E E D E -E E Wander -E, -S, -D -S D -E Example FSM - Better Events: E=Enemy Seen S=Sound Heard D=Die D Chase S, -E, -D S D S Spawn D

  44. Example FSM with Retreat Attack-ES E,-D,S,-L Retreat-S -E,-D,S,L Attack-E E,-D,-S,-L S L -S L -L E Events: E=Enemy Seen S=Sound Heard D=Die L=Low Health Each feature with N values can require N times as many states -E E -L Retreat-ES E,-D,S,L Wander-L -E,-D,-S,L E -L E L -S -L L S Retreat-E E,-D,-S,L Wander -E,-D,-S,-L -E -E E D D Chase -E,-D,S,-L D D Spawn D (-E,-S,-L) S

  45. Pick-up Powerup Start Turn Right Go-through Door Hierarchical FSM Attack • Expand a state into its own FSM Wander E/-E Chase S/-S Die Spawn

  46. Approach .3 Aim & Slide Right & Shoot .3 .3 .4 .3 .4 Aim & Slide Left & Shoot Aim & Jump & Shoot Non-Deterministic HierarchicalFSM (Markov Model) Wander Attack No enemy Start Die Start

  47. FSM Evaluation • Advantages: • Very fast – one array access • Can be compiled into compact data structure • Dynamic memory: current state • Static memory: state diagram – array implementation • Can create tools so non-programmer can build behavior • Non-deterministic FSM can make behavior unpredictable • Disadvantages: • Number of states can grow very fast • Exponentially with number of events: s=2e • Number of arcs can grow even faster: a=s2 • Hard to encode complex memories

  48. Decision Trees

  49. Classification Problems • Task: • Classify “objects” as one of a discrete set of “categories” • Input: set of facts about the object to be classified • Is today sunny, overcast, or rainy • Is the temperature today hot, mild, or cold • Is the humidity today high or normal • Output: the category this object fits into • Should I play tennis today or not? • Put today into the play-tennis category or the no-tennis category