Exemplo n.º 1
0
        public List <MeldType> Calculate(IPinochleHand hand)
        {
            Types = new List <MeldType>();
            int          meldValue = 0;
            List <ICard> cards     = hand.Cards;

            Trump = hand.Trump;

            if (Trump == None)
            {
                throw new Exception("Trump must be set before you can calculate the meld value.");
            }


            var allMeldTypes = GetAllMeldTypes();

            foreach (var meldType in allMeldTypes)
            {
                var addMeldType = true;
                if (hand.Contains(meldType.Cards))
                {
                    if (meldType == MarriageInTrump)
                    {
                        if (Types.Contains(Family))
                        {
                            //do not add
                            addMeldType = false;
                        }
                    }
                    if (Types.Contains(DoubleMarriageInTrump))
                    {
                        //do not add
                        //replace with meld type additional marriage in trump
                        if (Types.Contains(Family))
                        {
                            //do not add
                            DoubleMarriageInTrump.Value = 4;
                            addMeldType = false;
                            Types.Add(DoubleMarriageInTrump);
                            meldValue += meldType.Value;
                        }
                    }
                    if (addMeldType == true)
                    {
                        Types.Add(meldType);
                        meldValue += meldType.Value;
                    }
                }
            }

            MeldValue = meldValue;
            return(Types);
        }
Exemplo n.º 2
0
        public void TestMeld()
        {
            IPinochleHand hand      = _handHelper.GetTestHand();
            int           meldValue = hand.GetMeld();

            foreach (var meldType in hand.Meld.Types)
            {
                Console.WriteLine(meldType.Value + " - " + meldType.Name);
            }
            Console.WriteLine("Meld Total: " + hand.Meld.MeldValue);
            Assert.AreEqual(meldValue, 31);
        }