Advertisement

AI for continuous snake game (trying NEAT algorithm)

Started by May 12, 2014 08:55 PM
14 comments, last by rouncer 10 years, 4 months ago

1 min 11s

Really silly though as that's not what I'm trying to optimize it for, and it's not fun.

It'd probably kick a human ass at that game though

From the video I can see two places where you can probably just tweak it a bit:

  1. Directions - I could suggest that you add in a randomly generated value representing 3 states (left, straight, right), it may do unexpectedly good behaviors for the A.I. snakes. This can be applied if it is close in contact with the obstacles.
  2. Minimum distance - I see that you didn't calculate 2 sides (left and right sides) of the A.I. snake when both sides have obstacles near its head. Perhaps, I can suggest that you can take the mean average distance between the left and right side, and try to make the A.I. snake aim at that spot, so that it can barely touch the obstacles and can still keep going.
Advertisement

Hey Tom thanks! It's a bit hard to understand your grammar but here's my interpretation:

1. You're suggesting that I add a random input when the snake is near obstacles ? That sounds like a bad idea, how could it learn from it ?

2. You're suggesting that I find the direction of the middle of the hole in front of the snake and use that as an input ? The intuition is ok on that one, but this sounds quite fiddly. Also I would think that my smart ray pointing straight ahead already does that.

Of course I'm quite eager for more suggestions, silly or not, thanks!

Sorry for not replying soon enough. We had drills needed to do here.

  1. Not really. When there aren't any obstacles nearby, it keeps going in a straight line. Once it detects a presence of an obstacle, it randomly chooses to go either left or right of the obstacle. The moment the obstacle is outside of its detection, it goes in a straight line, and repeat the procedures if it detects another presence again and avoids it before colliding it.
  2. After 2 or more tries of avoidance, it learns by delaying the turning, so that it can do sharp bank turns or be couragious when it comes close to an obstacles.
  3. If the snake detects 2 or more than 2 obstacles within its detection range, take the mean average of two closest obstacles to the head, and make the head go straight towards it, and then return to its original state. I need a GIF to demonstrate.

uzWsKlv.gif

Cheers, love the animated gif:)

1. 'it randomly chooses to go either left or right of the obstacle'

Ok, imagine I look at a bunch of pixels in front of the snake, if I see some becoming non empty, then it chooses to go left or right of the obstacle. This is very fiddly, or at least your explanation would need a lot of work to make it into something programmable. If I look at a line of pixels in front of the snake and detect some pixels as occupied (not necessarily 1 interval, but possibly any combination of those pixels, edit: OK this is probably addressed in your 3.), then how exactly do I decide to go left of them ? Just go completely left/right of its field of vision. Also the turning radius needs to be taken into account, so not only this pixel line need to be taken into account, but also all the pixels in my planned trajectory. Also this algorithm doesn't look at anything after this line. Anyway I think about it, this doesn't sound programmable actually.

2. 'After 2 or more tries of avoidance, it learns by delaying the turning'

Maybe this addresses some of the shortcomings in 1. But I'm not exactly sure how

3. Ok this means go in the middle of the obstacles in the front if it can't go left or right. But again this has no knowledge of anything else than the line in front of you so it wouldn't be very smart. Here I included an image (excuse the drawing skills) showing that the snake could go straight into an obstacle in that case. I know it's a very specific example but I'm pretty sure an algorithm like that just wouldn't work in the general case

Again thanks for the input! But I think your approach is too simplistic.

I tried a very interesting different approach a few years ago that I'll post here (didn't manage to export the gmail thread today).

i (as in myself) wouldnt use neat, i dont believe in genetic algorythms.

What I would do, is put some "sight" into a set of inputs, like your doing now, with those hairs, its best it always knew where the opponent was, maybe even what part of the screen he was. the difficult thing would hes only aware of some of the lines there.

If youd like to do it like this yet still speculation of mine ->

now youve got that, just randomize a function that leads to left and right directions.

ok, if you do that, youll have to wait ten million years for him to learn a single step, cause you cant justify any of its learning yet. its based apon success of wins, so youd have to wait for a whole game to finish to even judge a single randomization.

what you have to do is form a rule for your play, in the form of a function watching your outputs, but giving you the sight that he has, cause he pretends you play like him, except you cheat and see the whole thing in detail.

ok, to actually justify the mutation, you have to play games in high speed of him, and the function that is "dummying" you, the more you speed it up the quicker hell be able to justify its behaviour as successful or a failure. the length of time it takes for him to lose or win (on a pole) would be how you would score it.

This topic is closed to new replies.

Advertisement