Using machine learning for Level Generation in Snake (video-game)

As a practical example, this tutorial uses machine learning models to predict where to best place the apple in Snake. By using datasets that contain different plays we can obtain different game experiences or models that can adapt to the style of a player.


In some video-games, the level and environment generation uses random variables that are usually sampled from uniformed distributions. Or in some cases, these variables are even manually programmed.
The different game experiences, like levels of difficulty, are usually achieved by truncating these distributions to increase the chances of obtaining a sample that translates in a particular game experience, for example, a harder game. In simple games, this is done commonly by just increasing the speed of the game, without changing the way these variables are sampled. All of these variables have an impact on the way the game is going to develop for the player.

Using Snake as an example, the goal of this tutorial is to instead of sampling the apple position from a uniform distribution, use a machine learning model trained on data from past games. By selecting different game situations to train our model we can archive different game experiences, such as different difficulty, game styles or even adapted to a player’s style.

Contents:
Part 1: Creating a game log
Part 2: Placing apples!
0 - Opening the game log
0.1 - Vizualizing some observations
1 - Metrics to select the best apple placements
1.1 - Metric's Scores
2 - Filtering Metric's Scores to create a training set
2.1 - Generating more apples
3 - Features
4 - Tranning
4.1 - Testing
5 - Create a model with your apples!

Github: https://github.com/Filipedls/Snake_PyData


Python Skill Level:

basic

Domain Expertise:

some

Abstract as a tweet:

Using machine learning models for level generation in video-games

Domains:

Data Science, Machine Learning