AI for snake game with steering ?

Started by
5 comments, last by vlad2048 12 years, 12 months ago
The gameplay in my game is pretty innovative. It's what it says in the title, like a snake game but with a couple of twists that make it really different:
- you drive the snake like a car (no 90 degree turns). so you draw smooth curves and you can accelerate and deccelerate
- the snake always grows up. So the games never last that long
- a couple of bouncing balls clear segments of our paths so we can sneak back in.
- you win by staying alive and getting the other snakes to crash into someone's trajectory (classic)

It's a multiplayer game, but it'd be great if I could implement some AI controlled snake.
I'd like the AI to try and cut the player's path. So it should do some reasoning like:
My speed is higher than the opponent, I'm close enough to him and there's a clear path --> So I can turn and cut his path

Is there such a thing as cutting someone's path steering behavior ?
How would I handle the very dynamic obstacle landscape (trails always grow and sometimes holes are created in them) ?

If I discretize my game area in smaller squares, I could use the A* algorithm to reach a point, should I use that somehow to calculate the "cut his path" strategy ?
What areas of AI should I look into ? Neural networks maybe ?

Let me know if I'm not being clear, thanks !
Advertisement
what if you thought of the head of the ai snake being what you want to control. Just make it so it steers away from the player. ie take it's current path, and check if it will collide with the player. if so then find a different path. Implement A* may be a bit over kill for this.

You could make it a little more advance than that too, and track the players movements. Then test if the player continues on it's current path, will the ai collide with the player. if so then find another path.

also this sounds alot like tron :)
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.

what if you thought of the head of the ai snake being what you want to control. Just make it so it steers away from the player. ie take it's current path, and check if it will collide with the player. if so then find a different path. Implement A* may be a bit over kill for this.

You could make it a little more advance than that too, and track the players movements. Then test if the player continues on it's current path, will the ai collide with the player. if so then find another path.

also this sounds alot like tron :)


Thanks freeworld ! Yes I'm thinking indeed about the head as what is to control.
What you're describing here is a defensive strategy in my game (avoid the other snakes). I'll probably start with that.

But ideally I'd like the AI to have an aggressive strategy (cut the other snake's paths when the occasion arise)
Also sometimes you can end up in a real maze of snake trails, so I would need some kind of pathfinding (navigate the maze towards the biggest clutter free area or towards an ennemy and then try to be aggressive again)

I'll try first the simple evasive approach you described freeworld, better start simple here.
I've done a little prototype in C# and implemented this "avoid the walls" strategy. Here's a video:

http://www.youtube.c...h?v=oKm-C36y_0k
I'm very happy with it :D

The AI casts 7 rays (100 pixels long) in front of the snake from -60 to +60 degrees.
If the front ray detects a wall, then I'll do
wallLeft = average of the 3 left rays
wallRight = average of the 3 right rays
wallLeft and wallRight now give us a good measure of how close the obstacles are on the left and right
So now if wallLeft < wallRight then I turn right and vice-versa

As you can see, the AI avoids the walls really well but it's too passive.
Basically it cannot foresee that I'm going to trap it into a wall and crashes into me in the end.

This seems like a very hard problem to me.
I have some ideas, what do you guys think about them ?

1) Do simulations of the future:
- simulate what happens in 60 frames if the player continues straight
- simulate what happens in 60 frames if the player turns left
- simulate what happens in 60 frames if the player turns right
if any of these 3 scenarios mean the ai crashes, then consider right now an exit strategy (eg: turn 100 degrees in the right direction)
This might make it a bit smarter but it's only a rough approximation of a good strategy.

2) Make the AI aggressive when it's not avoiding a wall, try to crash into the player
Do you have any ideas how I could concretely do that ?

3) Cheat a bit: make the AI a bit faster, take sharper turns than the player
I'd rather look for a proper solution first

So what do you think about these ?
Do you guys have any other ideas ?
What fields of AI could I use here ? It seems way too hard for neural networks ?
There was a Google AI Challenge that was about Tron last year, and it seems very similar to this....

Here's what the winner wrote about his implementation.

Alex

Join us in Vienna for the nucl.ai Conference 2015, on July 20-22... Don't miss it!


There was a Google AI Challenge that was about Tron last year, and it seems very similar to this....

Here's what the winner wrote about his implementation.

Alex

Hey folks... I was about to ping Alex about not including a link on his post, but it turns out that the formatting is such that it is invisible. The linked text is, indeed, "what the winner wrote". Hover to see the url formatting.


Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Ah yes, thanks guys, I had found the link and contacted the author.
He was very helpful, and basically said that I can apply his exact same algorithm if I cut my space in a grid.

This topic is closed to new replies.

Advertisement