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 GridStepInfo StartStep(Grid grid) { var stepInfo = new GridStepInfo(grid); this.BuildStep(stepInfo); return(stepInfo); }
public static GridDisplay GetDisplayForGridStep(GridStepInfo gridStepInfo) { if (gridStepInfo == null) { return(null); } var result = GetDisplayForGrid(gridStepInfo.Grid); result.InitGridStepInfo(gridStepInfo); return(result); }
public bool BuildStep(GridStepInfo stepInfo) { if (stepInfo == null) { return(false); } if (!GetNextCell(stepInfo)) { return(false); } ProcessCell(stepInfo.CurrentCell); return(true); }
public bool BuildStep(GridStepInfo stepInfo) { if (stepInfo == null) { return(false); } if ((stepInfo as WilsonGridStepInfo).Unvisited.IsEmpty()) { stepInfo.CurrentCell = null; return(false); } var unvisited = (stepInfo as WilsonGridStepInfo).Unvisited; if (stepInfo.Path.Count == 0) { stepInfo.CurrentCell = unvisited.Sample(); stepInfo.Path.Add(stepInfo.CurrentCell); return(true); } if (unvisited.Contains(stepInfo.CurrentCell)) { stepInfo.CurrentCell = stepInfo.CurrentCell.Neighbors.Sample(); int position = stepInfo.Path.IndexOf(stepInfo.CurrentCell); if (position >= 0) { stepInfo.Path.RemoveRange(position + 1, stepInfo.Path.Count - position - 1); } else { stepInfo.Path.Add(stepInfo.CurrentCell); } return(true); } for (int i = 0; i < stepInfo.Path.Count - 1; i++) { stepInfo.Path[i].Link(stepInfo.Path[i + 1]); unvisited.Remove(stepInfo.Path[i]); } stepInfo.Path.Clear(); return(true); }
public bool BuildStep(GridStepInfo stepInfo) { if (stepInfo == null) { return(false); } // Killing if ((stepInfo as HuntAndKillGridStepInfo).IsHunting == false) { var newCurrent = LinkToNeighbor(stepInfo.CurrentCell); if (newCurrent != null) { stepInfo.CurrentCell = newCurrent; } else { (stepInfo as HuntAndKillGridStepInfo).IsHunting = true; stepInfo.CurrentCell = null; } return(true); } // Hunting foreach (Cell cell in stepInfo.Grid.GetCells()) { if (cell == null) { continue; } var visitedNeighbors = cell.UsedNeighbors; if (cell.Links.IsEmpty() && !visitedNeighbors.IsEmpty()) { stepInfo.CurrentCell = cell; Cell neighbour = visitedNeighbors.Sample(); stepInfo.CurrentCell.Link(neighbour); return(true); } } stepInfo.CurrentCell = null; return(false); }
public bool BuildStep(GridStepInfo stepInfo) { if (stepInfo == null) { return(false); } if ((stepInfo as AldousBorderGridStepInfo).Unvisited == 0) { stepInfo.CurrentCell = null; return(false); } bool newCell; stepInfo.CurrentCell = ProcessCell(stepInfo.CurrentCell, out newCell); if (newCell) { (stepInfo as AldousBorderGridStepInfo).UsedCell(); } return(true); }