Representing the world with grids
A grid is the most used structure for representing worlds in games because it is easy to implement and visualize. However, we will lay the foundations for advanced graph representations while learning the basis of graph theory and properties.
Getting ready
First, we need to create an abstract class called Graph
, declaring the virtual methods that every graph representation implements. It is done this way because, no matter how the vertices and edges are represented internally, the path-finding algorithms remain high-level, thus avoiding the implementation of the algorithms for each type of graph representation.
This class works as a parent class for the different representations to be learned in the chapter and it's a good starting point if you want to implement graph representations not covered in the book.
The following is the code for the Graph
class:
Create the backbone with the member values:
using UnityEngine; using System.Collections; using System.Collections...