public string GetDirection(Cell bestNeightbour) { if (bestNeightbour == this.upper) return "D"; if (bestNeightbour == this.right) return "L"; if (bestNeightbour == this.lower) return "U"; return "R"; }
public Maze(string mazepath) { this.way = string.Empty; this.points = new List<Cell>(); this.StringPointers = new List<Cell>(); var filedata = File.ReadLines(mazepath).ToList(); Cell currentCell; foreach (string s in filedata) { currentCell = new Cell(s[0]); StringPointers.Add(currentCell); for (int i = 1; i < s.Length; i++) { currentCell.right = new Cell(s[i]); if (s[i] == 'e') this.exitCell = currentCell.right; if (s[i] == '*') this.entryCell = currentCell.right; if ("123456789".Contains(s[i])) points.Add(currentCell.right); currentCell.right.left = currentCell; currentCell = currentCell.right; } } Cell nextLineCurrentCell; for (int i = 0; i < StringPointers.Count-1; i++) { currentCell = StringPointers[i]; nextLineCurrentCell = StringPointers[i + 1]; while (currentCell != null | nextLineCurrentCell != null) { currentCell.lower = nextLineCurrentCell; nextLineCurrentCell.upper = currentCell; currentCell = currentCell.right; nextLineCurrentCell = nextLineCurrentCell.right; } } }
private void Locate(Cell cellPointer) { cellPointer.SetDistance(0); }