Beispiel #1
0
    public static void CalcDistance(string[,] inputMatrix)
    {
        int size = inputMatrix.GetLength(0);

        int[,] matrix = ParseMatrix(inputMatrix);
        Queue <HelpNode> queue = new Queue <HelpNode>(new[] { startNode });

        while (queue.Count > 0)
        {
            HelpNode currNode = queue.Dequeue();
            int      row      = currNode.Row;
            int      col      = currNode.Col;

            List <HelpNode> children = new List <HelpNode>()
            {
                new HelpNode(row + 1, col), new HelpNode(row - 1, col),
                new HelpNode(row, col + 1), new HelpNode(row, col - 1)
            };

            foreach (var child in children)
            {
                if (inBounds(child.Row, child.Col, size) && matrix[child.Row, child.Col] == 0)
                {
                    matrix[child.Row, child.Col] = matrix[row, col] + 1;
                    queue.Enqueue(new HelpNode(child.Row, child.Col));
                }
            }
        }

        PrintMatrix(matrix);
    }
Beispiel #2
0
        /// <summary>
        /// Tests the two nodes by comparing the names and the children.
        /// </summary>
        /// <param name="nodeA">The first node.</param>
        /// <param name="nodeB">The second node.</param>
        private void TestNodes(HelpNode nodeA, HelpNode nodeB)
        {
            Assert.AreEqual(nodeA.Name, nodeB.Name, "Node name values do not match");
            Assert.AreEqual(nodeA.Children.Count, nodeB.Children.Count, "Child counts do not match");

            for (int i = 0; i < nodeA.Children.Count; i++)
            {
                TestNodes(nodeA.Children[i], nodeA.Children[i]);
            }
        }
Beispiel #3
0
        private void CreateDynamicActions(HelpNode node)
        {
            string action = node.Anchor;
            if (!DynamicActions.ContainsKey(action))
            {
                DynamicActions[action] = new HelpDynamicAction();
            }

            foreach (HelpNode helpNode in node.Contents)
            {
                CreateDynamicActions(helpNode);
            }
        }
Beispiel #4
0
 public HelpContents()
 {
     root = new HelpNode("Help Contents", null, null);
     currentNode = root;
 }
Beispiel #5
0
 public void Add(HelpNode node)
 {
     Contents.Add(node);
 }
Beispiel #6
0
 public HelpContents GoToRoot()
 {
     currentNode = root;
     return this;
 }
Beispiel #7
0
 public HelpContents AddSection(string name, string anchor)
 {
     currentNode = new HelpNode(name, anchor, null);
     root.Add(currentNode);
     return this;
 }