예제 #1
0
        public bool IsNewRummy(ICustomBasicList <R> objectList, int howMany, EnumRummyType whatRummy)
        {
            UseSecond = false;
            CheckErrors();
            if (objectList.Count() < howMany)
            {
                return(false);
            }
            GetTempList(objectList);
            CustomBasicList <R> ignoreLinq = objectList.Where(Items => Items.IsObjectIgnored == true).ToCustomBasicList();

            if (ignoreLinq.Count > 0)
            {
                return(false);
            }
            switch (whatRummy)
            {
            case EnumRummyType.Sets:
                _tempList !.RemoveAllOnly(Items => Items.IsObjectWild == true);
                return(_tempList.HasOnlyOne(Items => Items.ReadMainValue));

            case EnumRummyType.Colors:
                _tempList !.RemoveAllOnly(Items => Items.IsObjectWild == true);
                return(_tempList.HasOnlyOne(Items => Items.GetColor));

            case EnumRummyType.Runs:
                return(IsStraight());

            default:
                throw new BasicBlankException("Not Supported");
            }
        }
예제 #2
0
        public bool CanCardUsed(ICustomBasicList <R> objectList, int whatElement, EnumRummyType whatRummy, int howMany = 3)
        {
            bool output = default;

            GetTempList(objectList);
            CheckErrors();
            if (objectList.Count < howMany)
            {
                output = false;
                return(output);
            }
            int thisnum;
            S   thissuit; //0 based

            thisnum  = _tempList ![whatElement].ReadMainValue;
예제 #3
0
        private void PrivateNewRummy <RR>(ICustomBasicList <RR> output, ICustomBasicList <RR> objectList, int howMany, EnumRummyType whatRummy, bool minOnly, bool noWilds = false, bool minWilds = false)
            where RR : IRummmyObject <S, C>, new()
        {
            CustomBasicList <R> firstTemp = objectList.Cast <R>().ToCustomBasicList();

            GetTempList(firstTemp);
            CheckErrors();
            UseSecond = false;
            int wildsUsed = default;
            int maxWildsUsed;

            maxWildsUsed = 100;
            CustomBasicList <R> wildList;
            CustomBasicList <R> mainList = new CustomBasicList <R>();
            CustomBasicList <R> thisList;

            wildList = _tempList.Where(Items => Items.IsObjectWild == true).ToCustomBasicList();
            int WildsNeeded;
            int x;

            switch (whatRummy)
            {
            case EnumRummyType.Colors:
                var colorList = _tempList.Where(Items => Items.IsObjectIgnored == false && Items.IsObjectWild == false).GroupBy(Items => Items.GetColor).ToCustomBasicList();
                colorList.ForEach(thisColor =>
                {
                    thisList  = new CustomBasicList <R>();
                    int count = thisColor.Count();
                    if (count >= howMany)
                    {
                        thisList.AddRange(thisColor);
                        if (minOnly == false)
                        {
                            thisList.AddRange(wildList);
                        }
                    }
                    else if (minOnly == false & count + wildList.Count >= howMany & HasWild == true)
                    {
                        thisList.AddRange(thisColor);
                        thisList.AddRange(wildList);
                    }
                    else if (minOnly == true & HasWild == true & count + wildList.Count > howMany)
                    {
                        thisList.AddRange(thisColor);
                        WildsNeeded = howMany - count;
                        var loopTo  = WildsNeeded - 1;
                        for (x = 0; x <= loopTo; x++)
                        {
                            thisList.Add(wildList[x]);
                        }
                    }
                    if (thisList.Count > mainList.Count)
                    {
                        mainList = thisList;
                    }
                });
                output.ReplaceRange(mainList.Cast <RR>());
                if (output.Count == objectList.Count & UseAll == false)
                {
                    output.RemoveAt(0);
                }
                return;

            case EnumRummyType.Sets:
                int y;
                var setList = _tempList.Where(Items => Items.IsObjectIgnored == false && Items.IsObjectWild == false).GroupBy(Items => Items.ReadMainValue).ToCustomBasicList();
                setList.ForEach(thisSet =>
                {
                    thisList  = new CustomBasicList <R>();
                    int Count = thisSet.Count();
                    if (Count >= howMany)
                    {
                        thisList.AddRange(thisSet);
                        if (minOnly == true & thisList.Count > howMany)
                        {
                            y           = thisList.Count - 1;
                            var loopTo1 = y;
                            for (x = howMany; x <= loopTo1; x++)
                            {
                                thisList.RemoveAt(0);
                            }
                        }
                        if (minOnly == false & wildList.Count > 0 & minWilds == false)     //they did not do else if here.  hopefully still okay
                        {
                            thisList.AddRange(wildList);
                            wildsUsed = 0;
                        }
                    }
                    else if ((minOnly == false | minWilds == true) & Count + wildList.Count >= howMany & HasWild == true)
                    {
                        thisList.AddRange(thisSet);
                        thisList.AddRange(wildList);
                        wildsUsed = wildList.Count;
                    }
                    else if (minOnly == true & HasWild == true & Count + wildList.Count > howMany)
                    {
                        thisList.AddRange(thisSet);
                        WildsNeeded = howMany - Count;
                        var loopTo2 = WildsNeeded;
                        for (x = 1; x <= loopTo2; x++)
                        {
                            thisList.Add(wildList[x - 1]);
                        }
                    }
                    if (wildsUsed < maxWildsUsed & HasWild == true & setList.Count() == mainList.Count & (minOnly == true | minWilds == true))
                    {
                        mainList = thisList;
                    }
                    else if (thisList.Count > mainList.Count & (HasWild == false | wildsUsed < maxWildsUsed & HasWild == true & (minOnly == true | minWilds == true) | HasWild == true & minOnly == false))
                    {
                        mainList = thisList;
                    }
                });
                output.ReplaceRange(mainList.Cast <RR>());
                if (output.Count == objectList.Count & UseAll == false)
                {
                    output.RemoveAt(0);
                }
                return;

            case EnumRummyType.Runs:
                var ourObjects = objectList.Cast <R>().ToCustomBasicList();
                var finTemp    = StraightSet(ourObjects, howMany, minOnly, wildList, noWilds);
                output.ReplaceRange(finTemp.Cast <RR>());
                if (FirstUsed == 2 & HasSecond == true)
                {
                    S   suit;
                    var suitList = _tempList.Where(Items => Items.IsObjectIgnored == false && Items.IsObjectWild == false).GroupBy(Items => Items.GetSuit).ToCustomBasicList();
                    if (suitList.Count == 0)
                    {
                        throw new BasicBlankException("There are no suits available.  If there are really no suits; then fix this");
                    }
                    suit = suitList.First().Key;
                    var runTemp = objectList.Where(Items => Items.GetSuit.Equals(suit) && Items.GetSecondNumber == 1).FirstOrDefault();
                    if (runTemp != null)
                    {
                        output.InsertBeginning(runTemp);     //maybe this should be inserted at beginning (?)
                    }
                }
                return;

            default:
                throw new BasicBlankException("Cannot figure out what rummy type to do");
            }
        }
예제 #4
0
        public DeckRegularDict <D> WhatNewRummy <D>(DeckRegularDict <D> cardList, int howMany, EnumRummyType whatRummy, bool minOnly, bool noWilds = false, bool minWilds = false)
            where D : IRummmyObject <S, C>, IDeckObject, new()
        {
            DeckRegularDict <D> output = new DeckRegularDict <D>();

            PrivateNewRummy(output, cardList, howMany, whatRummy, minOnly, noWilds, minWilds);
            return(output);
        }
예제 #5
0
        public CustomBasicList <R> WhatNewRummy(ICustomBasicList <R> objectList, int howMany, EnumRummyType whatRummy, bool minOnly, bool noWilds = false, bool minWilds = false)
        {
            CustomBasicList <R> output = new CustomBasicList <R>();

            PrivateNewRummy(output, objectList, howMany, whatRummy, minOnly, noWilds, minWilds);
            return(output);
        }