예제 #1
0
        // итоговый путь
        private List <PathCell> CalculatePath(PathCell endCell)
        {
            List <PathCell> path = new List <PathCell> {
                endCell
            };
            var currentCell = endCell;

            while (currentCell.CameFromCell != null)
            {
                path.Add(currentCell.CameFromCell);
                currentCell = currentCell.CameFromCell;
            }
            path.Reverse();
            if (debug)
            {
                DebugDrawingPath(path);
            }
            return(path);
        }
예제 #2
0
        private List <PathCell> GetNeighborList(PathCell currentCell)
        {
            List <PathCell> neighborList = new List <PathCell>();

            if (currentCell.PositionGrid.x - 1 >= 0)
            {
                neighborList.Add(grid[currentCell.PositionGrid.x - 1, currentCell.PositionGrid.y]); // левый сосед
                if (currentCell.PositionGrid.y - 1 >= 0)
                {
                    neighborList.Add(grid[currentCell.PositionGrid.x - 1, currentCell.PositionGrid.y - 1]);                                      // левый нижний сосед
                }
                if (currentCell.PositionGrid.y + 1 < grid.GetLength(0))
                {
                    neighborList.Add(grid[currentCell.PositionGrid.x - 1, currentCell.PositionGrid.y + 1]);                                                     // левый верхний сосед
                }
            }
            if (currentCell.PositionGrid.x + 1 < grid.GetLength(1))
            {
                neighborList.Add(grid[currentCell.PositionGrid.x + 1, currentCell.PositionGrid.y]); // правый сосед
                if (currentCell.PositionGrid.y - 1 >= 0)
                {
                    neighborList.Add(grid[currentCell.PositionGrid.x + 1, currentCell.PositionGrid.y - 1]);                                      // правый нижний сосед
                }
                if (currentCell.PositionGrid.y + 1 < grid.GetLength(0))
                {
                    neighborList.Add(grid[currentCell.PositionGrid.x + 1, currentCell.PositionGrid.y + 1]);                                                     // правый верхний сосед
                }
            }
            if (currentCell.PositionGrid.y - 1 >= 0)
            {
                neighborList.Add(grid[currentCell.PositionGrid.x, currentCell.PositionGrid.y - 1]);                                      // нижний сосед
            }
            if (currentCell.PositionGrid.y + 1 < grid.GetLength(1))
            {
                neighborList.Add(grid[currentCell.PositionGrid.x, currentCell.PositionGrid.y + 1]);                                                     // верхний сосед
            }
            return(neighborList);
        }