43
AI on the Racetrack By Emily Cohen

AI on the Racetrack

  • Upload
    ulfah

  • View
    41

  • Download
    0

Embed Size (px)

DESCRIPTION

AI on the Racetrack. By Emily Cohen. Hit the Track!. The first video racing game is said to be by Atari back in 1974 called Grand Track 10. Now:. Then:. Bad Racing AI. When competing against AI you should feel challenged Not so challenging - PowerPoint PPT Presentation

Citation preview

Page 1: AI on the Racetrack

AI on the RacetrackBy Emily Cohen

Page 2: AI on the Racetrack

Hit the Track!The first video racing game is said to be by

Atari back in 1974 called Grand Track 10

Then:Now:

Page 3: AI on the Racetrack

Bad Racing AIWhen competing against AI you should feel

challengedNot so challenging

We are going to talk about the general steps to make a good AI

Page 4: AI on the Racetrack

Start at the BottomIn order to create a ‘good’ AI we must start

from the bottomStore as much information as possible in the

road

Two types of roads:Race TracksOpen Street Conditions

Page 5: AI on the Racetrack

Divide it upSectors:

The track is divided up into multiple sectors Defined by a doubly linked list that allows for

forward and backward traversal Connected by Interfaces

Page 6: AI on the Racetrack

Connect the DotsInterfaces are the basic building blocks of the

race trackDefine the left and rightmost boundariesDefine possible driving linesThe Sector linked lists point to Leading and

Trailing edge Interfaces

Page 7: AI on the Racetrack

Drive on the Line!Driving lines used to define optimal paths

between interfacesComprised of:

Forward vector Right Vector – used to determine how far the car is

from the racing linePlanes used to mark

boundaries of sectorUse to check if car

is in particular sector

Page 8: AI on the Racetrack

Approximating Racing Lines

Page 9: AI on the Racetrack

Approach #1Record the path taken by a vehicle while

under the control of human playerGood: Fast and efficient way of making

accurate approx to racings linesBad: can not be used for randomly generated

or player created tracks

Page 10: AI on the Racetrack

Approach #2Have predefined segments with precompiled

racing linesGood: not to much…Bad:

Tracks are less randomRacing lines change depending on what comes

before and after the current segment

Page 11: AI on the Racetrack

Approach #3Lines of Minimum CurvatureRepeatedly apply small forces to every set of

three contiguous pointsGradually reduces the curvature

Page 12: AI on the Racetrack

Lines of Minimum CurvatureGood:

Can be approximated quickly, efficiently , and reliably.Follows true racing lines accurately enough focuses on finding an approx to the path of minimum

curvatureFinds the path the vehicle can travel at max speed

Bad:Ignores details of the physics of the vehicleNo sense of direction.Can produce errors in the way approx trades curvature

in one part of track off against curvature further along

Page 14: AI on the Racetrack

Where am I?It is easy to determine where you are on the

track when using sectors.

Floast DistAlongSector(const Csector& sector, const vector3& pos){

vector3 delta = pos – sector.drivingLinePos;delta.y = 0.0f;float dist =

DotPorduct(sector.drivingLineForward, delta);return (dist * lengthScale);

}

Page 15: AI on the Racetrack

More Info PleaseOther relevant data about the environment

should be stored in each sectorPath Type

Short cut, winding road, weapon pick-up rout etc.Terrain Type

Rugged terrainWallsHairpin turnBreak/Throttle

-1.0 to +1.0

Page 16: AI on the Racetrack

Now for the AI…Goal: have the AI produce an output that

emulates human inputBasic Framework:

Finite-State MachineA Fixed Time-Step

Changing the Time-Step can cause issues because AI might miss breaking points, or react to late to obstacles if the time-step is to long

Page 17: AI on the Racetrack

Now for the AI… - con’tControlling the car

Simple structure: Steering: x range -1.0 to +1.0 Acceleration: y <0.0 = breaking, >0.0 =

accelerationSimplifying with 2D

Project 3D coordinates onto XZ plane by zeroing Y element and then normalizing

This simplifies many calculations

Page 18: AI on the Racetrack

State = STARTING_GRIDThe AI must initialize the car

Pass in the starting grid locationSector pointer should be stored internally as

the current and last-valid sectorsLast-valid sector helps to return the car if it is

no longer in a sectorWhen the state is set to STATE_RACING, give

little delay before actually starting… more realistic

Page 20: AI on the Racetrack

State = RACINGUse linked list of sectors to traverse the trackAlso helps keep track of the car…

If the car can’t be found on a sector that means it is probably lost somewhere

For that you switch to STATE_OFF_TRACK

Page 21: AI on the Racetrack

What to do?Split Decisions

Deciding what way to go when you have two paths

Combination of AI’s current needs and path info

Anticipating the Road AheadKnowing your come up to a sharp bendTraverse sectors a certain distance ahead from

car’s current position

Page 22: AI on the Racetrack

Turn Quick!Hairpin turns:

