Beispiel #1
0
        //BFS Algorithm
        public void FindSelectableTiles(CandiceTile currentTile, float maxMovePoints, Action <List <CandiceTile> > callback)
        {
            //Make sure to call ComputeAdjacencyList() first;
            List <CandiceTile> selectableTiles = new List <CandiceTile>();

            Queue <CandiceTile> process = new Queue <CandiceTile>();

            process.Enqueue(currentTile);
            currentTile.visited = true;
            //currentTile.parent == ?? leave as null;

            while (process.Count > 0)
            {
                CandiceTile t = process.Dequeue();

                selectableTiles.Add(t);
                t.selectable = true;

                if (t.distance < maxMovePoints)
                {
                    foreach (CandiceTile CandiceTile in t.adjacencyList)
                    {
                        if (!CandiceTile.visited)
                        {
                            CandiceTile.parent   = t;
                            CandiceTile.visited  = true;
                            CandiceTile.distance = 1 + t.distance;
                            process.Enqueue(CandiceTile);
                        }
                    }
                }
            }
            callback(selectableTiles);
        }
Beispiel #2
0
        public void FindBFSPath(CandiceTile CandiceTile, Action <Stack <CandiceTile> > callback)
        {
            Stack <CandiceTile> path = new Stack <CandiceTile>();

            CandiceTile.target = true;

            CandiceTile next = CandiceTile;

            while (next != null)
            {
                path.Push(next);
                next = next.parent;
            }

            callback(path);
        }
Beispiel #3
0
        public void ComputeAdjacencyList(float jumpHeight, CandiceTile target)
        {
            try
            {
                tiles = GameObject.FindGameObjectsWithTag("CandiceTile");
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError(e.Message);
            }

            foreach (GameObject CandiceTile in tiles)
            {
                CandiceTile t = CandiceTile.GetComponent <CandiceTile>();
                t.FindNeighbors(jumpHeight, target);
            }
        }