1 / 43

AI on the Racetrack

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

ulfah
Download Presentation

AI on the Racetrack

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AI on the Racetrack By Emily Cohen

  2. Hit the Track! • The first video racing game is said to be by Atari back in 1974 called Grand Track 10 Now: Then:

  3. Bad Racing AI • When competing against AI you should feel challenged • Not so challenging • We are going to talk about the general steps to make a good AI

  4. Start at the Bottom • In order to create a ‘good’ AI we must start from the bottom • Store as much information as possible in the road • Two types of roads: • Race Tracks • Open Street Conditions

  5. Divide it up • Sectors: • The track is divided up into multiple sectors • Defined by a doubly linked list that allows for forward and backward traversal • Connected by Interfaces

  6. Connect the Dots • Interfaces are the basic building blocks of the race track • Define the left and rightmost boundaries • Define possible driving lines • The Sector linked lists point to Leading and Trailing edge Interfaces

  7. Drive on the Line! • Driving lines used to define optimal paths between interfaces • Comprised of: • Forward vector • Right Vector – used to determine how far the car is from the racing line • Planes used to mark boundaries of sector • Use to check if car is in particular sector

  8. Approximating Racing Lines

  9. Approach #1 • Record the path taken by a vehicle while under the control of human player • Good: Fast and efficient way of making accurate approx to racings lines • Bad: can not be used for randomly generated or player created tracks

  10. Approach #2 • Have predefined segments with precompiled racing lines • Good: not to much… • Bad: • Tracks are less random • Racing lines change depending on what comes before and after the current segment

  11. Approach #3 • Lines of Minimum Curvature • Repeatedly apply small forces to every set of three contiguous points • Gradually reduces the curvature

  12. Lines of Minimum Curvature • Good: • Can be approximated quickly, efficiently , and reliably. • Follows true racing lines accurately enough • focuses on finding an approx to the path of minimum curvature • Finds the path the vehicle can travel at max speed • Bad: • Ignores details of the physics of the vehicle • No sense of direction. • Can produce errors in the way approx trades curvature in one part of track off against curvature further along

  13. Just For Fun

  14. Where am I? • It is easy to determine where you are on the track when using sectors. FloastDistAlongSector(const Csector& sector, const vector3& pos) { vector3 delta = pos – sector.drivingLinePos; delta.y = 0.0f; float dist = DotPorduct(sector.drivingLineForward, delta); return (dist * lengthScale); }

  15. More Info Please • Other relevant data about the environment should be stored in each sector • Path Type • Short cut, winding road, weapon pick-up rout etc. • Terrain Type • Rugged terrain • Walls • Hairpin turn • Break/Throttle • -1.0 to +1.0

  16. Now for the AI… • Goal: have the AI produce an output that emulates human input • Basic Framework: • Finite-State Machine • A 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

  17. Now for the AI… - con’t • Controlling the car • Simple structure: • Steering: x  range -1.0 to +1.0 • Acceleration: y  <0.0 = breaking, >0.0 = acceleration • Simplifying with 2D • Project 3D coordinates onto XZ plane by zeroing Y element and then normalizing • This simplifies many calculations

  18. State = STARTING_GRID • The AI must initialize the car • Pass in the starting grid location • Sector pointer should be stored internally as the current and last-valid sectors • Last-valid sector helps to return the car if it is no longer in a sector • When the state is set to STATE_RACING, give little delay before actually starting… more realistic

  19. Weeeee

  20. State = RACING • Use linked list of sectors to traverse the track • Also 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

  21. 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 Ahead • Knowing your come up to a sharp bend • Traverse sectors a certain distance ahead from car’s current position

  22. 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

  23. 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

  24. Get Out of My Way • Overtaking: • As we say before there is an overtaking line • Just use the index of the alternate driving line to follow • Improve 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

  25. Some Other States • STATE_AIRBORN • Some tracks have jumps • Need to prepare the car for a controlled landing • Set steering straight ahead and put acceleration to full • STATE_OFF_TRACK • When car is no longer on in any of the sectors • Keeping track of last valid sector

  26. 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 slower • If weapons involved, AI could only target other AI • What NOT to do

  27. Around Town • Handling Open Street Conditions • Random network of roads and intersections • First need to create a map that the AI can handle

  28. Roads • Roads represent space between two intersections • Straight or Curved • Might include sidewalks with obstacles • Any two roads at an intersection define a sharp turn with an angle between them > 45˚

  29. Roads • Roads represent space between two intersections • Straight or Curved • Might include sidewalks with obstacles • Any two roads at an intersection define a sharp turn with an angle between them > 45˚

  30. Navigating the City • Figure 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 Cache • Includes current and next two road segments defined by primary route

  31. Navigating the City… con’t • Enumerate all possible routes for traversing road segment • Route planning distance • Longer • provide better choices, see potentially blocked routes • Uses up more CPU time

  32. Watch Out • Obstacle map: • Bucket system for organizing obstacles on the road • Breaks the road into smaller subsections • Intersections are defined as an obstacle bucket • When a collision happens: • Vehicle is completely under control of physics engine • Must backup (if visible)… manually reposition

  33. Buckets

  34. Getting around Obstacle

  35. Handling an Intersection • The arc of a circle defines the path through a sharp turn

  36. How Fast Can I Go? • Usually AI tries to go as fast as possible • Find fastest way to go through sharp turn: • Attain max speed without losing friction v = √μgR Radius Velocity Gravity Coefficient of friction

  37. Breaking • Once you get the target velocity figure out how long before you reach the turn: • Time to Reach the Turn (T) = Distance to Turn/Speed • Then calculate breaking force: • Breaking Force = (Current Speed – Target Speed)/(T*μ*g)

  38. Good ol’ Physics • If 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 Stability • Testing for a Stability • Correcting the Car

  39. Detecting Stability • The 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

  40. Testing for Stability

  41. Correcting the Car • 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

  42. Summary • Sectors, Interfaces and the information stored in the track • Two types of tracks: Race tracks and Open Street conditions • Driving lines, and some ways to generate them • Accounting for a physics engine to correct over and under turning

  43. Questions?

More Related