private void CalculateNeighboursLOS() { foreach (var p in Seats.Keys) { NeighboursOf.Add(p, new List <Point>()); for (int dx = -1; dx < 2; dx++) { for (int dy = -1; dy < 2; dy++) { if (dx != 0 || dy != 0) { for (int i = 1; i < MaxDim; i++) { int newX = p.X + i * dx; int newY = p.Y + i * dy; Point pn = new Point(newX, newY); if (newX >= 0 && newX < Width && newY >= 0 && newY < Height && Seats.ContainsKey(pn)) { List <Point> nb = NeighboursOf.GetValueOrDefault(p); nb.Add(pn); NeighboursOf[p] = nb; break; } } } } } } }
public void UpdateNeighbours(Point p, Dictionary <Point, int> occupiedNew) { foreach (var pn in NeighboursOf.GetValueOrDefault(p)) { if (occupiedNew.ContainsKey(pn)) { //var count = occupiedNew[pn] + 1; occupiedNew[pn] = occupiedNew.GetValueOrDefault(pn, 0) + 1; } else { occupiedNew.Add(pn, 1); } } }
private void CalculateNeighbours() { foreach (var p in Seats.Keys) { NeighboursOf.Add(p, new List <Point>()); for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { Point pn = new Point(p.X + i, p.Y + j); if ((i != 0 || j != 0) && p.X + i >= 0 && p.X + i < Width && p.Y + j >= 0 && p.Y + j < Height && Seats.ContainsKey(p)) { List <Point> nb = NeighboursOf.GetValueOrDefault(p); nb.Add(pn); NeighboursOf[p] = nb; } } } } }