Exemplo n.º 1
0
        public bool searchPath(Dictionary<string, string> pathMap)
        {
            PriorityQueue<Node> priorityQueue;
            priorityQueue = new PriorityQueue<Node>();

            priorityQueue.Push(this.begainNode);

            while (!priorityQueue.Empty())
            {
                Node topNode = priorityQueue.Pop();

                #region 判断是否找到目状态
                if (matched(topNode, this.targetNode))
                {
                    MessageBox.Show("Finished!");
                    return true;
                }
                #endregion

                int row = topNode.row_0;
                int col = topNode.col_0;

                if (row > 0 && topNode.cannotAct != Direction.up)
                {
                    Node curNode = new Node(topNode);

                    exchange(curNode, row, col, row - 1, col);
                    curNode.ToString();
                    curNode.cannotAct = Direction.down;

                    if (!pathMap.ContainsKey(curNode.state))
                    {
                        curNode.deepth = topNode.deepth + 1;
                        curNode.value = getValue(curNode, this.targetNode);
                        curNode.row_0 = row - 1;
                        curNode.col_0 = col;
                        priorityQueue.Push(curNode);
                        pathMap.Add(curNode.state, topNode.state);
                    }
                }

                if (row < 2 && topNode.cannotAct != Direction.down)
                {
                    Node curNode = new Node(topNode);

                    exchange(curNode, row, col, row + 1, col);
                    curNode.ToString();
                    curNode.cannotAct = Direction.up;

                    if (!pathMap.ContainsKey(curNode.state))
                    {
                        curNode.deepth = topNode.deepth + 1;
                        curNode.value = getValue(curNode, this.targetNode);
                        curNode.row_0 = row + 1;
                        curNode.col_0 = col;
                        priorityQueue.Push(curNode);
                        pathMap.Add(curNode.state, topNode.state);
                    }
                }

                if (col > 0 && topNode.cannotAct != Direction.left)
                {
                    Node curNode = new Node(topNode);

                    exchange(curNode, row, col, row, col - 1);
                    curNode.ToString();
                    curNode.cannotAct = Direction.left;
                    if (!pathMap.ContainsKey(curNode.state))
                    {
                        curNode.deepth = topNode.deepth + 1;
                        curNode.value = getValue(curNode, this.targetNode);
                        curNode.row_0 = row;
                        curNode.col_0 = col - 1;
                        priorityQueue.Push(curNode);
                        pathMap.Add(curNode.state, topNode.state);
                    }
                }

                if (col < 2 && topNode.cannotAct != Direction.right)
                {
                    Node curNode = new Node(topNode);
                    exchange(curNode, row, col, row, col + 1);
                    curNode.ToString();
                    curNode.cannotAct = Direction.right;
                    if (!pathMap.ContainsKey(curNode.state))
                    {
                        curNode.deepth = topNode.deepth + 1;
                        curNode.value = getValue(curNode, this.targetNode);
                        curNode.row_0 = row;
                        curNode.col_0 = col + 1;
                        priorityQueue.Push(curNode);
                        pathMap.Add(curNode.state, topNode.state);
                    }
                }
            }

            return false;
        }
Exemplo n.º 2
0
        private void AddNode(Node node)
        {
            List<TreeNode> ChildNodes = new List<TreeNode>();

            ChildNodes.Add(new TreeNode(node.ToString()));
            TreeNode Tn = new TreeNode("Status - " + node.IsOnline_ToString());
            Tn.Name = "Status";

            ChildNodes.Add(Tn);

            Tn = new TreeNode();
            Tn.Name = "Version";
            ChildNodes.Add(Tn);

            Tn = new TreeNode();
            Tn.Name = "CRC";
            ChildNodes.Add(Tn);

            Tn = new TreeNode();
            Tn.Name = "Ckp Count";
            ChildNodes.Add(Tn);

            Tn = new TreeNode();
            Tn.Name = "DeviceType";
            ChildNodes.Add(Tn);

            Tn = new TreeNode();
            Tn.Name = "Serial";
            ChildNodes.Add(Tn);

            Tn = new TreeNode();
            Tn.Name = "AppName";
            ChildNodes.Add(Tn);

            TreeNode NewParentNode = new TreeNode("Node - 0x" + node.NodeId.ToString("X2"), ChildNodes.ToArray<TreeNode>());
            NewParentNode.Tag = node;

            tvNodes.Nodes.Add(NewParentNode);
        }
Exemplo n.º 3
0
 private void RefreshGUI(TreeNodeCollection Tree, Node<int> Node)
 {
     if (Node != null)
     {
         String text = Node.ToString();
         if (AdvancedBTree<int>.isLeft(Node))
             text += " (Левый)";
         else
             if (AdvancedBTree<int>.isParent(Node))
                 text += " (Корень)";
             else
                 text += " (Правый)";
         Tree.Add(text);
         RefreshGUI(Tree[Tree.Count - 1].Nodes, Node.Left);
         RefreshGUI(Tree[Tree.Count - 1].Nodes, Node.Right);
     }
 }