0
$\begingroup$

I am working on a DIY project in which I want to be able to train a neural network to play Snake.

  • Is a genetic algorithm an efficient way of training a network for this application?

  • For a GA, what should the inputs of the network be? (distance to walls and fruit or the squares in the proximity of the snake head as a vector)

  • What would the difference in efficiency be depending on the algorithm and what limitation does each one have? Are there any other alternatives I should consider?

$\endgroup$
1
$\begingroup$

Q-Learning and Genetic algorithm are both good algorithms to create an IA that plays Snake.

The one you use depends mostly on how you understand and model your IA environment.

  • Q-Learning algorithm is an algorithm that needs a State (give by the environment), Actions it can take, and Rewards to give him according to how it performs.
  • Genetic algorithm needs to have intrinsic parameters (could be caracteristics of the network taking the decisions, or more simple things like leg size / muscle strenght if you want to make an IA that runs), how to merge 2 parents to create children, and a Metric to evaluate how the network performed.

I assume your snake is make of a grid (like old snake where you only have 4 directions, you can't go in diagonal directions).

In snake example, here is how I would define it in both case (careful, this is how I would model the problem, there might be more efficient models) :

Q-Learning

  • State : what is in each block of the grid (snake tail, snake head, food)
  • Actions : Up, Down, Right, Left
  • Rewards : Not dying : +0.01; dying : -10; eating piece of food: +1.

Genetic Algorithm

  • Intrinsic Parameters : Parameters of the network that takes decisions (inputs of the network could be whole state of the environment as described in Q-Table).
  • How to merge : ?
  • Metric : Lenght of the snake or time lived.

I can't find exactly how to make a genetic algorithm, but it should be possible.

Hope it helps. Q-Learning is usually easier so this is what I would use, but feel free to use whatever you want.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.