artificial intelligence for games lecture 1 1 minor games programming

58
Artificial Intelligence for Games Lecture 1 1 Minor Games Programming

Upload: avis-lester

Post on 01-Jan-2016

227 views

Category:

Documents


2 download

TRANSCRIPT

Artificial Intelligence for Games

Artificial Intelligence for GamesLecture 1 1Minor Games Programming2Artificial Intelligence for GamesIntroduction to game AI (self study)Theory: Moving Game Agents

Jan [email protected] AIGame AI is not a subset of AIGame AIoften covers techniques that are not considered AI-likeAIuses techniques impractical in a game context

AIGame AI3What is Game AI?Analogygame AI is to "real" AI asstage design is to architectureThe goal of game AI is to give the impression of intelligenceto avoid the impression of stupidityto provide a reasonable challenge for the player4ChallengeIt is very possible to make the computer too smartthink: driving game or a chess gameThe task of AI is to support the experiencemany compromises from optimal required5Not dumbIt is surprisingly hard to make the computer not dumbWhy are computers so stupid?especially with limited computational resourcesExampleHumans are good at navigating complex 3-D environmentsDoing this efficiently is (still) an unsolved problem in AI

6ButGame AI is the future of gamesMany designers see AI as a key limitationthe inability to model and use emotionthe inability of games to adapt to users abilitiesthe need for level designers to supply detailed guidance to game characters78Study bookLiterature:

Mat Buckland

Programming Game AI by Example

http://www.ai-junkie.com

8What we will coverFinite-state machines (Previous Knowledge !!)the most basic technique for implementing game AIfundamental to everything elseSteering behaviorsbasic behaviors for avoiding stupidity while navigating the worldPath planningthe surprisingly tricky problem of getting from point A to point BAction planningassembling sequences of actionsFuzzy logicreasoning by degrees910Today's Theory: Moving Game Agents,(see study book: chapter 3) What is an Autonomous Agent?Steering BehaviorsGroup BehaviorsCombining Steering BehaviorsSpatial PartitioningSmoothing

11MovementTwo typesReactive movementPlanned movement

11Steering behaviorsTendencies of motionthat produce useful (interesting, plausible, etc.) navigation activityby purely reactive meanswithout extensive predictionPioneering paperReynolds, 199912ExamplesI want the insect monsters to swarm at the player all at once, but not get in each other's way.I want the homing missile to track the ship and close in on it.I want the guards to wander around, but not get too far from the treasure and not too close to each other.I want pedestrians to cross the street, but avoid on-coming cars.13Steering behavior solutionWrite a mathematical rulethat describes accelerations to be madein response to the state of the environmentExample: "don't hit the wall"generate a backwards force inversely proportional to the proximity of the wallthe closer you get, the more you will be pushed awayif you're going really fast, you'll get closer to the wall, but you'll slow down smoothly14Combining forcesBehaviors can be combined bysumming the forces that they produceExample: followI want the spy to follow the general, but not too closetwo behaviorsgo to general's locationcreates a force pointing in his directionnot too closea counter-force inverse proportion to distancewhere the forces balanceis where spy will tend to stay1516Steering Behaviors:Physics Model Simple Vehicle Modelorientation, mass, position, velocitymax_force, max_speed

Forward Euler Integrationsteering_force = truncate (steering_dir, max_force) acceleration = steering_force / mass velocity = truncate (velocity + acceleration, max_speed)position = position + velocity

Read Only Page

1617Steering Behaviors:Seek and FleeSeek Steer toward goalFlee Steer away from goalSteering force is the difference between current velocity and desired velocityBlue is steering force, magenta is velocity

1718Steering Behaviors:Pursue and EvadeBased on underlying Seek and FleePursue Predict future interception position of target and seek that pointEvade Use future prediction as target to flee from(Another Chase and Evade demo)

1819Steering Behaviors:WanderType of random steering with long term orderSteering is related from one frame to anotherMaintains stateRed dot is wander directionConstrained to be on black circleRandomly moves within white circle each frame

1920Steering Behaviors:ArrivalGoal to arrive at target with zero velocityRed circle is maximum distance before slowing down

2021Steering Behaviors:Obstacle AvoidanceWhite box is future pathSteering force strictly left or rightBraking force stronger as collision gets closer

21Obstacle avoidance IIBasic ideaproject a box forward in the direction of motionthink of the box as a "corridor of safety"as long as there are no obstacles in the boxmotion forward is safeTo do thisfind all of the objects that are nearbytoo expensive to check everythingignore those that are behind yousee if any of the obstacles overlap the boxif none, charge aheadif several, find the closest onethis is what we have to avoid22Obstacle avoidance IIISteering forcewe want to turn away from the obstaclejust enough to miss itwe want to slow downso we have time to correctNeed a steering force perpendicular* to the agent's headingproportional to how far the obstacle protrudes into the detection boxNeed a braking force anti-parallel to agent's headingproportional to our proximity to obstacle

* http://en.wikipedia.org/wiki/Perpendicular

2324Steering Behaviors:HideHide attempts to position a vehicle so that an obstacle is always between itself and the agent (the hunter) its trying to hide from

2425Steering Behaviors:Wall FollowingMove parallel and offset from gray areasGoal to remain given distance from wallPredict objects future position (black dot)Project future position to wallMove out from wall set amount from normalSeek toward new point (red circle)

2526Steering Behaviors:Path FollowingPath is connected line segments with radiusCorrective steering only when varying off of pathRed dot future predicted positionRed circle is closest spot on pathCorrective steering toward white circle farther down path

2627Combined Steering Behaviors:Group Path FollowingPath following with separation steeringCombined with weighted sumPath following has 3 times weight as separation

