There's more...

You are welcome to play with different heuristic functions depending on the game and context, and the following is an example of how to do so.

Define a heuristic function in the Graph class:

public float Heuristic(Vertex a, Vertex b) 
{ 
  float estimation = 0f; 
  // your logic here 
  return estimation; 
} 

The important thing here is that the heuristic we develop is both admissible and consistent. For more theoretical insights about these topics, please refer to Artificial Intelligence: A Modern Approach, by Russel and Norvig.

In case you haven't noticed, we didn't implement the BuildPath method. This is because we talked about it at the end of Chapter 2, Navigation, in the recipe Finding your way out of a maze with DFS.

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.