The AStar class

The AStar class implements the pathfinding algorithm using the classes we have implemented so far. If you want a quick review of the A* algorithm, see the Revisiting the A* algorithm section from earlier in this chapter. The steps for implementation of AStar are as follows:

  1. We start with our openList declaration, which is a PriorityQueue type variable, and closedList, which is a HashSet of nodes. The AStar.cs file is as follows:
using UnityEngine;using System.Collections;using System.Collections.Generic;
 
public class AStar { 
    public static PriorityQueue openList;    public static HashSet<Node> closedList;
  1. We implement a method called HeuristicEstimateCost to calculate the cost between the two nodes. The calculation is simple. ...

Get Unity Artificial Intelligence Programming - Fourth 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.