public static Distances PathTo(Cell start, Cell goal) { Cell current = goal; Distances fullGrid = Build(start); Distances breadcrumbs = new Distances(start); breadcrumbs.Add(current, fullGrid.GetDistance(current)); do { foreach (Cell neighbour in current.Links) { if (fullGrid.GetDistance(neighbour) < fullGrid.GetDistance(current)) { breadcrumbs.Add(neighbour, fullGrid.GetDistance(neighbour)); current = neighbour; break; } } }while (current != start); return(breadcrumbs); }
public static string ToText(Grid grid, Distances distances) { if (grid == null) { return(string.Empty); } string output = "+"; for (int i = 0; i < grid.Columns; i++) { output += "---+"; } output += "\n"; for (int r = 0; r < grid.Rows; r++) { string top = "|"; string bottom = "+"; for (int i = 0; i < grid.Columns; i++) { Cell cell = grid.GetCell(r, i); if (cell == null) { cell = new Cell(-1, -1); } string cellContent = " "; if ((distances != null) && distances.KnowsCell(cell)) { cellContent = " " + (char)(distances.GetDistance(cell) + 65) + " "; } top += cellContent + (cell.IsLinked(cell.East) ? " " : "|"); bottom += (cell.IsLinked(cell.South) ? " " : "---") + "+"; } output += top + "\n" + bottom + "\n"; } return(output); }
protected Color GetCellColor(Distances distances, Cell cell) { if ((this.GridStepInfo != null) && (this.GridStepInfo.CurrentCell != null)) { if (cell == this.GridStepInfo.CurrentCell) { return(this.StepCurrentCellColor); } if (this.GridStepInfo.Path.Contains(cell)) { return(this.StepPathColor); } if (this.GridStepInfo.CurrentCell.IsLinked(cell)) { return(this.StepCurrentCellNeighborColor); } } if (distances == null) { return(Color.FromArgb(255, 208, 208, 208)); } if (!distances.KnowsCell(cell)) { return(Color.FromArgb(255, 208, 208, 208)); } int dist = distances.GetDistance(cell); int maxdist = distances.MaxDistance().Value; double intensity = 1.0 * (maxdist - dist) / maxdist; byte r = (byte)((this.DistanceFromColor.R * intensity) + (this.DistanceToColor.R * (1 - intensity))); byte g = (byte)((this.DistanceFromColor.G * intensity) + (this.DistanceToColor.G * (1 - intensity))); byte b = (byte)((this.DistanceFromColor.B * intensity) + (this.DistanceToColor.B * (1 - intensity))); return(Color.FromArgb(255, r, g, b)); }