/// <summary> /// Sets the EmptyTile's adjacent tiles /// </summary> public void SetAdjacents(List <BaseNode> nodes, int worldLimit) { //if tile is not on left edge if (location.x != 0) { LeftEmpty = nodes.Single(t => t.location.x == location.x - 1 && t.location.y == location.y); Adjacents.Add(LeftEmpty); } //if tile is not on right edge if (location.x + 1 != worldLimit) { RightEmpty = nodes.Single(t => t.location.x == location.x + 1 && t.location.y == location.y); Adjacents.Add(RightEmpty); } //if tile is not on bottom edge if (location.y != 0) { BottomEmpty = nodes.Single(t => t.location.x == location.x && t.location.y == location.y - 1); Adjacents.Add(BottomEmpty); } //if tile is not on top edge if (location.y + 1 != worldLimit) { TopEmpty = nodes.Single(t => t.location.x == location.x && t.location.y == location.y + 1); Adjacents.Add(TopEmpty); } }
public override void AddEdge(int src, int dest, bool readFromFile = false) { if (!readFromFile) { if (src < 1 || src > Size) { throw new ArgumentException("Can't add this edge // Wrong Source Vertex!"); } if (dest < 1 || dest > Size) { throw new ArgumentException("Can't add this edge // Wrong Destination Vertex!"); } } bool containsSrc = Adjacents.ContainsKey(src); bool containsDest = Adjacents.ContainsKey(dest); if (!containsDest) { Adjacents.Add(dest, new List <int>()); } if (!containsSrc) { Adjacents.Add(src, new List <int> { dest }); } else if (!Adjacents[src].Contains(dest)) { Adjacents[src].Add(dest); } //Console.WriteLine($"Add directed edge [{src},{dest}] to graph"); }
/// <summary> /// Connects points /// </summary> public Point Link(params Point[] targets) { foreach(var point in targets) { point.Adjacents.Add(this); Adjacents.Add(point); } return this; }
public void AddAdjacent(Corner corner) { Adjacents.Add(corner); }