Exemple #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");
            }
        }
Exemple #2
0
        private ICustomBasicList <R> StraightSet(ICustomBasicList <R> objectList, int howMany, bool minOnly, ICustomBasicList <R> wildList, bool noWilds = false)
        {
            ICustomBasicList <R> output = new CustomBasicList <R>();
            bool tempwilds = HasWild;

            if (noWilds == true)
            {
                HasWild = false;
            }
            else if (HasWild == false)
            {
                HasWild = false;
            }
            else
            {
                HasWild = true;
            }
            IEnumerable <R> firstLinq; //we may need that unfortunately.

            if (UseSecond == false)
            {
                firstLinq = from Objects in _tempList
                            where Objects.IsObjectIgnored == false && Objects.IsObjectWild == false
                            orderby Objects.ReadMainValue
                            select Objects;
            }
            else
            {
                firstLinq = from Objects in _tempList
                            where Objects.IsObjectIgnored == false && Objects.IsObjectWild == false
                            select Objects;
            }
            CustomBasicList <R> firstList = new CustomBasicList <R>();

            firstList.AddRange(firstLinq);
            var exps = firstLinq.GroupBy(Items => Items.ReadMainValue).ToCustomBasicList();
            CustomBasicList <R> temps;

            if (NeedMatch == false)
            {
                temps = firstList.GroupBy(Items => Items.ReadMainValue).Select(Items => Items.First()).ToCustomBasicList();
            }
            else
            {
                temps = firstList.GroupBy(Items => new { Items.ReadMainValue, Items.GetSuit }).Select(Items => Items.First()).ToCustomBasicList();
            }
            firstList.ReplaceRange(temps);
            if (NeedMatch == true)
            {
                firstList = firstList.OrderBy(Items => Items.GetSuit).ThenBy(Items => Items.ReadMainValue).ToCustomBasicList();
            }
            else
            {
                firstList = firstList.OrderBy(Items => Items.ReadMainValue).ToCustomBasicList();
            }
            int[]? aObjectIndex;
            aObjectIndex = new int[1];
            bool bStraightFound = default;
            int  lngUnUsedWild  = default;
            int  Start          = default;

            if (HasValidStraight(firstList, wildList, false, howMany, minOnly, ref aObjectIndex, ref lngUnUsedWild, ref Start))
            {
                bStraightFound = true;
            }
            else
            {
                aObjectIndex = null;
                if (HasSecond == true)
                {
                    firstList = new CustomBasicList <R>();
                    firstList.AddRange(firstLinq);
                    if (NeedMatch == true)
                    {
                        firstList = (from Items in firstList
                                     orderby Items.GetSuit ascending, Items.GetSecondNumber ascending
                                     select Items).ToCustomBasicList();
                    }
                    else
                    {
                        firstList = (from Items in firstList
                                     orderby Items.GetSecondNumber
                                     select Items).ToCustomBasicList();
                    }
                }
                if (HasValidStraight(firstList, wildList, true, howMany, minOnly, ref aObjectIndex, ref lngUnUsedWild, ref Start))
                {
                    UseSecond      = true;
                    bStraightFound = true;
                }
            }
            int lngObjectInStraight;
            int lngIndex;

            if (bStraightFound == true)
            {
                lngObjectInStraight = aObjectIndex !.GetUpperBound(0) - 1; // i think
                var loopTo = (long)Start + lngObjectInStraight;
                for (lngIndex = Start; lngIndex <= loopTo; lngIndex++)
                {
                    output.Add(firstList[lngIndex]);
                    if (output.Count == _maxStraight)
                    {
                        break;
                    }
                }
                int intHigh = default;
                int intLow  = default;
                HighLow(ref firstList, output, howMany, minOnly, lngUnUsedWild, ref intHigh, ref intLow);
                FirstUsed = intLow;
                if (HasWild == true)
                {
                    var loopTo1 = wildList.Count() - 1;
                    for (lngIndex = 0; lngIndex <= loopTo1; lngIndex++)
                    {
                        if (lngIndex + 1 <= wildList.Count())
                        {
                            if (output.Count < howMany | minOnly == false)
                            {
                                output.Add(wildList[lngIndex]);
                            }
                        }
                        if (output.Count == _maxStraight)
                        {
                            return(output);
                        }
                    }
                }
            }
            if (output.Count == objectList.Count & UseAll == false)
            {
                firstLinq = from Objects in output
                            where Objects.ReadMainValue == FirstUsed
                            select Objects;
                if (firstLinq.Count() > 0)
                {
                    output.RemoveSpecificItem(firstLinq.First());
                }
                else
                {
                    output.RemoveLastItem();
                }
            }
            aObjectIndex = null;
            int newnum;

            newnum = FirstUsed + output.Count - 1;
            newnum = HighNumber - newnum;
            if (FirstUsed > 0 & newnum < 0)
            {
                FirstUsed += newnum;
            }
            HasWild = tempwilds;
            return(output);
        }