2728Combined Steering Behaviors:Leader Following (Group)Combines separation and arrivalArrival target is a point offset slightly behind the leaderFollowers must move out of leaders future path

2829Combined Steering Behaviors:Leader Following (Queue)Combines separation and arrivalEach object has a different leader

2930Combined Steering Behaviors:Unaligned Collision AvoidanceObjects moving in all directions (unaligned)Combines containment and avoidanceFuture collisions predicted and objects steer away from collision site, or speed-up / slow-down

3031Combined Steering Behaviors:QueuingSeek doorway, Avoid gray walls, Separation from each other, Braking if others nearby or in front

3132Flocking

3233Flocking

3334Flocking

3435FlockingFirst demonstrated by Craig Reynolds in his 1987 SIGGRAPH paper and movieFlocks, Herds, and Schools: A Distributed Behavior ModelFilm (Stanley and Stella in "Breaking the Ice"Used to give flocks of birds and schools of fish eerily realistic movementWon an Oscar in 1997 for his flocking work (Scientific and Technical Award)Flocking is an example of emergent behavior (a-life)Simple individual rules result in complex group behaviorIndividual creatures often called boidsPS2 technical demoOpenSteer demo

3536Flocking:Three simple rulesSeparation

Alignment

Cohesion

36Separation"Don't crowd"Basic ideagenerate a force based on the proximity of each other agentsum all of the vectorsResultEach agent will move in the distance that takes it furthest from othersNeighbors disperse from each other37Alignment"Stay in step"Basic ideakeep an agent's heading aligned with its neighborscalculate the average heading and go that wayResultthe group moves in the same direction38Cohesion"Stay together"Basic ideaopposite of separationgenerate a force towards the center of mass of neighborsResultgroup stays together39Combining these behaviorsWe get flockingdifferent weights and parameters yield different effectsanimationdemo40Implementation issuesCombining behaviorseach steering behavior outputs a forceit is possible for the total force to exceed what an agent's acceleration capacityWhat to do?41Combination methodsSimplest: Weighted truncated sum,weight the behaviors, add up, and truncate at max_forcevery tricky to get the weights rightmust do all of the calculationsBetter: PrioritizationEvaluate behaviors in a predefined orderobstacle avoidance firstwander lastKeep evaluating and adding until max_force reachedProblem is getting the fixed priority rightCheaper: Prioritized ditheringAssociate a probability with each behaviorprobabilities sum to 1That behavior will get its force applied a certain percentage of the time42PartitioningWe want to calculate the neighbors of each agentif we look at all agents, n2 operationif there are many, many agents, too slowMany techniques for speeding this upbasic idea is to consider only those agents that could be neighborscarve up space and just look at the relevant bitsVery important in other parts of game programming, toocollision detectionview rendering43Cell-space partitionCover space with a gridMaintain a list of agents in each cellnot that expensive since it is just an x,y threshold testCalculate which grid cells could contain neighborscheck only those agents in the effected cellsO(n)

44SmoothingJitter occurs when behaviors switch in and outobstacle avoidance kicks in when objects is in detection boxbut other behaviors push back towards obstacleSolutionaverage the heading over several updates

Read study book for a solution or take notice of: http://blogs.msdn.com/shawnhar/archive/2007/04/23/hysteresis.aspx

4546Alternative to Flocking:Simple SwarmsComputationally simplerDoesnt enforce separation or interpenetrationExampleHundreds of spiders crawling around, up walls, and dropping from the ceiling Tom Scutt, Tomb Raider series

4647Simple Swarmsattacking PlayerOuter zoneIf heading toward player: waver headingIf heading away: steer toward playerInner zoneSwirl around playerFlee after random amount of time

4748Swarm IntelligenceTechnique based on collective behavior in decentralized, self-organized systemsBeni & Wang (1989)Simple agents interact locallyGlobal behavior emergesAnt coloniesBird flockingAnimal herdingSwarm RoboticsCombining swarm intelligence with robotics4849FormationsMimics military formationsHow is it similar to flocking?How is it different from flocking?

49How is it similar to flocking?1. Three flocking rules seem related

How is it different from flocking?1. Not emergent behavior2. Each member is told exactly where to go.3. Someone is leading the formation50FormationsIssuesIs there a leader?Where do individuals steer towards?What happens when they turn?What happens when they change heading by 180 degrees?What happens when there is a narrow pass?Formation splitting and reforming?5051Math and PhysicsDo you remember your Math and Physics?

If needed: Read and recall chapter 1 of the study book5152Steering Behaviors(see demo programs!)SeekFleeArrivePursuitEvadeWanderObstacle AvoidanceWall AvoidanceInterposeHidePath FollowingOffset Pursuit5253Group Behaviors (see demo programs!)SeparationAlignmentCohesionFlocking5354Combining Steering Behaviors (see demo programs!)Weighted Truncated Sum.. With PrioritizationPrioritized DitheringEnsuring Zero Overlap5455And finally (see demo programs!)Spatial PartitioningSmoothing5556Homeworkpart 1HomeworkStudy chapter 3 of your study book. (Study behaviors description and algorithms; read code, browse math and physics and run demos).

Run the demo programs: Seek, Flee, Arrive, Pursuit, Wander, Obstacle Avoidance, Interpose, Hide, Path Following, Offset Pursuit, Flocking, Non Penetration Constraint and Big Shoal, Another Big Shoal and Another Big Shoal with Smoothing.

5657Homeworkpart 2Homework (in couples of 2 students)Run the amazing program SteeringCS (see blackboard)

Modify this program: Implement LEADER FOLLOWING and EXPLORE (see Blackboard for details)

You need your solution at next AI practice, so be sure to take your files with you.

5758PracticeThe practice will be:

Implement one or more steering behaviors using the steering C# project of your homework. Which ones will be told.

In same student couples

58