How to do it...

We will develop three different classes: a component for our prefabs, the level predictor, and the level generator that puts everything together.

LevelSlice is the component to attach to the prefabs:

 using UnityEngine;public class LevelSlice : MonoBehaviour{  public string id;  override public string ToString()  {    return id;  }}

Now we need to develop the predictor:

public class LevelPredictor : NGramPredictor<LevelSlice>{  public LevelPredictor(int windowSize) : base(windowSize)  {  }}

And, finally, we develop the level generator:

 using UnityEngine;using System.Collections.Generic;public class LevelGenerator : MonoBehaviour{  public LevelPredictor predictor;  public List<LevelSlice> pattern;  public List<LevelSlice> result; private ...

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.