public GridStepInfo StartStep(Grid grid) { var stepInfo = new GridStepInfo(grid); this.BuildStep(stepInfo); return(stepInfo); }
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); }
public void InitGridStepInfo(GridStepInfo gridStepInfo) { if (gridStepInfo == null) { return; } this.GridStepInfo = gridStepInfo; this.Grid = gridStepInfo.Grid; }
public void InitGrid(Grid grid) { if (grid == null) { return; } this.Grid = grid; this.GridStepInfo = null; }
public bool BuildStep(GridStepInfo stepInfo) { if (stepInfo == null) { return(false); } if (!GetNextCell(stepInfo)) { return(false); } ProcessCell(stepInfo.Path, stepInfo.CurrentCell); return(true); }
public bool BuildStep(GridStepInfo stepInfo) { return(false); }