Beispiel #1
0
 public static void DrawWireBounds(Vector3 center, Vector3 size, Color lineColor, Neighbors sides)
 {
     float bh = size.y-0.2f;
     float bs = size.x-0.2f;
     Vector3 here = center + new Vector3(-bs/2+0.1f, -bh/2+0.1f, -bs/2+0.1f);
     if((sides & Neighbors.FrontLeft) != 0) {
         Vector3[] frontLeft = new Vector3[]{
             here+new Vector3(0,0,bs),
             here+new Vector3(0,bh,bs),
             here+new Vector3(0,bh,0),
             here+new Vector3(0,0,0)
         };
         Handles.DrawSolidRectangleWithOutline(frontLeft, Color.clear, lineColor);
     }
     if((sides & Neighbors.FrontRight) != 0) {
         Vector3[] frontRight = new Vector3[]{
             here+new Vector3(0,0,0),
             here+new Vector3(bs,0,0),
             here+new Vector3(bs,bh,0),
             here+new Vector3(0,bh,0),
         };
         Handles.DrawSolidRectangleWithOutline(frontRight, Color.clear, lineColor);
     }
     if((sides & Neighbors.Top) != 0) {
         Vector3[] top = new Vector3[]{
             here+new Vector3(bs,bh,0),
             here+new Vector3(bs,bh,bs),
             here+new Vector3(0,bh,bs),
             here+new Vector3(0,bh,0),
         };
         Handles.DrawSolidRectangleWithOutline(top, Color.clear, lineColor);
     }
     if((sides & Neighbors.Bottom) != 0) {
         Vector3[] bottom = new Vector3[]{
             here+new Vector3(bs,0,0),
             here+new Vector3(bs,0,bs),
             here+new Vector3(0,0,bs),
             here+new Vector3(0,0,0),
         };
         Handles.DrawSolidRectangleWithOutline(bottom, Color.clear, lineColor);
     }
     if((sides & Neighbors.BackLeft) != 0) {
         Vector3[] backLeft = new Vector3[]{
             here+new Vector3(0,0,bs),
             here+new Vector3(bs,0,bs),
             here+new Vector3(bs,bh,bs),
             here+new Vector3(0,bh,bs),
         };
         Handles.DrawSolidRectangleWithOutline(backLeft, Color.clear, lineColor);
     }
     if((sides & Neighbors.BackRight) != 0) {
         Vector3[] backRight = new Vector3[]{
             here+new Vector3(bs,bh,bs),
             here+new Vector3(bs,0,bs),
             here+new Vector3(bs,0,0),
             here+new Vector3(bs,bh,0)
         };
         Handles.DrawSolidRectangleWithOutline(backRight, Color.clear, lineColor);
     }
 }
Beispiel #2
0
 public void SetTileSpecOnTileAt(int spec, int x, int y, int z, Neighbors sides)
 {
     MapTile t = TileAt(x,y,z);
     if(!MapTileIsNull(t)) {
         t.SetTileSpecOnSides(spec, sides);
     }
     RemakeMesh();
 }
Beispiel #3
0
    public void AdjustHeightOnSidesOfTile(
		int x, int y, int z,
		int deltaH,
		Neighbors sides,
		bool top
	)
    {
        MapTile t = TileAt(x,y,z);
        if(t == null) { return; }
        t.AdjustHeightOnSides(deltaH, sides, top, NextTile(t));
        RemakeMesh();
    }
Beispiel #4
0
 private void BroadcastUpdate(LinkStateAdvertisement packet)
 {
     Neighbors
     .ForEach(neighbor => neighbor.ReceiveUpdate(packet));
 }
 /// <summary>
 /// Setting it's own neighbour
 /// </summary>
 /// <param name="nextNode"></param>
 /// <param name="distance"></param>
 public void SetNeighbour(Node nextNode, int distance)
 {
     Neighbors.Add(nextNode, distance);
 }
Beispiel #6
0
        private Tile GetNeighbor(Tile target, Neighbors neighbor)
        {
            Tile tile = null;
            int col = target.col;
            int row = target.row;

            switch (neighbor) {
            case Neighbors.UpperLeft:
                if (col > 0 && row > 0) {
                    tile = tiles [col - 1, row - 1];
                }
                break;

            case Neighbors.Above:
                if (row > 0) {
                    tile = tiles [col, row - 1];
                }
                break;

            case Neighbors.UpperRight:
                if (col < 7 && row > 0) {
                    tile = tiles [col + 1, row - 1];
                }
                break;

            case Neighbors.Left:
                if (col > 0) {
                    tile = tiles [col - 1, row];
                }
                break;

            case Neighbors.Right:
                if (col < 7) {
                    tile = tiles [col + 1, row];
                }
                break;

            case Neighbors.LowerLeft:
                if (col > 0 && row < 7) {
                    tile = tiles [col - 1, row + 1];
                }
                break;

            case Neighbors.Below:
                if (row < 7) {
                    tile = tiles [col, row + 1];
                }
                break;

            case Neighbors.LowerRight:
                if (col < 7 && row < 7) {
                    tile = tiles [col + 1, row + 1];
                }
                break;
            }

            return tile;
        }
