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