How to do it...

The process of building an N-Gram predictor is divided into five big steps, as follows:

  1. Create the general class within a file that has the same name:
using System.Collections; 
using System.Collections.Generic; 
using System.Text; 
 
public class NGramPredictor<T> 
{ 
    private int nValue; 
    private Dictionary<string, KeyDataRecord<T>> data; 
}
  1. Implement the constructor for initializing the member variables:
public NGramPredictor(int windowSize) 
{ 
    nValue = windowSize + 1; 
    data = new Dictionary<string, KeyDataRecord<T>>(); 
} 
  1. Implement a static function for converting a set of actions into a string key:
public static string ArrToStrKey(ref T[] actions) { StringBuilder builder = new StringBuilder(); foreach (T a in actions) { builder.Append(a.ToString()); ...

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.