Beispiel #7
0
    public void AdjustHeightOnSides(int ht, Neighbors mask, bool top, MapTile next)
    {
        if(top && (heights == null || heights.Length == 0)) {
            heights = new int[]{1, 1, 1, 1};
        }
        if(!top && (baselines == null || baselines.Length == 0)) {
            baselines = new int[]{0, 0, 0, 0};
        }
        int hts = ht > 0 ? 1 : -1;
        while(ht != 0) {
            int hcl = heights[(int)Corners.Left];
            int hcf = heights[(int)Corners.Front];
            int hcr = heights[(int)Corners.Right];
            int hcb = heights[(int)Corners.Back];
            int bcl = baselines[(int)Corners.Left];
            int bcf = baselines[(int)Corners.Front];
            int bcr = baselines[(int)Corners.Right];
            int bcb = baselines[(int)Corners.Back];
            int aboveTileZIfAny = next != null ? next.z : int.MaxValue;
            if(top) {
                //raise rules: if corners are different heights, only raise the lower one;
                //             don't raise a corner if it will cause a collision with a tile above
                //lower rules: if corners are different heights, only lower the higher one;
                //             don't lower a height to or below its corresponding baseline
                if((mask & Neighbors.FrontLeft) != 0) {
                    if(hts > 0 ? (hcl <= hcf && z+hcl < aboveTileZIfAny) : (hcl >= hcf && hcl > bcl+1)) {
                        heights[(int)Corners.Left]  += hts;
                    }
                    if(hts > 0 ? (hcf <= hcl && z+hcf < aboveTileZIfAny) : (hcf >= hcl && hcf > bcf+1)) {
                        heights[(int)Corners.Front] += hts;
                    }
                }
                if((mask & Neighbors.FrontRight) != 0) {
                    if(hts > 0 ? (hcr <= hcf && z+hcr < aboveTileZIfAny) : (hcr >= hcf && hcr > bcr+1)) {
                        heights[(int)Corners.Right] += hts;
                    }
                    if(hts > 0 ? (hcf <= hcr && z+hcf < aboveTileZIfAny) : (hcf >= hcr && hcf > bcf+1)) {
                        heights[(int)Corners.Front] += hts;
                    }
                }
                if((mask & Neighbors.BackRight) != 0) {
                    if(hts > 0 ? (hcr <= hcb && z+hcr < aboveTileZIfAny) : (hcr >= hcb && hcr > bcr+1)) {
                        heights[(int)Corners.Right] += hts;
                    }
                    if(hts > 0 ? (hcb <= hcr && z+hcb < aboveTileZIfAny) : (hcb >= hcr && hcb > bcb+1)) {
                        heights[(int)Corners.Back] += hts;
                    }
                }
                if((mask & Neighbors.BackLeft) != 0) {
                    if(hts > 0 ? (hcl <= hcb && z+hcl < aboveTileZIfAny) : (hcl >= hcb && hcl > bcl+1)) {
                        heights[(int)Corners.Left] += hts;
                    }
                    if(hts > 0 ? (hcb <= hcl && z+hcb < aboveTileZIfAny) : (hcb >= hcl && hcb > bcb+1)) {
                        heights[(int)Corners.Back] += hts;
                    }
                }
            } else {
                //raise rules: if corners are different heights, only raise the lower one;
                //             don't raise a baseline to or above its corresponding height;
                //             while all corners are raised above 0, decrement all corners by 1 and increase z by 1.
                //lower rules: if corners are different heights, only lower the higher one;
                //             don't lower a corner below 0
                //             (later: don't lower a corner below 0 if there is a tile below;)
                //             (later: while any corner is below 0, increment all corners by 1 and decrease z by 1)
                if((mask & Neighbors.FrontLeft) != 0) {
                    if(hts > 0 ? (bcl <= bcf && bcl+1<hcl) : (bcl >= bcf && bcl > 0)) {
                        baselines[(int)Corners.Left]  += hts;
                    }
                    if(hts > 0 ? (bcf <= bcl && bcf+1<hcf) : (bcf >= bcl && bcf > 0)) {
                        baselines[(int)Corners.Front] += hts;
                    }
                }
                if((mask & Neighbors.FrontRight) != 0) {
                    if(hts > 0 ? (bcr <= bcf && bcr+1<hcr): (bcr >= bcf && bcr > 0)) {
                        baselines[(int)Corners.Right] += hts;
                    }
                    if(hts > 0 ? (bcf <= bcr && bcf+1<hcf) : (bcf >= bcr && bcf > 0)) {
                        baselines[(int)Corners.Front] += hts;
                    }
                }
                if((mask & Neighbors.BackRight) != 0) {
                    if(hts > 0 ? (bcr <= bcb && bcr+1<hcr) : (bcr >= bcb && bcr > 0)) {
                        baselines[(int)Corners.Right] += hts;
                    }
                    if(hts > 0 ? (bcb <= bcr && bcb+1<hcb) : (bcb >= bcr && bcb > 0)) {
                        baselines[(int)Corners.Back] += hts;
                    }
                }
                if((mask & Neighbors.BackLeft) != 0) {
                    if(hts > 0 ? (bcl <= bcb && bcl+1<hcl) : (bcl >= bcb && bcl > 0)) {
                        baselines[(int)Corners.Left] += hts;
                    }
                    if(hts > 0 ? (bcb <= bcl && bcb+1<hcb) : (bcb >= bcl && bcb > 0)) {
                        baselines[(int)Corners.Back] += hts;
                    }
                }
                while(baselines[(int)Corners.Left] > 0 &&
                            baselines[(int)Corners.Front] > 0 &&
                            baselines[(int)Corners.Right] > 0 &&
                            baselines[(int)Corners.Back] > 0) {
                    baselines[(int)Corners.Left]--;
                    baselines[(int)Corners.Front]--;
                    baselines[(int)Corners.Right]--;
                    baselines[(int)Corners.Back]--;
                    z++;
                }
            }

            ht -= hts;
        }
    }
 public void AddEdge(GraphNode <T> graphNode)
 {
     Neighbors.Add(graphNode);
 }
 /// <summary>
 /// Checks to see if given Region is a neighbor to this region.
 /// </summary>
 /// <param name="region"></param>
 /// <returns>True if this Region is a neighbor of given Region, false otherwise.</returns>
 public bool IsNeighbor(Region region)
 {
     return(Neighbors.Contains(region));
 }
