Ejemplo n.º 1
0
    /// <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);
        }
    }
Ejemplo n.º 2
0
        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");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Connects points
        /// </summary>
        public Point Link(params Point[] targets)
        {
            foreach(var point in targets)
            {
                point.Adjacents.Add(this);
                Adjacents.Add(point);
            }

            return this;
        }
Ejemplo n.º 4
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Adjacents != null ? Adjacents.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (TypeName != null ? TypeName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ObjRef.GetHashCode();
         return(hashCode);
     }
 }
Ejemplo n.º 5
0
        public virtual bool RemoveAllAdjacents()
        {
            bool removed = false;

            foreach (KeyValuePair <Side, Node> adj in Adjacents.ToList())
            {
                if (adj.Value != null)
                {
                    removed = true;
                    RemoveAdjacent(adj.Key, adj.Value);
                }
            }
            return(removed);
        }
Ejemplo n.º 6
0
        public override bool RemoveAllAdjacents()
        {
            bool removed = false;

            foreach (KeyValuePair <Side, Node> adj in Adjacents.ToList())
            {
                if (adj.Value != null)
                {
                    removed = true;
                    RemoveAdjacent(adj.Key, adj.Value);
                }
            }
            ConnectedInputs.Clear();
            return(removed);
        }
Ejemplo n.º 7
0
        public System.Object[] TraverseAllRecursive(List <Node> looked, bool reached)
        {
            if (Globals.UltraDebug)
            {
                Print();
            }
            System.Object[] returns = new System.Object[3];
            returns[2] = reached;
            looked.Add(this);
            Node adj;

            if (Adjacents.TryGetValue(Sides.North, out adj) && !(bool)returns[2])
            {
                if (adj != null && !looked.Contains(adj))
                {
                    returns = adj.TraverseAllRecursive(looked, reached);
                }
            }
            if (Adjacents.TryGetValue(Sides.South, out adj) && !(bool)returns[2])
            {
                if (adj != null && !looked.Contains(adj))
                {
                    returns = adj.TraverseAllRecursive(looked, reached);
                }
            }
            if (Adjacents.TryGetValue(Sides.West, out adj) && !(bool)returns[2])
            {
                if (adj != null && !looked.Contains(adj))
                {
                    returns = adj.TraverseAllRecursive(looked, reached);
                }
            }
            if (Adjacents.TryGetValue(Sides.East, out adj) && !(bool)returns[2])
            {
                if (adj != null && !looked.Contains(adj))
                {
                    returns = adj.TraverseAllRecursive(looked, reached);
                }
            }
            if (!(bool)returns[2])
            {
                looked.Remove(this);
            }
            return(returns);
        }
Ejemplo n.º 8
0
 public void AddAdjacent(Corner corner)
 {
     Adjacents.Add(corner);
 }
Ejemplo n.º 9
0
 public void Init()
 {
     instance = new Adjacents();
 }