Representing the world with grids
A grid is the most widely-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 its properties.
Getting ready
First, we need to create an abstract class, 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, thereby avoiding 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 is a good starting point if you want to implement graph representations not covered in the book.
Then, we will implement a graph sub-class that handles itself internally as a grid.
How to do it...
The following code is for the Graph
class:
- Create the...