Beispiel #10
0
 public void AddNeighbor(Vertex <T> vertex)
 {
     Neighbors.Add(vertex);
 }
    private Neighbors GetBubbleNeighbors(Dimension gridPos, bool isShifted)
    {
        var neighbors = new Neighbors();

        neighbors.Initialize();

        //Left & Right
        neighbors.left.bubble = gridPos.columns > 0
            ? this._gridBubbles[gridPos.rows, gridPos.columns - 1]
            : null;
        neighbors.left.gridPosition = new Dimension(gridPos.rows, gridPos.columns - 1);
        neighbors.left.canUseIt     = gridPos.columns > 0;

        neighbors.right.bubble = (gridPos.columns + 1) < gridDimension.columns
            ? this._gridBubbles[gridPos.rows, gridPos.columns + 1]
            : null;
        neighbors.right.gridPosition = new Dimension(gridPos.rows, gridPos.columns + 1);
        neighbors.right.canUseIt     = (gridPos.columns + 1) < gridDimension.columns;

        //- Top Right & Left
        if (gridPos.rows > 0)
        {
            if (isShifted)
            {
                neighbors.topLeft.gridPosition = new Dimension(gridPos.rows - 1, gridPos.columns);
                neighbors.topLeft.bubble       = this._gridBubbles[gridPos.rows - 1, gridPos.columns];

                neighbors.topRight.gridPosition = new Dimension(gridPos.rows - 1, gridPos.columns + 1);
                neighbors.topRight.bubble       = (gridPos.columns + 1) < gridDimension.columns
                    ? this._gridBubbles[gridPos.rows - 1, gridPos.columns + 1]
                    : null;
            }
            else
            {
                neighbors.topLeft.gridPosition = new Dimension(gridPos.rows - 1, gridPos.columns - 1);
                neighbors.topLeft.bubble       = (gridPos.columns - 1) >= 0
                    ? this._gridBubbles[gridPos.rows - 1, gridPos.columns - 1]
                    : null;

                neighbors.topRight.gridPosition = new Dimension(gridPos.rows - 1, gridPos.columns);
                neighbors.topRight.bubble       = this._gridBubbles[gridPos.rows - 1, gridPos.columns];
            }
        }
        else
        {
            neighbors.topLeft.canUseIt  = false;
            neighbors.topRight.canUseIt = false;
            neighbors.topLeft.bubble    = null;
            neighbors.topRight.bubble   = null;
        }

        //- Down Left & Right
        if ((gridPos.rows + 1) >= gridDimension.rows)
        {
            if (isShifted)
            {
                neighbors.downLeft.canUseIt  = true;
                neighbors.downRight.canUseIt = ((gridPos.columns + 1) < gridDimension.columns);
            }
            else
            {
                neighbors.downLeft.canUseIt  = gridPos.columns > 0;
                neighbors.downRight.canUseIt = true;
            }
            neighbors.downLeft.bubble  = null;
            neighbors.downRight.bubble = null;
        }
        else
        {
            if (isShifted)
            {
                neighbors.downLeft.gridPosition = new Dimension(gridPos.rows + 1, gridPos.columns);
                neighbors.downLeft.bubble       = this._gridBubbles[gridPos.rows + 1, gridPos.columns];
                neighbors.downLeft.canUseIt     = true;

                neighbors.downRight.gridPosition = new Dimension(gridPos.rows + 1, gridPos.columns + 1);
                neighbors.downRight.bubble       = ((gridPos.columns + 1) < gridDimension.columns)
                    ? this._gridBubbles[gridPos.rows + 1, gridPos.columns + 1]
                    : null;
                neighbors.downRight.canUseIt = ((gridPos.columns + 1) < gridDimension.columns);
            }
            else
            {
                neighbors.downLeft.gridPosition = new Dimension(gridPos.rows + 1, gridPos.columns - 1);
                neighbors.downLeft.bubble       = (gridPos.columns > 0)
                    ? this._gridBubbles[gridPos.rows + 1, gridPos.columns - 1]
                    : null;
                neighbors.downLeft.canUseIt = gridPos.columns > 0;

                neighbors.downRight.gridPosition = new Dimension(gridPos.rows + 1, gridPos.columns);
                neighbors.downRight.bubble       = this._gridBubbles[gridPos.rows + 1, gridPos.columns];
                neighbors.downRight.canUseIt     = true;
            }
        }

        return(neighbors);
    }
