public List <MapSection> GetMapSections() { foreach (Cell cell in _map.GetAllCells()) { if (!cell.IsWalkable) { continue; } bool foundSection = false; foreach (MapSection mapSection in _mapSections) { var shortestPath = _pathFinder.ShortestPath(cell, mapSection.Cells.First()); if (shortestPath.First() != null) { mapSection.AddCell(cell); foundSection = true; break; } } if (!foundSection) { var mapSection = new MapSection(); mapSection.AddCell(cell); _mapSections.Add(mapSection); } } return(_mapSections); }
private MapSection Visit(ICell cell) { Stack <ICell> stack = new Stack <ICell>(new List <ICell>()); MapSection mapsection = new MapSection(); stack.Push(cell); while (stack.Count != 0) { cell = stack.Pop(); if (_visited[cell.Y][cell.X] || !cell.IsWalkable) { continue; } mapsection.AddCell(cell); _visited[cell.Y][cell.X] = true; foreach (ICell neighbor in GetNeighbors(cell)) { if (cell.IsWalkable == neighbor.IsWalkable && !_visited[neighbor.Y][neighbor.X]) { stack.Push(neighbor); } } } return(mapsection); }