using System; using System.Collections.Generic; using System.Text; namespace ClassLib000.Walker { public class Appartment { public List CleanSpaces; public VacuumCleaner VC; public Appartment() { VC = new VacuumCleaner(); CleanSpaces = new List(); } #region public methods /// /// Формирование содержимого для сохранения (сериализация) /// public string GetContent() { StringBuilder sb = new StringBuilder(); sb.AppendLine($"{VC.GetContent()}"); foreach (CleanSpace space in CleanSpaces) { sb.AppendLine($"{space.GetContent()}"); } return sb.ToString(); } public void InitDoor(int x1, int y1, int x2, int y2) { foreach (var sp in CleanSpaces) { if (sp.X > x1 && sp.X > x2 && sp.Y > y1 && sp.Y < y2) { sp.WallEast = false; sp.WallNorth = false; sp.WallSouth = false; sp.WallWest = false; } } } public void InitRoom(int x1, int y1, int x2, int y2) { for (int iX = x1; iX <= x2; iX++) { for (int iY = y1; iY <= y2; iY++) { CleanSpace cs = new CleanSpace(x1, y1); if (iX == x1) { cs.WallWest = true; } if (iX == x2) { cs.WallEast = true; } if (iY == y1) { cs.WallNorth = true; } if (iY == y2) { cs.WallSouth = true; } } } } public void InitVC() { VC.X = CleanSpaces[0].X; VC.Y = CleanSpaces[0].Y; } public List GetDirtyCleanSpace(int iDayCount) { List result = new List(); DateTime dtFrom = DateTime.Now.AddDays(-iDayCount); foreach (var sp in CleanSpaces) { if (sp.DateClean < dtFrom) { result.Add(sp); } } return result; } public List FindRouteForVC(VacuumCleaner vc, int toX, int toY) { List result = new List(); int fromX = vc.X; int fromY = vc.Y; // ... реализация алгоритма перебора путей (поиск кратчайшего) var cleanSpaceFrom = CleanSpaces[0]; var cleanSpaceTo = CleanSpaces[1]; if (vc.CanGo(cleanSpaceFrom, cleanSpaceTo)) { //... } return result; } #endregion } }