Beispiel #12
0
 public void RemovePeer(Peer toRemove)
 {
     Neighbors.Remove(toRemove);
     MessageState.SentMessages.Remove(toRemove);
 }
Beispiel #13
0
 public virtual void AddNeighbor(Vertex <T> neighbor)
 {
     Neighbors.Add(neighbor);
     neighbor.Neighbors.Add(this);
 }
 public int[] GetNeighboursIDs()
 {
     return(Neighbors.Select(s => s.NeighborNode.ID).ToArray());
 }
 public Neighbor[] GetNeighbours()
 {
     return(Neighbors.ToArray());
 }
Beispiel #16
0
 public void Add(Node neighbor)
 {
     Neighbors.Add(neighbor);
 }
Beispiel #17
0
 /// <summary>
 /// Adds an edge based on the data in the passed-in EdgeToNeighbor instance.
 /// </summary>
 internal void AddDirected(EdgeToNeighbor e)
 {
     Neighbors.Add(e);
 }
Beispiel #18
0
    private bool HasNeighbor(int[] node, int[] neighbor, 
                              out Neighbors node_dir, out Neighbors neighbor_dir)
    {
        node_dir = Neighbors.N;
        neighbor_dir = Neighbors.S;

        int dx = neighbor[0] - node[0];
        int dy = neighbor[1] - node[1];

        if (dy > 0) {
            if (dx < 0) {
                node_dir = Neighbors.NW;
                neighbor_dir = Neighbors.SE;
            } else if (dx == 0) {
                node_dir = Neighbors.N;
                neighbor_dir = Neighbors.S;
            } else /* if (dx > 0) */ {
                node_dir = Neighbors.NE;
                neighbor_dir = Neighbors.SW;
            }
        } else if (dy == 0) {
            if (dx < 0) {
                node_dir = Neighbors.W;
                neighbor_dir = Neighbors.E;
            } else if (dx == 0) {
                return false;
            } else /* if (dx > 0) */ {
                node_dir = Neighbors.E;
                neighbor_dir = Neighbors.W;
            }
        } else /* if (dy < 0) */ {
            if (dx < 0) {
                node_dir = Neighbors.SW;
                neighbor_dir = Neighbors.NE;
            } else if (dx == 0) {
                node_dir = Neighbors.S;
                neighbor_dir = Neighbors.N;
            } else /* if (dx > 0) */ {
                node_dir = Neighbors.SE;
                neighbor_dir = Neighbors.NW;
            }
        }

        if (!HasSurface (node) || !HasSurface (neighbor)) {
            return false;
        }

        bool nodeOpen = !IndexConnectable (node);
        bool neighborOpen = !IndexConnectable (neighbor);

        bool nodeBridged = IsBridged (node);
        bool neighborBridged = IsBridged (neighbor);

        if (nodeOpen && neighborOpen) {
            return true;
        }

        Edge nodeEdge = Edge.North;
        Edge neighborEdge = Edge.South;

        // only allow diagonals if both surfaces are open as above
        if (dx != 0 && dy != 0) {
            return false;
        } else if (dx > 0) {
            nodeEdge = Edge.East;
            neighborEdge = Edge.West;
        } else if (dx < 0) {
            nodeEdge = Edge.West;
            neighborEdge = Edge.East;
        } else if (dy > 0) {
            nodeEdge = Edge.North;
            neighborEdge = Edge.South;
        } else if (dy < 0) {
            nodeEdge = Edge.South;
            neighborEdge = Edge.North;
        }

        bool nodeConnection = EdgeConnectable (node, nodeEdge);
        bool neighborConnection = EdgeConnectable (neighbor, neighborEdge);

        if (nodeConnection && neighborConnection && (nodeBridged || neighborBridged)) {
            return true;
        }

        if (!nodeConnection && !neighborConnection && !(nodeBridged || neighborBridged)) {
            return true;
        }

        return false;
    }
Beispiel #19
0
 public bool IsAdjacentTo(Vertex v)
 {
     return(Neighbors.Any(n => n.Id == v.Id));
 }
