# Re: [pygame] car game AI

The name of the algorithm you might find most useful here is "A-star" path-finding (also sometimes written as "A*").
```
```
I recall there was an article I found really useful on the gamasutra website some years ago. I think it was this one:
```Smart Move: Intelligent Path-Finding
http://www.gamasutra.com/view/feature/3317/smart_move_intelligent_.php
Without reading it I'm not sure though. It might have been this:
Toward More Realistic Pathfinding
http://www.gamasutra.com/view/feature/3096/toward_more_realistic_pathfinding.php

There is a good quick intro on Wikipedia:
http://en.wikipedia.org/wiki/A*_search_algorithm
http://www.policyalmanac.org/games/aStarTutorial.htm

There are some tutorials on YouTube too:

Nathan BIAGINI wrote:
```
```Hi,
i'm still writing my car game and now i need to think about implementing
an AI. I searched on the internet for any ressources concerning AI in
car games and i found some post about steering behaviors from Craig
Reynolds : http://www.red3d.com/cwr/steer/. It seems to be exactly what
i need but i don't know yet how to exploit this behaviors for my AI.
At the moment, here is my idea to simulate autonomous car behaviors :

* I split my circuit into area. Areas are positionned at each turn of
the circuit.
* I create a path by randomly choosing one point per area
* Then i create a kind of "lure" and make it moves along the path at
constant speed (no acceleration and no decceleration). The lure is
actually invisible and it will only be used for showing to the
attached car the right direction to take
* Then i create a new car that will always steer to that lure, the car
speed will be lower than the lure one just to make the moves more
realistic. The distance between car and lure must stay between 0 and
CONSTANT (here is a constant value arbitary choosen). When the
distance exceed the CONSTANT value, the lure is stopped until the
car get close enough to the lure.

I thought to do it this way to manage case where the car struck another
car or whatever and is projected away, as the lure is virtual, the car
will always be able to reajust his trajectory by steering to the lure
position.
The problem i have now is to deal with obstacles. My circuit have some
obstacles so i need to consider them in my AI. So i though to use some
obstacle avoidance behaviors and top on the path following. Note the i
use the "steer" behavior illustrated by Craig Reynolds for the lure and
the car, the lure seek the next point of the path and the car seek the lure.
Here is my code without obstacle avoidance : http://pastebin.com/SqN1dJJ6
So please tell me what you think of my way to do (this is the first time
i have to write this kind of AI). If you have idea to improve it and to
how to implement obstacle avoidande, i linkded a diagram to illustrate
the way i think it could works i still need helps for determinating the
components of the force to apply on the car to avoide obstacle.
I hope i was clear enough, thanks.
```
```

--
If you don't have any failures then you're not trying hard enough.
- Dr. Charles Elachi, director of NASA's Jet Propulsion Laboratory
-----
Website: http://miriam-english.org
Blogs:   http://miriam-e.dreamwidth.org
http://miriam-e.livejournal.com

```