Ejemplo n.º 1
0
        private void Move()
        {
            //pickup three cups
            CupChain cc = CurrentCup.RemoveNext(3);

            //select destination cup
            int destinationCupNumber = CurrentCup.Number - 1;

            if (destinationCupNumber < 1)
            {
                destinationCupNumber = CupMax;
            }
            while (cc.Contains(destinationCupNumber))
            {
                destinationCupNumber--;
                if (destinationCupNumber < 1)
                {
                    destinationCupNumber = CupMax;
                }
            }

            //place picked cups
            Cup destinationCup = OrderedCupList[destinationCupNumber - 1];

            destinationCup.InsertChain(cc);

            //select current cup
            CurrentCup = CurrentCup.Next;
        }
Ejemplo n.º 2
0
        internal void InsertChain(CupChain cc)
        {
            Cup nextTmp = Next;

            Next             = cc.StartCup;
            cc.StartCup.Prev = this;
            nextTmp.Prev     = cc.EndCup;
            cc.EndCup.Next   = nextTmp;
        }
Ejemplo n.º 3
0
        public CupChain RemoveNext(int count)
        {
            CupChain cc = new CupChain();

            cc.StartCup = this.Next;
            cc.EndCup   = this.Next;
            for (int i = 0; i < count - 1; i++)
            {
                cc.EndCup = cc.EndCup.Next;
            }

            this.Next           = cc.EndCup.Next;
            cc.EndCup.Next.Prev = this;
            cc.EndCup.Next      = null;
            cc.StartCup.Prev    = null;

            return(cc);
        }