• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
vlad2048

AI for continuous snake game (trying NEAT algorithm)

15 posts in this topic

Ah, very interesting article thanks, I'll read it carefully tomorrow for insights.

Basic avoidance steering would work to avoid obstacles, but it'd be pretty stupid indeed.

 

A good player needs to:

1) Avoid walls. Your two suggestions address that.

2) Notice occasions when it can 'cut short' the other one (when next to him a bit ahead).

3) Avoid getting 'cut short'.

4) Also ideally a great player would need an idea of the topology of the current 2d space to try to enclose the other one in a smaller space / safeguard himself a bigger space.

 

My approach seems to have potential indeed as it starts to exhibit 1), 2) and 3). I wonder what other kind of inputs I could give the neural network though...

Also for some reason, my networks do not evolve any hidden neurons so far. I probably need to get more familiar with the NEAT algorithm.

1

Share this post


Link to post
Share on other sites

Ah, very interesting article thanks, I'll read it carefully tomorrow for insights.

Basic avoidance steering would work to avoid obstacles, but it'd be pretty stupid indeed.

 

A good player needs to:

1) Avoid walls. Your two suggestions address that.

2) Notice occasions when it can 'cut short' the other one (when next to him a bit ahead).

3) Avoid getting 'cut short'.

4) Also ideally a great player would need an idea of the topology of the current 2d space to try to enclose the other one in a smaller space / safeguard himself a bigger space.

 

My approach seems to have potential indeed as it starts to exhibit 1), 2) and 3). I wonder what other kind of inputs I could give the neural network though...

Also for some reason, my networks do not evolve any hidden neurons so far. I probably need to get more familiar with the NEAT algorithm.

 

You might be able to simulate some of the 2nd and 3rd points with basic steering.  If the AI is ahead of the opponent, instead of avoidance, it could have an attractive parallel force, while if it is behind someone, it could have a repulsive force to the player.  Though there would be no way to do 4.

 

Or it might just end up a fiddly mess =)

 

I look forward to seeing how the NEAT algorithm does though, and it looks promising.

Edited by ferrous
1

Share this post


Link to post
Share on other sites

I can't contribute sadly having never heard of NEAT before, but i'd be interested in reading about your progress smile.png

(also the exe would be nice)

Edited by SerialKicked
0

Share this post


Link to post
Share on other sites

Sure, I've added the .exe in the first post. Let me know how it works for you !

 

I've not made huge progress really, I've been mostly playing with the parameters.

I got some ideas for new inputs, I'll post again when I implement them!

1

Share this post


Link to post
Share on other sites

Thanks, It worked perfectly (Win7 4core AMD CPU -> used 100% with evo on)

 

A few things i noticed, no idea if it's of any use to you:

 

I've not played extensively and in general it tries to get the same spiral pattern you described earlier.

 

However, on my first go, its behavior was pretty weird, maybe because I died a few times stupidly at the beginning of the round (getting used to the lag, a sleep somewhere would help a bit). Maybe it reached an evolutionary dead end, I dunno. Anyway, even after 150+ generations its go-to behavior was to draw a simple circle and kill itself. After a few rounds it tried to go for a spiral again and / or follow me, failed and back to the circle for a few more rounds (rinse and repeat).

 

The graph was still getting fairly complicated, with all top nodes connected to the bottom ones and several additional nodes created in the middle. I probably should have taken a screenshot, sorry i forgot.

 

When it gets a good generation, it can be a fun opponent indeed, much less predictable than what you'd usually expect in this kind of game.

Edited by SerialKicked
0

Share this post


Link to post
Share on other sites

If there is only 1 AI snake on the gamefield and no players, what the longest survival time it can reach?

Edited by tom_mai78101
0

Share this post


Link to post
Share on other sites

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

https://www.youtube.com/watch?v=Y02tXQPjjAY

0

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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

Edited by vlad2048
1

Share this post


Link to post
Share on other sites

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.

-2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0