Establishing the priority queue

We represent our open and closed list using the PriorityQueue class. This approach allows us to implement some helper methods for our own convenience. The PriorityClass.cs file looks like this:

using System.Collections;public class PriorityQueue {    private ArrayList nodes = new ArrayList();        public int Length    {        get { return nodes.Count; }    }        public bool Contains(object node)    {        return nodes.Contains(node);    }        public Node GetFirstNode()    {        if (nodes.Count > 0)        {            return (Node)nodes[0];        }        return null;    }        public void Push(Node node)    {        nodes.Add(node);        nodes.Sort();    }    public void Remove(Node node)    {        nodes.Remove(node);        nodes.Sort();    }}

There isn't much of note in this code, but the Sort() method in particular is interesting. ...

Get Unity 2017 Game AI Programming - Third 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.