Beispiel #20
0
        /// <summary>
        /// Updates the node. This will copy data from another node into this node. Updated elements are checked for equality
        /// and the method will only return true if the node data has been changed.
        ///
        /// <param name="node">the <see cref="ZigBeeNode"> that contains the newer node data.</param>
        /// <returns>true if there were changes made as a result of the update</returns>
        /// </summary>
        public bool UpdateNode(ZigBeeNode node)
        {
            if (!node.IeeeAddress.Equals(IeeeAddress))
            {
                Log.Debug("{IeeeAddress}: Ieee address inconsistent during update <>{NodeIeeeAddress}", IeeeAddress, node.IeeeAddress);
                return(false);
            }

            bool updated = false;

            if (NetworkAddress != 0 && !NetworkAddress.Equals(node.NetworkAddress))
            {
                Log.Debug("{IeeeAddress}: Network address updated from {NetworkAddress} to {NodeNetworkAddress}", IeeeAddress, NetworkAddress, node.NetworkAddress);
                updated        = true;
                NetworkAddress = node.NetworkAddress;
            }

            if (node.NodeDescriptor != null && (NodeDescriptor == null || !NodeDescriptor.Equals(node.NodeDescriptor)))
            {
                Log.Debug("{IeeeAddress}: Node descriptor updated", IeeeAddress);
                updated        = true;
                NodeDescriptor = node.NodeDescriptor;
            }

            if (node.PowerDescriptor != null && (PowerDescriptor == null || !PowerDescriptor.Equals(node.PowerDescriptor)))
            {
                Log.Debug("{IeeeAddress}: Power descriptor updated", IeeeAddress);
                updated         = true;
                PowerDescriptor = node.PowerDescriptor;
            }

            lock (AssociatedDevices)
            {
                if (!AssociatedDevices.SetEquals(node.AssociatedDevices))
                {
                    Log.Debug("{IeeeAddress}: Associated devices updated", IeeeAddress);
                    updated = true;
                    AssociatedDevices.Clear();
                    AssociatedDevices.UnionWith(node.AssociatedDevices);
                }
            }

            lock (BindingTable)
            {
                if (!BindingTable.SetEquals(node.BindingTable))
                {
                    Log.Debug("{IeeeAddress}: Binding table updated", IeeeAddress);
                    updated = true;
                    BindingTable.Clear();
                    BindingTable.UnionWith(node.BindingTable);
                }
            }

            lock (Neighbors)
            {
                if (!Neighbors.SetEquals(node.Neighbors))
                {
                    Log.Debug("{IeeeAddress}: Neighbors updated", IeeeAddress);
                    updated = true;
                    Neighbors.Clear();
                    Neighbors.UnionWith(node.Neighbors);
                }
            }

            lock (Routes)
            {
                if (!Routes.SetEquals(node.Routes))
                {
                    Log.Debug("{IeeeAddress}: Routes updated", IeeeAddress);
                    updated = true;
                    Routes.Clear();
                    Routes.UnionWith(node.Routes);
                }
            }

            // Endpoints are only copied over if they don't exist in the node
            // The assumption here is that endpoints are only set once, and not changed.
            // This should be valid as they are set through the SimpleDescriptor.
            foreach (var endpoint in node.Endpoints)
            {
                if (Endpoints.ContainsKey(endpoint.Key))
                {
                    continue;
                }
                Log.Debug("{IeeeAddress}: Endpoint {EndpointId} added", IeeeAddress, endpoint.Key);
                updated = true;
                Endpoints[endpoint.Key] = endpoint.Value;
            }

            return(updated);
        }
Beispiel #21
0
 public float LowestHeightAt(Neighbors side)
 {
     int hcl = heights[(int)Corners.Left];
     int hcf = heights[(int)Corners.Front];
     int hcr = heights[(int)Corners.Right];
     int hcb = heights[(int)Corners.Back];
     switch(side) {
         case Neighbors.FrontLeftIdx:
             return Mathf.Min(hcl, hcf)+this.z;
         case Neighbors.FrontRightIdx:
             return Mathf.Min(hcr, hcf)+this.z;
         case Neighbors.BackLeftIdx:
             return Mathf.Min(hcl, hcb)+this.z;
         case Neighbors.BackRightIdx:
             return Mathf.Min(hcr, hcb)+this.z;
         default:
             Debug.LogError("given neighbor is not a side edge: "+side);
             return this.z;
     }
 }
Beispiel #22
0
 public Boolean hasNeighbor(NeighborLocation loc)
 {
     return(Neighbors.ContainsKey(loc));
 }
Beispiel #23
0
 public void AddNehigbors(NodeOtelloPiece node) //ta in min pos hitta grannar
 {
     Neighbors.Enqueue(node);
 }
Beispiel #24
0
 /// <summary>Runs the A* search algorithm algorithm on a graph.</summary>
 /// <param name="start">The node to start at.</param>
 /// <param name="neighbors">Delegate for gettign the neighbors of a node.</param>
 /// <param name="heuristic">Computes the heuristic value of a given node in a graph.</param>
 /// <param name="cost">Computes the cost of moving from the current node to a specific neighbor.</param>
 /// <param name="goal">The goal node.</param>
 /// <returns>Stepper of the shortest path or null if no path exists.</returns>
 public static Stepper <T> Astar(T start, Neighbors neighbors, Heuristic heuristic, Cost cost, T goal)
 {
     return(Astar(start, neighbors, heuristic, cost, goal, Equate.Default));
 }
Beispiel #25
0
 public void RemoveRouter(Router router)
 {
     Neighbors.Remove(router);
     Network.RemoveNode(router.Id);
     ReceiveUpdate(new LinkStateAdvertisement(LinkStateAdvertisement.Counter, Id, Network));
 }
