コード例 #1
0
ファイル: Node.cs プロジェクト: watsonyan/boardgo
        public void SetAction(string type, string arg, bool front)
        {
            Action targetAction = FindActionByType(type);

            if (targetAction == null)
            {
                if (front)
                {
                    PrependAction(new Action(type, arg));
                }
                else
                {
                    AddAction(new Action(type, arg));
                }
            }
            else
            {
                if (string.IsNullOrEmpty(arg))
                {
                    actions.Remove(targetAction);
                }
                else
                {
                    LinkedListNode <string> args = targetAction.Args;
                    if (args == null)
                    {
                        targetAction.AddArugment(arg);
                    }
                    else
                    {
                        targetAction.Arg = arg;
                    }
                }
            }
        }
コード例 #2
0
ファイル: Node.cs プロジェクト: watsonyan/boardgo
        public void ExpandAction(Action action)
        {
            Action targetAction = FindActionByType(action.Type);

            if (targetAction == null)
            {
                AddAction(action);
            }
            else
            {
                targetAction.AddArugment(action.Arg);
            }
        }
コード例 #3
0
        char ReadNode(TreeNode tree, StreamReader reader)
        {
            //bool sgf=GF.getParameter("sgfcomments",false);

            char   c = ReadNext(reader);
            Action action;
            //Node n = new Node(((Node)p.content()).number());
            TreeNode node = new TreeNode(tree.EptTreeNum);
            string   s;

            loop : while (true) // read all actions
            {
                BufferN = 0;
                while (true)
                {
                    if (c >= 'A' && c <= 'Z')
                    {
                        Store(c);
                    }
                    // note only capital letters
                    else if (c == '(' || c == ';' || c == ')')
                    {
                        goto goon;
                    }
                    // last property reached
                    // BufferN should be 0 then
                    else if (c == '[')
                    {
                        break;
                    }
                    // end of porperty type, arguments starting
                    else if (c < 'a' || c > 'z')
                    {
                        throw new IOException();
                    }
                    // this is an error
                    c = ReadNext(reader);
                }
                if (BufferN == 0)
                {
                    throw new IOException();
                }
                s = new String(Buffer, 0, BufferN);
                //if (s.Equals("L")) a=new LabelAction(GF);
                //else if (s.equals("M")) a=new MarkAction(GF);
                //else
                action = new Action(s);
                while (c == '[')
                {
                    BufferN = 0;
                    while (true)
                    {
                        c = ReadChar(reader);
                        if (c == '\\')
                        {
                            c = ReadChar(reader);
                            if (/*sgf &&*/ c == '\n')
                            {
                                if (BufferN > 1 && Buffer[BufferN - 1] == ' ')
                                {
                                    continue;
                                }
                                else
                                {
                                    c = ' ';
                                }
                            }
                        }
                        else if (c == ']')
                        {
                            break;
                        }

                        Store(c);
                    }
                    c = ReadNext(reader); // prepare next argument
                    String s1;
                    if (BufferN > 0)
                    {
                        s1 = new String(Buffer, 0, BufferN);
                    }
                    else
                    {
                        s1 = "";
                    }
                    //if (!expand(action, s1))
                    action.AddArugment(s1);
                }
                // no more arguments
                node.AddAction(action);
                if (action.Type.Equals("B") || action.Type.Equals("W"))
                {
                    node.EptTreeNum = node.EptTreeNum + 1;
                }
            } // end of actions has been found
              // append node
goon:
            node.SetMain(tree);
            if (tree.FirstAction == null)
            {
                tree.SetNode(node);
            }
            else
            {
                tree.AddChild(node);
                node.SetMain(tree);
                tree = node;
                if (tree.Parent != null && tree != tree.Parent.FirstChild)
                {
                    tree.EptTreeNum = 2;
                }
            }
            return(c);
        }