Predicting actions with an N-Gram predictor
Predicting actions is a great way to give players a challenge by going from random selection to selection based on past actions. One way to implement machine learning is by using probabilities to predict what the player will do next, and that's what an N-Gram predictor does.
To predict the player's next choice, N-Gram predictors hold a record of the probabilities of making particular decisions (which are usually moves), given all the combinations of the choices for the previous n moves.
Getting ready...
This is a recipe that makes use of general types. It is recommended that you have at least a basic understanding of how they work, because it's important that we use them well.
The first thing to do is implement a data type for holding the actions and their probabilities, which is called KeyDataRecord
.
The KeyDataRecord.cs
file should look like this:
using System.Collections; using System.Collections.Generic; public class KeyDataRecord<T> ...