Code-Bullet / SnakeFusion

Using the genetic algorithm and neural networks I trained up 5 snakes who will then fuse to become the ultimate snake, this is how I did it
789 stars 214 forks source link

How to use use? #3

Open TheOnlyPixels opened 6 years ago

TheOnlyPixels commented 6 years ago

How do I train the snakes in 0-4? They always do the same moves and die at almost the same spots. It doesn't seem like they're learning anything.

DerAchmet commented 6 years ago

i dont know either somebody pls explain

human-0 commented 6 years ago

Use this fork, it has instructions: https://github.com/turboxx/SnakeFusion/commit/2da3088b1d9512af07b424decba6faea225e8d73

Trikos commented 6 years ago

Hi, I tried this code and rewrite the Genetic Algorithm and also Fitness function, but my snake still nedd at least 100 Gen to avoid 1 or 2 wall in a row and eat 1 apple then other 200+ gen to do other super simple movement! Somebody can help me? Maybe @Code-Bullet! I saw different times your first video on youtube and Im 100% sure that you dont use this code! Hope in a reply with further instruction, or maybe in an commit that modify all the stuff :D Thank you pals

Xenossolitarius commented 6 years ago

I ve also made my own neural net and made some tweaks to his code but all in all its working (more or less). The issue is you need to get lucky with a random seed. While I was testing his setup i noticed that if you don't get the fitness/score as he did in the video you can just stop the training. But if you get "lucky" which happens actually alot you will see the same results as him. Sooo just keep restarting the 100 generations until you see like 11 or 12 apples eaten. Hope this helps :D Btw. you should try implementing elitism ( about 10%) because I 've noticed it is helping alot with the results in combination with higher 5% mutation rate.

Trikos commented 6 years ago

@Xenossolitarius Hey, thanks for reply! Anyway I dont know what is elitism but im saure that a 5% mutation rate is a bit high. Anyway can you post your code here on github or just send it to me? Really appreciate

Xenossolitarius commented 6 years ago

@Trikos Actually I would be glad to help 👍 because it took me ages with the same problem. I can send code to you, no problem. It works for me with no changes but yesterday at 2 am I wrote a much better fitness function. Where can I send you the code ? ( C#)

Trikos commented 6 years ago

Can you publish it on your profile???

Xenossolitarius commented 6 years ago

nah I will keep it to my self but ill give you the changes and directions here: https://pastebin.com/MEchCRUS

Trikos commented 6 years ago

Man appreciate your help but I get some part of your code not working cause I cant see the other code! SnakePart stop the executation! I think you mean a PVector with SnakePart

SparshaSaha commented 6 years ago

Hi, I tried this code and rewrite the Genetic Algorithm and also Fitness function, but my snake still nedd at least 100 Gen to avoid 1 or 2 wall in a row and eat 1 apple then other 200+ gen to do other super simple movement! Somebody can help me? Maybe @Code-Bullet! I saw different times your first video on youtube and Im 100% sure that you dont use this code! Hope in a reply with further instruction, or maybe in an commit that modify all the stuff :D Thank you pals

@Trikos , buddy why don't you use python where a prebuilt Neuro Evolution of Augmented Topologies (NEAT) library is availiable and you don't have to ge into the details of writing all the mutation and crossover stuff by yourself. I have used it and it pretty much works cool.. You can find more information regarding NEAT here: https://neat-python.readthedocs.io/en/latest/

You can find the game-AI that i have made using NEAT here: https://github.com/SparshaSaha/Self-Playing-AI-Bot-using-Evolutionary-Algorithms

Trikos commented 6 years ago

Well, currently I have no info about NEAT but instead I study the Q-Learning which is really bad for Snake, taking a life to learn how to play cause of Fitness function and the super space of solution! Or maybe Im not doing it well (more probably). Im not a Python program and I never used it yet so I will have some struggle to understand Python Syntax then the Algorithm, but I will take a look and try to implement it! Thank you for suggestion and the code mate!

SparshaSaha commented 6 years ago

@Trikos I think you're gonna find that learning python is pretty much the easiest job on the planet.. And i'm pretty sure that you're gonna love python.. Anyway.. Good luck!! :)

Vortetty commented 5 years ago

@Trikos I think you're gonna find that learning python is pretty much the easiest job on the planet.. And i'm pretty sure that you're gonna love python.. Anyway.. Good luck!! :)

it is one of the best beginner languages, very versatile too.