Exemplo n.º 1
0
        public bool ExplodeHelper(List <Tuple <SnailNode, SnailDirection> > parents)
        {
            if (parents.Count == 5 && !IsLeaf())
            {
                int leftadd = left.value;

                int i = 4;
                for (; i >= 0; i--)
                {
                    if (parents[i].Item2 == SnailDirection.RIGHT)
                    {
                        break;
                    }
                }
                if (i != -1)
                {
                    SnailNode start = parents[i].Item1.left;
                    while (!start.IsLeaf())
                    {
                        start = start.right;
                    }
                    start.value += leftadd;
                }

                int rightadd = right.value;

                i = 4;
                for (; i >= 0; i--)
                {
                    if (parents[i].Item2 == SnailDirection.LEFT)
                    {
                        break;
                    }
                }
                if (i != -1)
                {
                    SnailNode start = parents[i].Item1.right;
                    while (!start.IsLeaf())
                    {
                        start = start.left;
                    }
                    start.value += rightadd;
                }
                left  = null;
                right = null;
                value = 0;
                return(true);
            }
            else if (IsLeaf())
            {
                return(false);
            }
            else
            {
                List <Tuple <SnailNode, SnailDirection> > pleft  = new List <Tuple <SnailNode, SnailDirection> >(parents.ToArray());
                List <Tuple <SnailNode, SnailDirection> > pright = new List <Tuple <SnailNode, SnailDirection> >(parents.ToArray());
                pleft.Add(new Tuple <SnailNode, SnailDirection>(this, SnailDirection.LEFT));
                pright.Add(new Tuple <SnailNode, SnailDirection>(this, SnailDirection.RIGHT));
                return(left.ExplodeHelper(pleft) || right.ExplodeHelper(pright));
            }
        }
Exemplo n.º 2
0
 public bool IsPair()
 {
     return(left != null && right != null && left.IsLeaf() && right.IsLeaf());
 }