How to do it...

We will comprise everything in just a class that will handle the abstract representation, called DSFDungeon:

  1. Define the DFSDungeon component and its member values:
using UnityEngine;using System.Collections.Generic;public class DFSDungeon : MonoBehaviour{  public int width;  public int height;  public bool[,] dungeon;  public bool[,] visited;  private Stack<Vector2> stack;  private Vector2 current;  private int size;  // next steps}
  1. Define the initialization function:
private void Init(){  // next steps  }
  1. Initialize the required variables and random initial position:
stack = new Stack<Vector2>();size = width * height;dungeon = new bool[height, width];visited = new bool[height, width];current.x = Random.Range(0, width - 1);current.y ...

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.