Beispiel #26
0
 /// <summary>Runs the A* search algorithm algorithm on a graph.</summary>
 /// <param name="start">The node to start at.</param>
 /// <param name="neighbors">Delegate for gettign the neighbors of a node.</param>
 /// <param name="heuristic">Computes the heuristic value of a given node in a graph.</param>
 /// <param name="cost">Computes the cost of moving from the current node to a specific neighbor.</param>
 /// <param name="goal">The goal node.</param>
 /// <param name="equate">A delegate for checking for equality between two nodes.</param>
 /// <returns>Stepper of the shortest path or null if no path exists.</returns>
 public static Stepper <T> Astar(T start, Neighbors neighbors, Heuristic heuristic, Cost cost, T goal, Equate <T> equate)
 {
     return(Astar(start, neighbors, heuristic, cost, (T node) => { return equate(node, goal); }));
 }
Beispiel #27
0
 void UVMap(MapTile t, Neighbors side, Vector2[] uvs, int idx)
 {
     if(uvs == null) { return; }
     int specIdx;
     if(t.tileSpecs == null || t.tileSpecs.Length == 0) { specIdx = -1; }
     else {
         switch(side) {
             case Neighbors.FrontLeft:  specIdx = t.tileSpecs[0]; break;
             case Neighbors.FrontRight: specIdx = t.tileSpecs[1]; break;
             case Neighbors.BackRight:  specIdx = t.tileSpecs[2]; break;
             case Neighbors.BackLeft:   specIdx = t.tileSpecs[3]; break;
             case Neighbors.Bottom:     specIdx = t.tileSpecs[4]; break;
             case Neighbors.Top:        specIdx = t.tileSpecs[5]; break;
             default:                   specIdx = -1;             break;
         }
     }
     if(specIdx == -1 || specIdx >= tileSpecs.Count || tileSpecs[specIdx] == null || tileSpecs[specIdx].texture == null) {
         uvs[idx+0] = new Vector2(0,0);
         uvs[idx+1] = new Vector2(0,0);
         uvs[idx+2] = new Vector2(0,0);
         uvs[idx+3] = new Vector2(0,0);
     }	else {
     /*			TileSpec spec = tileSpecs[specIdx];*/
         Rect rect = tileRects[specIdx];
         Vector2 ul = new Vector2(rect.x, rect.y);
         Vector2 ll = new Vector2(rect.x, rect.yMax);
         Vector2 ur = new Vector2(rect.xMax, rect.y);
         Vector2 lr = new Vector2(rect.xMax, rect.yMax);
         if(side == Neighbors.FrontLeft) {
             uvs[idx+0] = ll;
             uvs[idx+1] = lr;
             uvs[idx+2] = ul;
             uvs[idx+3] = ur;
         } else if(side == Neighbors.BackLeft) {
             uvs[idx+0] = lr;
             uvs[idx+1] = ur;
             uvs[idx+2] = ll;
             uvs[idx+3] = ul;
         }	else if(side == Neighbors.BackRight) {
             uvs[idx+0] = ur;
             uvs[idx+1] = ul;
             uvs[idx+2] = lr;
             uvs[idx+3] = ll;
         } else if(side == Neighbors.Bottom) {
             uvs[idx+0] = lr;
             uvs[idx+1] = ur;
             uvs[idx+2] = ll;
             uvs[idx+3] = ul;
         } else { //works for front-right and top
             uvs[idx+0] = ul;
             uvs[idx+1] = ll;
             uvs[idx+2] = ur;
             uvs[idx+3] = lr;
         }
     }
 }
Beispiel #28
0
 /// <summary>Runs the Greedy search algorithm algorithm on a graph.</summary>
 /// <param name="start">The node to start at.</param>
 /// <param name="neighbors">Step function for all neigbors of a given node.</param>
 /// <param name="heuristic">Computes the heuristic value of a given node in a graph.</param>
 /// <param name="goal">Predicate for determining if we have reached the goal node.</param>
 /// <returns>Stepper of the shortest path or null if no path exists.</returns>
 public static Stepper <T> Greedy(T start, Neighbors neighbors, Heuristic heuristic, T goal)
 {
     return(Greedy(start, neighbors, heuristic, goal, Equate.Default));
 }
Beispiel #29
0
 public void InsetSidesOfTile(int x, int y, int z, float inset, Neighbors mask)
 {
     MapTile t = TileAt(x,y,z);
     if(t != null) {
         t.InsetSides(inset, mask);
         RemakeMesh();
     }
 }
Beispiel #30
0
 /// <summary>Runs the Greedy search algorithm algorithm on a graph.</summary>
 /// <param name="start">The node to start at.</param>
 /// <param name="neighbors">Step function for all neigbors of a given node.</param>
 /// <param name="heuristic">Computes the heuristic value of a given node in a graph.</param>
 /// <param name="goal">Predicate for determining if we have reached the goal node.</param>
 /// <param name="equate">Delegate for checking for equality between two nodes.</param>
 /// <returns>Stepper of the shortest path or null if no path exists.</returns>
 public static Stepper <T> Greedy(T start, Neighbors neighbors, Heuristic heuristic, T goal, Equate <T> equate)
 {
     return(Greedy(start, neighbors, heuristic, (T node) => { return equate(node, goal); }));
 }
