Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AI and Deep Learning by (50.2k points)

I'm trying to implement an AI for a game of 'continuous snake'. It's very different from a normal snake game, at least as far as the AI is concerned. Basically, the snake drives a bit like a car and the first one of the 2 players to crash into his trail or the other's trail loses the game. Also, the screen wraps around its borders.

You can understand it better if you look at a video of my current progress:

It's not too bad, but it still can't beat me (I'm yellow). A winning AI would ideally need to exhibit these behaviors:

  1. Avoid walls

  2. Notice occasions when it can 'cut me short' (when next to me a bit ahead).

  3. Avoid getting 'cut short'.

  4. Have an idea of the topology of the current 2d space to try to enclose me in a smaller space/safeguard himself a bigger space.

My current approach uses the NEAT algorithm (http://www.cs.ucf.edu/~kstanley/neat.html). It's a genetic algorithm that evolves neural networks over generations. It learned how to do 1,2 and 3 to some extent (but not great) but has no idea about 4.

For the inputs, I'm using:

  • the opponent angle relative to us

  • the opponent distance to us

  • the opponent heading relative to us

  • smart rays that probe in some directions with some amount of tree search (see video)

I'm a bit stuck now though and would like to know:

  • What's the class of algorithms I should look into? Recurrent / RealTime / Continous / Unsupervised Neural networks, ... An explanation about these and how they would apply to my problem would be great.

  • Any specific algorithms I should research?

  • What other sets of inputs could I use? A human player gets to see all the pixels in the game which is a lot more information than my simple set of inputs. But I don't think to feed the 200x200 pixels in my example to my NN would work at all. Maybe if I discretize them and make them relative to the AI position/heading...sounds tricky.

I'm happy to make my code available if someone wants to see it (C#).

Thanks!

1 Answer

0 votes
by (107k points)

The neural network needs some data to learn on. Input data is a very important part of machine learning. If you have a huge amount of data, you can achieve great results even if the architecture of your network is not good. That’s why companies like Google are trying to gain all the information they can get from their users (of course not because they have bad architectures but because really big data is precious).

So we need to generate some data. You can sit and play as many games as you can, but it is always good when you can generate data automatically (from scratch or modifying data that you have). In our case, it is easy to create data just randomly choosing direction and observing if the snake is still alive after the turn.

After 100 games I’ve got 5504 training examples. It is enough for training to survive

More information regarding Snake game AI: Movement rating functions and evolutionary algorithm-based optimization, refer to the following link: https://www.researchgate.net/publication/309390260_Snake_game_AI_Movement_rating_functions_and_evolutionary_algorithm-based_optimization

For Evolutionary Algorithm to Teach a NeuralNetwork to Play a Snake Game, refer to the following link: https://www.codeproject.com/Tips/1016742/Evolutionary-Algorithm-to-Teach-a-NeuralNetwork-to 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...