示例#1
0
        private List<SkyNetCell> GetAdjacentWalkableNodes(SkyNetCell currentPosition)
        {
            var nextLocations = currentPosition.Neighbors;
            var walkableNodes = new List<SkyNetCell>();

            foreach (var node in nextLocations)
            {
                // Ignore already-closed nodes
                if (node.Status == SkyNetCellStatus.Close)
                    continue;
                // Already-open nodes are only added to the list if their G-value is lower going via this route.

                if (node.Parent == null)
                {
                    node.Parent = currentPosition;
                    node.DistanceFromStart = currentPosition.DistanceFromStart + 1;
                    node.Status = SkyNetCellStatus.Open;
                    walkableNodes.Add(node);
                }
                else
                {
                    if (node.DistanceFromStart > currentPosition.DistanceFromStart + 1)
                    {
                        node.Parent = currentPosition;
                        node.DistanceFromStart = currentPosition.DistanceFromStart + 1;
                        node.Status = SkyNetCellStatus.Open;
                        walkableNodes.Add(node);

                    }
                }

            }

            return walkableNodes.OrderByDescending(n => n.DistanceFromStart).ToList();
        }
示例#2
0
        public SkyNet(List<SkyNetCell> nodes, int InitialId)
        {
            ResetNodes(nodes);
            _nodes = nodes;

            _startNode = _nodes.First(x => x.Id == InitialId);

            _endNode = null;
        }
示例#3
0
        private void Walk(SkyNetCell currentPosition)
        {
            var borderCells = new List<SkyNetCell>();
            borderCells.Add(currentPosition);

            while (borderCells.Count>0)
            {
                var currentCell = borderCells.First();

                currentCell.Status = SkyNetCellStatus.Close;
                borderCells.RemoveAt(0);

                foreach (var neighbor in currentCell.Neighbors)
                {
                    if(neighbor.Status ==  SkyNetCellStatus.Close)
                        continue;
                    else if (neighbor.Status == SkyNetCellStatus.Untested)
                    {
                        neighbor.Parent = currentCell;
                        neighbor.Status = SkyNetCellStatus.Open;
                        neighbor.DistanceFromStart = currentCell.DistanceFromStart + 1;
                        borderCells.Add(neighbor);
                    }
                    else
                    {
                        if (neighbor.DistanceFromStart > currentCell.DistanceFromStart + 1)
                        {
                            neighbor.Parent = currentCell;
                            neighbor.DistanceFromStart = currentCell.DistanceFromStart + 1;
                        }
                    }

                }

                borderCells = borderCells.Where(c => c.Status != SkyNetCellStatus.Close).OrderBy(d => d.DistanceFromStart).ToList();

            }
        }