Beispiel #31
0
        /// <summary>
        /// Calculates a path on the graph
        /// If the path is optimal is dependent on the heuristic implemented in the graph
        /// </summary>
        /// <param name="graph">IGraph implementation to search the path on</param>
        /// <param name="start">node in IGraph where the algorithm should start</param>
        /// <param name="goal">node in IGraph where the path should lead</param>
        /// <returns>List of integers wich correspond with the node id's in the IGraph implementation</returns>
        public static List <int> AStarSearch(IGraph graph, int start, int goal)
        {
            if (start == -1)
            {
                throw new System.ArgumentException("Parameter must be equal or larger than zero", "start");
            }
            else if (goal == -1)
            {
                throw new System.ArgumentException("Parameter must be equal or larger than zero", "goal");
            }

            IPriorityQueue           priorityQueue = new MinHeap();
            Dictionary <int, int>    cameFrom      = new Dictionary <int, int>();
            Dictionary <int, double> costSoFar     = new Dictionary <int, double>();
            List <int> path      = new List <int>();
            Neighbors  component = new Neighbors();
            double     newCost;
            double     priority;
            int        current;

            priorityQueue.Add(start, 0);

            cameFrom[start]  = start;
            costSoFar[start] = 0;

            // as long as unvisited nodes are available
            do
            {
                // get element with the best value and remove it from the unvisited nodes
                current = priorityQueue.Poll();

                // test if the current node is the goal
                if (current == goal)
                {
                    break;
                }

                if (!graph.HasComponent <Neighbors>(current))
                {
                    continue;
                }

                component = graph.GetComponent <Neighbors>(current);

                // go through all nodes that are directly connected to the current one
                foreach (int next in component.GetNeighbors())
                {
                    // calculate cost for the current node
                    newCost = costSoFar[current] + component.GetCost(next);

                    // only add the node when it does not exist or when the cost is smaller than the current cost
                    if (!costSoFar.ContainsKey(next) || newCost < costSoFar[next])
                    {
                        // calculate priority and add node to frontier
                        costSoFar[next] = newCost;
                        priority        = newCost + graph.Heuristic(next, goal);
                        priorityQueue.Add(next, priority);
                        cameFrom[next] = current;
                    }
                }
            }while (priorityQueue.Size() > 0);

            // reconstruct path by folloing cameFrom from the goal to the start
            path.Add(current);

            while (cameFrom[current] != start)
            {
                path.Add(cameFrom[current]);
                current = cameFrom[current];
            }

            path.Add(cameFrom[current]);
            path.Reverse();
            return(path);
        }
 public void AddEdge(Vertex <T> vertex)
 => Neighbors.Add(vertex);
Beispiel #33
0
 public void AddNeighbor(GraphNode neighbor)
 {
     Neighbors.Add(neighbor);
 }
 public void AddEdges(params Vertex <T>[] newNeighbors)
 => Neighbors.AddRange(newNeighbors);
Beispiel #35
0
 public void AddNeighborVertex(Edge <T> e)
 {
     Edges.Add(e);
     Neighbors.Add(e.RightVertex);
 }
 public void AddEdges(IEnumerable <Vertex <T> > newNeighbors)
 => Neighbors.AddRange(newNeighbors);
Beispiel #37
0
 void AdjustIsoHeightAt(int idx, Neighbors collidedFace, Vector3 wpos, int dh)
 {
     Map m = (Map)target;
     int ny = idx/(int)m.size.x;
     int nx = idx-(ny*(int)m.size.x);
     int nz = editZ;
     MapTile t = m.TileAt(nx,ny,nz);
     if(t==null) { return; }
     Vector3 tpos = m.InverseTransformPointWorld(wpos);
     Neighbors side = Neighbors.None;
     //get the fractional part of each coord
     /*		Debug.Log("adjust height at "+nx+","+ny+","+nz+", tpos "+tpos+", wpos "+wpos);*/
     tpos.x = modf(tpos.x);
     tpos.y = modf(tpos.y);
       //tpos.z = modf(tpos.z);
     bool top = tpos.z > t.z + (t.maxHeight-t.z)/2;
     /*		Debug.Log("tpos frac "+tpos.x+", "+tpos.y+", "+tpos.z);*/
     if((collidedFace & Neighbors.FrontLeft) != 0) {
         side = Neighbors.FrontLeft;
     } else if((collidedFace & Neighbors.FrontRight) != 0) {
         side = Neighbors.FrontRight;
     } else if((collidedFace & Neighbors.BackRight) != 0) {
         side = Neighbors.BackRight;
     } else if((collidedFace & Neighbors.BackLeft) != 0) {
         side = Neighbors.BackLeft;
     } else { //top or bottom
         top = (collidedFace & Neighbors.Top) != 0;
         if(tpos.x < 0.3 && tpos.y < 0.75 && tpos.y > 0.25) {
             side = Neighbors.FrontLeft;
         } else if(tpos.x > 0.3 && tpos.y < 0.75 && tpos.y > 0.25) {
             side = Neighbors.BackRight;
         } else if(tpos.y < 0.3 && tpos.x < 0.75 && tpos.x > 0.25) {
             side = Neighbors.FrontRight;
         } else if(tpos.y > 0.3 && tpos.x < 0.75 && tpos.x > 0.25) {
             side = Neighbors.BackLeft;
         }
     }
     RegisterUndo("Adjust Tile Height");
     m.AdjustHeightOnSidesOfTile(nx, ny, nz, dh, side, top);
     EditorUtility.SetDirty(target);
 }
 public void RemoveEdge(Vertex <T> vertex)
 => Neighbors.Remove(vertex);