Exemple #3
0
        private bool HasValidStraight(ICustomBasicList <R> firstList, ICustomBasicList <R> wildList, bool bUseSecond, int lngHowMany, bool minonly, ref int[]?aStraightObject, ref int lngUnUsedWild, ref int startAt)
        {
            CustomBasicList <TempObject> aObject = new CustomBasicList <TempObject>();
            TempObject tempObject;
            int        lngObjectIndex = default;
            int        lngIndex;
            int        lngAvailableWild;
            int        lngTotalWild;
            int        lngObjectInStraight;
            int        lngEnd;
            bool       output = true; //this time it was set to true.
            int        intObjectNumber;

            if (firstList.Count + wildList.Count < lngHowMany)
            {
                return(false);
            }
            if (lngHowMany == 1)
            {
                return(true);
            }
            if (HasWild)
            {
                lngTotalWild     = wildList.Count(); // i think
                lngAvailableWild = lngTotalWild;     // 'initally available wild will be same as total wild
                lngUnUsedWild    = lngTotalWild;
            }
            else
            {
                lngTotalWild     = 0;
                lngAvailableWild = 0;
                lngUnUsedWild    = 0;
            }
            S   CurrentSuit;
            var loopTo = firstList.Count - 1;

            for (lngIndex = 0; lngIndex <= loopTo; lngIndex++)
            {
                tempObject = new TempObject();
                if (NeedMatch == true)
                {
                    CurrentSuit     = firstList[lngIndex].GetSuit;
                    tempObject.Suit = CurrentSuit;
                }
                intObjectNumber = firstList[lngIndex].ReadMainValue;
                if (bUseSecond)
                {
                    intObjectNumber = firstList[lngIndex].GetSecondNumber;
                }
                tempObject.ObjectNumber      = intObjectNumber;
                tempObject.IndexinCollection = lngIndex;
                aObject.Add(tempObject);
                lngObjectIndex++; //i think
            }

            if (output == false)
            {
                return(false);
            }
            if (lngObjectIndex + lngTotalWild < lngHowMany)
            {
                return(false);
            }
            lngObjectInStraight = 1;
            startAt             = 0;
            lngEnd = 0;
            var loopTo1 = lngObjectIndex - (long)2;

            for (lngIndex = 0; lngIndex <= loopTo1; lngIndex++)
            {
                if (Math.Abs(aObject[lngIndex].ObjectNumber - aObject[lngIndex + 1].ObjectNumber) == 1 & (NeedMatch == false | NeedMatch == true & aObject[lngIndex].Suit.Equals(aObject[lngIndex + 1].Suit)))
                {
                    lngObjectInStraight += 1;
                    lngEnd = lngIndex + 1;
                }
                else if (HasWild == true)
                {
                    if ((long)(Math.Abs(aObject[lngIndex].ObjectNumber - aObject[lngIndex + 1].ObjectNumber) - 1) <= lngAvailableWild & lngAvailableWild > 0)
                    {
                        if (minonly == true)
                        {
                            if (lngObjectInStraight < lngHowMany)
                            {
                                lngAvailableWild   -= lngHowMany - lngObjectInStraight;
                                lngObjectInStraight = lngObjectInStraight + lngHowMany - lngObjectInStraight;
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            lngObjectInStraight++;
                            lngObjectInStraight = lngObjectInStraight + Math.Abs(aObject[lngIndex].ObjectNumber - aObject[lngIndex + 1].ObjectNumber) - 1;
                            lngAvailableWild   -= Math.Abs(aObject[lngIndex].ObjectNumber - aObject[lngIndex + 1].ObjectNumber) - 1;
                            lngEnd = lngIndex + 1;
                        }
                    }
                    else if (lngObjectInStraight >= lngHowMany)
                    {
                        lngEnd = lngIndex;
                        break;
                    }
                    else
                    if (lngObjectIndex - lngIndex - (long)1 + lngTotalWild >= lngHowMany)
                    {
                        startAt             = lngIndex + 1;
                        lngAvailableWild    = lngTotalWild;
                        lngObjectInStraight = 1;
                        lngEnd = startAt;
                    }
                    else
                    {
                        break;
                    }
                }
                else if (lngObjectInStraight >= lngHowMany)
                {
                    lngEnd = lngIndex;
                    break;
                }
                else
                {
                    startAt             = lngIndex + 1;
                    lngAvailableWild    = lngTotalWild; // 'Make all wild available
                    lngObjectInStraight = 1;
                    lngEnd = startAt;
                }
                if (lngObjectInStraight >= lngHowMany & minonly == true)
                {
                    break;
                }
            }
            if (lngObjectInStraight + lngAvailableWild >= lngHowMany)
            {
                aStraightObject = new int[lngObjectInStraight - (lngTotalWild - lngAvailableWild) + 1];
                long lngPos;
                lngPos = 0;
                var loopTo2 = lngEnd;
                for (lngIndex = startAt; lngIndex <= loopTo2; lngIndex++)
                {
                    aStraightObject[lngPos] = aObject[lngIndex].IndexinCollection;
                    lngPos++;
                }
                output        = true;
                lngUnUsedWild = lngAvailableWild;
            }
            else
            {
                output = false;
            }
            return(output);
        }