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

            this.BuildStep(stepInfo);
            return(stepInfo);
        }
Exemplo 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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void InitGridStepInfo(GridStepInfo gridStepInfo)
        {
            if (gridStepInfo == null)
            {
                return;
            }

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

            this.Grid         = grid;
            this.GridStepInfo = null;
        }
Exemplo 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);
        }
Exemplo n.º 7
0
 public bool BuildStep(GridStepInfo stepInfo)
 {
     return(false);
 }