Exemple #1
0
        private List <PathCell> GetNewEmptyNeighbourCells(List <PathCell> pathCells)
        {
            var newCells = new List <PathCell>();

            foreach (var cell in pathCells)
            {
                foreach (var offset in neighbourOffsets)
                {
                    neighbour.x = cell.X + offset.x;
                    neighbour.y = cell.Z + offset.y;

                    if (cells.IsPieceInCell(neighbour))
                    {
                        continue;
                    }

                    var reachableCell = new PathCell(neighbour.x, neighbour.y, cell.Dist + 1, cell);
                    if (!newCells.Contains(reachableCell) && !reachableCells.Contains(reachableCell))
                    {
                        if (grid.IsWithinGridBoundary(reachableCell.X, reachableCell.Z))
                        {
                            newCells.Add(reachableCell);
                        }
                    }
                }
            }
            return(newCells);
        }
Exemple #2
0
        private static List <Vector3> ConstructPath(PathCell target, int maxDistance)
        {
            var path = new Stack <Vector3>();
            var cell = target;

            while (cell != null)
            {
                if (path.Count - 1 >= maxDistance)
                {
                    return(null);
                }

                path.Push(HexCoordinates.ToPosition(cell.X, cell.Z));
                cell = cell.PreviousCell;
            }

            return(path.ToList());
        }