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; }
internal void InsertChain(CupChain cc) { Cup nextTmp = Next; Next = cc.StartCup; cc.StartCup.Prev = this; nextTmp.Prev = cc.EndCup; cc.EndCup.Next = nextTmp; }
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); }