Beispiel #39
0
 void SetTileSpecAt(int idx, Neighbors collidedFace)
 {
     Map m = (Map)target;
     int ny = idx/(int)m.size.x;
     int nx = idx-(ny*(int)m.size.x);
     int nz = editZ;
     RegisterUndo("Paint Tile");
     m.SetTileSpecOnTileAt(specSelectedSpec, nx, ny, nz, collidedFace);
     EditorUtility.SetDirty(target);
 }
 public override string ToString()
 => Neighbors.Aggregate(new StringBuilder($"{Value}: "), (sb, n) => sb.Append($"{n.Value} -> ")).ToString();
Beispiel #41
0
 public void InsetSides(float inset, Neighbors mask)
 {
     if(sideInsets == null || sideInsets.Length == 0) {
         sideInsets = new float[]{0,0,0,0,0,0};
     }
     if((mask & Neighbors.FrontLeft) != 0) {
         sideInsets[0] = inset;
     }
     if((mask & Neighbors.FrontRight) != 0) {
         sideInsets[1] = inset;
     }
     if((mask & Neighbors.BackRight) != 0) {
         sideInsets[2] = inset;
     }
     if((mask & Neighbors.BackLeft) != 0) {
         sideInsets[3] = inset;
     }
     if((mask & Neighbors.Bottom) != 0) {
         sideInsets[4] = inset;
     }
     if((mask & Neighbors.Top) != 0) {
         sideInsets[5] = inset;
     }
 }
Beispiel #42
0
        /// <summary>
        /// Updates the node. This will copy data from another node into this node. Updated elements are checked for equality
        /// and the method will only return true if the node data has been changed.
        ///
        /// <param name="node">the <see cref="ZigBeeNode"> that contains the newer node data.</param>
        /// <returns>true if there were changes made as a result of the update</returns>
        /// </summary>
        public bool UpdateNode(ZigBeeNode node)
        {
            if (!node.IeeeAddress.Equals(IeeeAddress))
            {
                return(false);
            }

            bool updated = false;

            if (!NetworkAddress.Equals(node.NetworkAddress))
            {
                updated        = true;
                NetworkAddress = node.NetworkAddress;
            }

            if (!NodeDescriptor.Equals(node.NodeDescriptor))
            {
                updated        = true;
                NodeDescriptor = node.NodeDescriptor;
            }

            if (!PowerDescriptor.Equals(node.PowerDescriptor))
            {
                updated         = true;
                PowerDescriptor = node.PowerDescriptor;
            }

            lock (AssociatedDevices)
            {
                if (!AssociatedDevices.Equals(node.AssociatedDevices))
                {
                    updated = true;
                    AssociatedDevices.Clear();
                    AssociatedDevices.AddRange(node.AssociatedDevices);
                }
            }

            lock (BindingTable)
            {
                if (!BindingTable.Equals(node.BindingTable))
                {
                    updated = true;
                    BindingTable.Clear();
                    BindingTable.AddRange(node.BindingTable);
                }
            }

            lock (Neighbors)
            {
                if (!Neighbors.Equals(node.Neighbors))
                {
                    updated = true;
                    Neighbors.Clear();
                    Neighbors.AddRange(node.Neighbors);
                }
            }

            lock (Routes)
            {
                if (!Routes.Equals(node.Routes))
                {
                    updated = true;
                    Routes.Clear();
                    Routes.AddRange(node.Routes);
                }
            }

            // TODO: How to deal with endpoints

            return(updated);
        }
Beispiel #43
0
 public void SetTileSpecOnSides(int spec, Neighbors mask)
 {
     if(tileSpecs == null || tileSpecs.Length == 0) {
         tileSpecs = new int[]{-1, -1, -1, -1, -1, -1};
     }
     if((mask & Neighbors.FrontLeft) != 0) {
         tileSpecs[0] = spec;
     }
     if((mask & Neighbors.FrontRight) != 0) {
         tileSpecs[1] = spec;
     }
     if((mask & Neighbors.BackRight) != 0) {
         tileSpecs[2] = spec;
     }
     if((mask & Neighbors.BackLeft) != 0) {
         tileSpecs[3] = spec;
     }
     if((mask & Neighbors.Bottom) != 0) {
         tileSpecs[4] = spec;
     }
     if((mask & Neighbors.Top) != 0) {
         tileSpecs[5] = spec;
     }
 }
Beispiel #44
0
        private void DoNeighbor(Tile tile, Neighbors neighbor)
        {
            Tile target = GetNeighbor(tile, neighbor);

            if (target != null) {
                if (target.isCovered () && !target.isMine ()) {
                    target.Uncover ();
                    if (target.Value == 0) {
                        DoUncover (target);
                    }
                }
            }
        }