Exemple #1
0
        public int CalculateNodeValue(Day8Node node)
        {
            if (node.NodeValue != 0)
            {
                return(node.NodeValue);
            }

            int        _ret     = 0;
            List <int> childIds = new List <int>();

            if (node.NumChildNodes == 0)
            {
                node.NodeValue = node.Sum();
                return(node.NodeValue);
            }

            foreach (int i in node.MetadataEntries)
            {
                if (node.ChildNodeIds.Count >= i && i > 0)
                {
                    _ret += CalculateNodeValue(resultingNodes.FirstOrDefault(w => w.ID == node.ChildNodeIds[i - 1]));
                }
            }

            node.NodeValue = _ret;
            return(_ret);
        }
Exemple #2
0
        public void RunTree()
        {
            if (this.DataArray.Count == 0)
            {
                return;
                // Exception?
            }

            // Initial node
            Day8Node node = new Day8Node();

            node.ID                 = AssignId();
            node.NumChildNodes      = this.DataArray.Dequeue();
            node.NumMetadataEntries = this.DataArray.Dequeue();
            resultingNodes.Add(node);
            this.CurrentNode = node;

            while (this.CurrentNode != null)
            {
                BuildNextNodes();
            }
        }
Exemple #3
0
        public void BuildNextNodes()
        {
            while (this.CurrentNode.NumChildNodes > this.CurrentNode.ChildNodeIds.Count)
            {
                Day8Node node = new Day8Node();
                node.ID                 = AssignId();
                node.ParentID           = this.CurrentNode.ID;
                node.NumChildNodes      = this.DataArray.Dequeue();
                node.NumMetadataEntries = this.DataArray.Dequeue();
                resultingNodes.Add(node);
                this.CurrentNode = node;
                this.ParentNode.ChildNodeIds.Add(node.ID);

                if (this.CurrentNode.NumChildNodes > this.CurrentNode.ChildNodeIds.Count)
                {
                    BuildNextNodes();
                }
            }

            for (int i = 0; i < this.CurrentNode.NumMetadataEntries; i++)
            {
                this.CurrentNode.MetadataEntries.Add(this.DataArray.Dequeue());
            }

            if (this.CurrentNode.ParentID != -99)
            {
                this.ParentNode.ChildNodesCompleted.Add(this.CurrentNode.ID);
            }

            if (this.CurrentNode.NumChildNodes == this.CurrentNode.ChildNodesCompleted.Count && this.CurrentNode != null)
            {
                CheckParent();

                return;
            }
        }