Esempio n. 1
0
    private void CreateGrid()
    {
        grid = new NodeF[gridSizeX, gridSizeY];
        Vector3 bottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2;

        for (int y = 0; y < gridSizeY; y++)
        {
            for (int x = 0; x < gridSizeX; x++)
            {
                Vector3 worldPoint = bottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.forward * (y * nodeDiameter + nodeRadius);
                bool    Wall       = false;
                bool    Track      = false;

                if (Physics.CheckSphere(worldPoint, nodeRadius, WallMask))
                {
                    Wall = true;
                }
                if (Physics.CheckSphere(worldPoint, nodeRadius, TrackMask))
                {
                    Track = true;
                }

                grid[x, y] = new NodeF(Wall, Track, worldPoint, x, y);
            }
        }
    }
Esempio n. 2
0
    private int GetManhattenDistance(NodeF nodeA, NodeF nodeB)
    {
        int ix = Mathf.Abs(nodeA.gridX - nodeB.gridX);
        int iy = Mathf.Abs(nodeA.gridY - nodeB.gridY);

        return(ix + iy);
    }
Esempio n. 3
0
        public void TestWithDuplicates()
        {
            List <string> list = new List <string>(new[] { "ab", "aa", "c", "d", "e", "e", "f", "f" });
            Frequency     fr   = new Frequency();
            NodeF         f    = fr.Generate(list);

            Assert.AreNotEqual(f, null);
        }
Esempio n. 4
0
        private void Form2_Load(object sender, EventArgs e)
        {
            this.supperPanel1.BackColor = ColorTranslator.FromHtml("#e5e6f0");

            this.supperPanel1.BoxShadow = new VWG.BoxShadow(Color.Gray,2,2,3);
            var node = new NodeF();
            this.treeView1.Nodes.Add(new NodeF());
        }
Esempio n. 5
0
    public void FindPath(Vector3 sPos, Vector3 tPos)
    {
        NodeF StartNode  = grid.NodeFromWorldPosition(sPos);
        NodeF TargetNode = grid.NodeFromWorldPosition(tPos);

        List <NodeF>    OpenList   = new List <NodeF>();
        HashSet <NodeF> ClosedList = new HashSet <NodeF>();

        OpenList.Add(StartNode);

        while (OpenList.Count > 0)
        {
            NodeF CurrentNode = OpenList[0];
            for (int i = 1; i < OpenList.Count; i++)
            {
                if (OpenList[i].FCost < CurrentNode.FCost || OpenList[i].FCost == CurrentNode.FCost && OpenList[i].hCost < CurrentNode.hCost)
                {
                    CurrentNode = OpenList[i];
                }
            }

            OpenList.Remove(CurrentNode);
            ClosedList.Add(CurrentNode);

            if (CurrentNode == TargetNode)
            {
                GetFinalPath(StartNode, TargetNode);
            }

            foreach (NodeF NeighborNode in grid.GetNeighboringNodes(CurrentNode))
            {
                if (!NeighborNode.IsTrack || ClosedList.Contains(NeighborNode))
                {
                    continue;
                }

                int MoveCost = CurrentNode.gCost + GetManhattenDistance(CurrentNode, NeighborNode);

                if (MoveCost < NeighborNode.gCost || !OpenList.Contains(NeighborNode))
                {
                    NeighborNode.gCost  = MoveCost;
                    NeighborNode.hCost  = GetManhattenDistance(NeighborNode, TargetNode);
                    NeighborNode.Parent = CurrentNode;

                    if (!OpenList.Contains(NeighborNode))
                    {
                        OpenList.Add(NeighborNode);
                    }
                }
            }
        }
    }
Esempio n. 6
0
    private void GetFinalPath(NodeF sNode, NodeF eNode)
    {
        List <NodeF> FinalPath   = new List <NodeF>();
        NodeF        CurrentNode = eNode;

        while (CurrentNode != sNode)
        {
            FinalPath.Add(CurrentNode);
            CurrentNode = CurrentNode.Parent;
        }

        FinalPath.Reverse();
        grid.FinalPath = FinalPath;
    }
Esempio n. 7
0
 private void Form2_Load(object sender, EventArgs e)
 {
     this.treeNode1.Expand();
     this.supperPanel1.BackColor = ColorTranslator.FromHtml("#e5e6f0");
     this.supperPanel1.ArrowPosition = VWG.ArrowPosition.Top;
     this.supperPanel1.ArrowStart = (uint)(this.supperPanel1.Width / 2)-4;
     this.supperPanel1.BoxShadow = new VWG.BoxShadow(ColorTranslator.FromHtml("#666"), 3, 3, 10);
     this.supperPanel1.Radius = new CornerRadius(10);
     var node = new NodeF();
     this.treeView1.Nodes.Add(new NodeF());
     this.supperPanel3.LinearGradient = new VWG.LinearGradient("top","#fafafa", "#eaeaea");
     this.jrtLabel1.LinearGradient = new VWG.LinearGradient("top", "#8add6d", "#60b044");
     this.jrtLabel1.HoverLinearGradient=new VWG.LinearGradient("top", "#79d858", "#569e3d");
 }
Esempio n. 8
0
    public List <NodeF> GetNeighboringNodes(NodeF cNode)
    {
        List <NodeF> NeighboringNodes = new List <NodeF>();

        for (int x = -1; x <= 1; x++)
        {
            for (int y = -1; y <= 1; y++)
            {
                if (x == 0 && y == 0)
                {
                    continue;
                }

                int checkX = cNode.gridX + x;
                int checkY = cNode.gridY + y;

                if (checkX >= 0 && checkX < gridSizeX && checkY >= 0 && checkY < gridSizeY)
                {
                    NeighboringNodes.Add(grid[checkX, checkY]);
                }
            }
        }
        return(NeighboringNodes);
    }