Looking ahead can cause issues with hairpin turns

Mark sectors as “hairpin left” or “hairpin right” Cut the search short

The AI will continue to target the start of the first sector. Once the minimum search distance is reached, the AI will then target the driving line ahead by this distance. Result: The AI targets the first marked sector while

breaking to a reasonable speed, and then following the corner when close enough

Page 23: AI on the Racetrack

Turn Quick!Hairpin turns:

Looking ahead can cause issues with hairpin turns

Mark sectors as “hairpin left” or “hairpin right” Cut the search short

The AI will continue to target the start of the first sector. Once the minimum search distance is reached, the AI will then target the driving line ahead by this distance. Result: The AI targets the first marked sector while

breaking to a reasonable speed, and then following the corner when close enough

Page 24: AI on the Racetrack

Get Out of My WayOvertaking:

As we say before there is an overtaking lineJust use the index of the alternate driving line

to followImprove upon the AI’s over taking ability by

creating multiple overtaking lines.Chose appropriate line based on other car’s

relative position and what line is on the inside corner

Page 25: AI on the Racetrack

Some Other StatesSTATE_AIRBORN

Some tracks have jumpsNeed to prepare the car for a controlled

landingSet steering straight ahead and put

acceleration to fullSTATE_OFF_TRACK

When car is no longer on in any of the sectorsKeeping track of last valid sector

Page 26: AI on the Racetrack

Catch up!If the AI is doing “too well”

Limit AI’s top speed to proportion to how far it is in the lead

Break earlier for corners and accelerate slowerIf weapons involved, AI could only target other

AIWhat NOT to do

Page 27: AI on the Racetrack

Around TownHandling Open Street Conditions

Random network of roads and intersectionsFirst need to create a map that the AI can

handle

Page 28: AI on the Racetrack

RoadsRoads represent space between two

intersectionsStraight or CurvedMight include sidewalks with obstacles

Any two roads at an intersection define a sharp turn with an angle between them > 45˚

Page 29: AI on the Racetrack

RoadsRoads represent space between two

intersectionsStraight or CurvedMight include sidewalks with obstacles

Any two roads at an intersection define a sharp turn with an angle between them > 45˚

Page 30: AI on the Racetrack

Navigating the CityFigure out what road or intersection car is on

Can then determine the relative location in the primary route

Plan immediate rout to navigate up coming obstacles

Update Road CacheIncludes current and next two road segments

defined by primary route

Page 31: AI on the Racetrack

Navigating the City… con’tEnumerate all possible routes for traversing

road segmentRoute planning distance

Longer provide better choices, see potentially blocked

routes Uses up more CPU time

Page 32: AI on the Racetrack

Watch OutObstacle map:

Bucket system for organizing obstacles on the road

Breaks the road into smaller subsectionsIntersections are defined as an obstacle bucket

When a collision happens:Vehicle is completely under control of physics

engineMust backup (if visible)… manually reposition

Page 33: AI on the Racetrack

Buckets

Page 35: AI on the Racetrack

Handling an IntersectionThe arc of a circle defines the path through a

sharp turn

Page 36: AI on the Racetrack

How Fast Can I Go?Usually AI tries to go as fast as possibleFind fastest way to go through sharp turn:

Attain max speed without losing friction

v = √μgRVelocit

yCoefficient of friction

Radius

Gravity

Page 37: AI on the Racetrack

BreakingOnce you get the target velocity figure out

how long before you reach the turn:Time to Reach the Turn (T) = Distance to

Turn/SpeedThen calculate breaking force:

Breaking Force = (Current Speed – Target

Speed)/(T*μ*g)

Page 38: AI on the Racetrack

Good ol’ PhysicsIf the car is modeled with even a basic

physics simulator the car will be subjected to under-steering and over-steering.This causes spinning and missing a turn

3 Steps:Detect the Car’s StabilityTesting for a StabilityCorrecting the Car

Page 39: AI on the Racetrack

Detecting StabilityThe stability can be determined by a few

comparisons of the sideways velocities of each wheel

Find the dot product of the velocity of the wheel and the unit-length right direction of its orientation

Page 40: AI on the Racetrack

Testing for Stability

Page 41: AI on the Racetrack

Correcting the CarCase Velocity

SignsCorrection

Under-Steer

Same Abs(FrontVel + RearVel)/UndersteerRange

Over-Steer 1

Same Abs(FrontVel - RearVel)/OversteerRange

Over-Steer 2

Different (Abs(RearVel)-Abs(FrontVel))/OversteerRange

Summed velocities divided by range factor – this reduces the correction amount to a value between 0 and 1

Correction value should be added or subtracted from the current steering positions depending on sign on dx

Page 42: AI on the Racetrack

SummarySectors, Interfaces and the information

stored in the trackTwo types of tracks: Race tracks and Open

Street conditionsDriving lines, and some ways to generate

themAccounting for a physics engine to correct

over and under turning

Page 43: AI on the Racetrack

Questions?