Esempio n. 1
0
        public GridStepInfo StartStep(Grid grid)
        {
            var stepInfo = new GridStepInfo(grid);

            this.BuildStep(stepInfo);
            return(stepInfo);
        }
Esempio n. 2
0
        private static bool GetNextCell(GridStepInfo stepInfo)
        {
            var cells = stepInfo.Grid.GetCells();

            // at end
            if ((cells.Length == 0) || (stepInfo.CurrentCell == cells[cells.Length - 1]))
            {
                stepInfo.CurrentCell = null;
                return(false);
            }

            if (stepInfo.CurrentCell == null)
            {
                stepInfo.CurrentCell = cells[0];
                return(true);
            }

            for (int i = 0; i < cells.Length - 1; i++)
            {
                if (cells[i] == stepInfo.CurrentCell)
                {
                    stepInfo.CurrentCell = cells[i + 1];
                    return(true);
                }
            }

            stepInfo.CurrentCell = null;
            return(false);
        }
        public bool BuildStep(GridStepInfo stepInfo)
        {
            if (stepInfo == null)
            {
                return(false);
            }

            Cell current = stepInfo.CurrentCell;

            var unusedNeighbors = current.UnusedNeighbors;

            if (unusedNeighbors.IsEmpty())
            {
                (stepInfo as RecursiveBacktrackerGridStepInfo).Pop();
            }
            else
            {
                Cell neighbour = unusedNeighbors.Sample();
                current.Link(neighbour);
                (stepInfo as RecursiveBacktrackerGridStepInfo).Push(neighbour);
            }

            stepInfo.CurrentCell = (stepInfo as RecursiveBacktrackerGridStepInfo).Peek();

            return(stepInfo.CurrentCell != null);
        }
Esempio n. 4
0
        public void InitGridStepInfo(GridStepInfo gridStepInfo)
        {
            if (gridStepInfo == null)
            {
                return;
            }

            this.GridStepInfo = gridStepInfo;
            this.Grid         = gridStepInfo.Grid;
        }
Esempio n. 5
0
        public void InitGrid(Grid grid)
        {
            if (grid == null)
            {
                return;
            }

            this.Grid         = grid;
            this.GridStepInfo = null;
        }
Esempio n. 6
0
        public bool BuildStep(GridStepInfo stepInfo)
        {
            if (stepInfo == null)
            {
                return(false);
            }

            if (!GetNextCell(stepInfo))
            {
                return(false);
            }

            ProcessCell(stepInfo.Path, stepInfo.CurrentCell);
            return(true);
        }
Esempio n. 7
0
 public bool BuildStep(GridStepInfo stepInfo)
 {
     return(false);
 }