コード例 #1
0
ファイル: SGF_Tree.cs プロジェクト: macomfan/goGo
        private List <byte> PersistNode(SGF_Node node)
        {
            List <byte> result = new List <byte>();

            result.Add((byte)';');
            foreach (SGF_Property property in node.Properties)
            {
                result.AddRange(System.Text.Encoding.ASCII.GetBytes(property.Name));
                result.Add((byte)'[');
                foreach (byte[] value in property.Values)
                {
                    result.AddRange(value);
                }
                result.Add((byte)']');
            }
            if (node.StepChildren.Count == 0)
            {
                if (node.Child != null)
                {
                    result.AddRange(PersistNode(node.Child));
                }
            }
            else
            {
                result.AddRange(PersistTree(node.Child));
                foreach (SGF_Node stepNode in node.StepChildren)
                {
                    result.AddRange(PersistTree(stepNode));
                }
            }
            return(result);
        }
コード例 #2
0
 public void AddNode(SGF_Node node)
 {
     node.parent_ = this;
     if (child_ == null)
     {
         child_ = node;
     }
     else
     {
         stepChildren_.Add(node);
     }
 }
コード例 #3
0
ファイル: SGF_Tree.cs プロジェクト: macomfan/goGo
        private List <byte> PersistTree(SGF_Node node)
        {
            List <byte> result = new List <byte>();

            result.Add((byte)'(');
            result.AddRange(PersistNode(node));
            foreach (SGF_Node stepNode in node.StepChildren)
            {
                result.AddRange(PersistTree(stepNode));
            }
            result.Add((byte)')');
            result.Add((byte)'\n');
            return(result);
        }
コード例 #4
0
ファイル: SGF_Tree.cs プロジェクト: macomfan/goGo
        private SGF_Node ProcessNode(SGF_Node parent, int branchNumber)
        {
            SGF_Node newNode = null;

            if (parent == null)
            {
                newNode = new SGF_Node_Root();
                roots_.Add(newNode as SGF_Node_Root);
            }
            else
            {
                newNode = new SGF_Node(roots_[branchNumber]);
                parent.AddNode(newNode);
            }
            while (!EOF)
            {
                char ch = PeekChar();
                if (IsControlChar(ch))
                {
                    break;
                }
                else if (IsUnusedChar(ch))
                {
                    ReadChar();
                    continue;
                }
                int indexPropertyValueStart = FindToPropertyValueStart();
                if (indexPropertyValueStart == -1)
                {
                    break;
                }
                byte[]       name       = ReadBytes(indexPropertyValueStart - index_);
                string       nameString = Encoding.ASCII.GetString(name);
                SGF_Property propertry  = new SGF_Property(nameString);
                ProcessPropertyValue(propertry);
                newNode.AddProperty(propertry);
            }
            return(newNode);
        }
コード例 #5
0
ファイル: SGF_Tree.cs プロジェクト: macomfan/goGo
        private void ProcessTree(SGF_Node parent, int branchNumber)
        {
            SGF_Node currentNode = parent;

            while (!EOF)
            {
                char ch = ReadToNextControlChar();
                if (ch == ';')
                {
                    currentNode = ProcessNode(currentNode, branchNumber);
                }
                else if (ch == '(')
                {
                    ProcessTree(currentNode, branchNumber);
                }
                else if (ch == ')')
                {
                    //End Tree
                    break;
                }
            }
        }