Exemple #1
0
        public CustomBasicList <CustomBasicList <C> > GetPossibleCombinations(int howManyNeeded) //will not take in a condition for this.  too complex otherwise.
        {
            if (howManyNeeded <= 0 || howManyNeeded > _howManyColumns || howManyNeeded > _howManyRows)
            {
                throw new CustomArgumentException(nameof(howManyNeeded), "The number needed can't be less than one or more than rows and columns you have");
            }
            int currentC;
            int currentR;

            void ResetRowColumns()
            {
                currentC = 1;
                currentR = 1;
            }

            ResetRowColumns();
            CustomBasicList <CustomBasicList <C> > output = new CustomBasicList <CustomBasicList <C> >();
            CustomBasicList <CustomBasicList <C> > temps;

            temps = GetSpecificCombo(currentR, currentC, EnumTempInfo.Horizontal, howManyNeeded);
            output.AddRange(temps);
            ResetRowColumns();
            temps = GetSpecificCombo(currentR, currentC, EnumTempInfo.Vertical, howManyNeeded);
            output.AddRange(temps);
            ResetRowColumns();
            temps = GetSpecificCombo(currentR, currentC, EnumTempInfo.DiagRightH, howManyNeeded);
            output.AddRange(temps);
            currentC = _howManyColumns;
            temps    = GetSpecificCombo(currentR, currentC, EnumTempInfo.DiagLeftH, howManyNeeded);
            output.AddRange(temps);
            return(output);
        }
Exemple #2
0
        protected virtual void ReplaceGame()
        {
            //return;
            _ = MainContainer.ReplaceObject <IViewModelData>(); //this has to be replaced before the game obviously.
            Assembly assembly = Assembly.GetAssembly(GetType()) !;
            CustomBasicList <Type> thisList = assembly.GetTypes().Where(items => items.HasAttribute <AutoResetAttribute>()).ToCustomBasicList();

            thisList.AddRange(GetAdditionalObjectsToReset());

            ClearSubscriptions();

            Type?type = MainContainer.LookUpType <IStandardRollProcesses>();

            if (type != null)
            {
                thisList.Add(type); //hopefully this simple.  this allows more parts to be able to be added without a new class
                //useful for dice games.
            }
            //attempt to also unsubscribe to all as well.

            //could do delegates.  however, if not set, then won't do.
            if (MiscDelegates.GetMiscObjectsToReplace != null)
            {
                thisList.AddRange(MiscDelegates.GetMiscObjectsToReplace.Invoke());
            }


            MainContainer.ResetSeveralObjects(thisList);
            _mainGame = MainContainer.ReplaceObject <IBasicGameProcesses <P> >(); //hopefully this works
        }
        public async Task AddSectionAsync(BasicSection thisSection) //now can be all async since the console supports async.
        {
            await Task.Run(() =>
            {
                _alreadyHad   = true;
                var firstList = thisSection.SongList !.ToCustomBasicList();
                if (firstList.Count == 0)
                {
                    throw new BasicBlankException("When getting custom list, can't have 0 songs");
                }

                _pList           = new CustomBasicList <IBaseSong>();
                var howManySongs = PrivateHowManySongs(thisSection, firstList.Count);
                if (howManySongs == 0)
                {
                    throw new BasicBlankException("PrivateHowManySongs Can't Return 0 Songs");
                }

                firstList.ShuffleList(howManySongs); //i think
                if (firstList.Count == 0)
                {
                    throw new BasicBlankException("Can't have 0 songs after shuffling.  Rethink");
                }

                firstList.ForEach(items =>
                {
                    SongsChosen.Add(items.ID); //i think
                });
                _pList = firstList;
                _rList.AddRange(firstList);
            });
        }
        async Task IEverybodyOneProcesses.EverybodyGetsOneAsync(CustomBasicList <int> thisList, int selectedIndex)
        {
            if (_gameContainer.SingleInfo !.CanSendMessage(_gameContainer.BasicData !))
            {
                CustomBasicList <int> sendList = new CustomBasicList <int>();
                sendList.AddRange(thisList);
                sendList.Add(selectedIndex);
                await _gameContainer.Network !.SendAllAsync("everybodygetsone", sendList);
            }
            int player  = _actionContainer.GetPlayerIndex(selectedIndex);
            var newList = thisList.Select(items => new PreviousCard {
                Deck = items, Player = player
            }).ToCustomBasicList();

            _gameContainer !.EverybodyGetsOneList.AddRange(newList);
            int oldCount = _gameContainer.TempActionHandList.Count;

            _gameContainer.TempActionHandList.RemoveGivenList(thisList, System.Collections.Specialized.NotifyCollectionChangedAction.Remove);
            _actionContainer.SetUpGoals();
            if (_gameContainer.TempActionHandList.Count == oldCount)
            {
                throw new BasicBlankException("Did not remove from temphand");
            }
            if (_gameContainer.CanLoadEverybodyGetsOne() == false)
            {
                await LastCardsForEverybodyGetsOneAsync();

                return;
            }
            await _processes.AnalyzeQueAsync();
        }
Exemple #5
0
        public static CustomBasicList <ICard> GetInterfaceList(this IDeckDict <YahtzeeHandsDownCardInformation> thisList)
        {
            CustomBasicList <ICard> output = new CustomBasicList <ICard>();

            output.AddRange(thisList);
            return(output);
        }
        public static CustomBasicList <CustomBasicList <RegularSimpleCard> > PossibleCombinations(this IDeckDict <RegularSimpleCard> thisList, EnumColorList whatColor, int maxs)
        {
            if (maxs < 3 && whatColor == EnumColorList.Red)
            {
                throw new BasicBlankException("Attack must allow 3 cards for combinations");
            }
            int mins;

            if (whatColor == EnumColorList.Red)
            {
                mins = 2;
            }
            else
            {
                mins = 1;
            }
            int x;
            CustomBasicList <int> firstList = new CustomBasicList <int>();
            var loopTo = maxs;

            for (x = mins; x <= loopTo; x++)
            {
                firstList.Add(x);
            }
            var newList = thisList.Where(items => items.Color == whatColor).ToCustomBasicList();
            CustomBasicList <CustomBasicList <RegularSimpleCard> > fullList = new CustomBasicList <CustomBasicList <RegularSimpleCard> >();

            firstList.ForEach(y =>
            {
                var thisCombo = newList.GetCombinations(y);
                fullList.AddRange(thisCombo);
            });
            return(fullList); //looks like has to return a standard list for this one.
        }
Exemple #7
0
        public static CustomBasicList <CustomBasicList <T> > GetAllPossibleCombinations <T>(this CustomBasicList <T> thisList)
        {
            CustomBasicList <CustomBasicList <T> > finList = new CustomBasicList <CustomBasicList <T> >();
            var loopTo = thisList.Count;
            int x;

            for (x = 1; x <= loopTo; x++)
            {
                CustomBasicList <CustomBasicList <T> > tempList = thisList.GetCombinations(x);
                finList.AddRange(tempList);
            }
            return(finList);
        }
        public MoveInfo MoveToMake()
        {
            CustomBasicList <MoveInfo> newList = new CustomBasicList <MoveInfo>();

            _gameContainer.SingleInfo !.MainHandList.ForEach(thisCard =>
            {
                newList.AddRange(MoveList(thisCard.Deck));
                MoveInfo thisMove  = new MoveInfo();
                thisMove.ToDiscard = true;
                thisMove.Deck      = thisCard.Deck;
                newList.Add(thisMove);
            });
            return(newList.GetRandomItem());
        }
Exemple #9
0
        public static void Bind(object viewModel, BindableObject view, BindableObject?content = null)
        {
            //if (StopRun)
            //{
            //    return;
            //}
            Type type = viewModel.GetType();

            if (!(view is VisualElement element))
            {
                return;
            }
            var viewType   = viewModel.GetType();
            var properties = viewType.GetProperties();
            var methods    = viewType.GetMethods().ToCustomBasicList();

            _controls.Clear();
            if (view is VisualElement ee)
            {
                GetChildren(ee);
            }

            if (_controls.Count() == 0 && content is VisualElement vv)
            {
                GetChildren(vv);
            }
            _controls.AddRange(ManuelElements);

            if (_controls.Count == 0)
            {
                return;
            }


            if (_controls.Count == 1 && _controls.Single() == null)
            {
                return;
            }

            BindProperties(_controls, type, properties);
            var pList = methods.Where(x => x.Name.StartsWith("Can")).ToCustomBasicList();

            methods.KeepConditionalItems(x => x.HasCommandAttribute()); //because only
            if (methods.Any(x =>
            {
                if (x.ReturnType.Name != "Task" && x.ReturnType.Name != "Void")
                {
                    return(true);
                }
                return(false);
            }))
            {
                throw new BasicBlankException("Cannot put as command if the return type of any is not void or task.  Rethink");
            }



            BindStandardCommands(_controls, viewModel, methods, properties, pList);
            //do a separate one for combo boxes.  not enough in common with text boxes to do interfaces.
            //too many specialized stuff.
            //if i do right, combo may be easier to use than ever (well see).
        }
        private void LoadLinkList()
        {
            if (AssemblyLinker.ViewModelAssembly == null)
            {
                throw new BasicBlankException("Needs to have view model assembly in order to link list");
            }
            if (AssemblyLinker.ViewAssembly == null)
            {
                throw new BasicBlankException("Needs to have the view assembly in order to link list");
            }
            Assembly mains = GetDefaultAssembly;
            CustomBasicList <Type> viewLists      = GetFilteredList(AssemblyLinker.ViewAssembly, "Views");
            CustomBasicList <Type> viewModelLists = GetFilteredList(AssemblyLinker.ViewModelAssembly, "ViewModels");
            CustomBasicList <Type> mores;

            if (mains != AssemblyLinker.ViewAssembly)
            {
                //more for view assembly
                mores = GetFilteredList(mains, "Views");
                viewLists.AddRange(mores);
            }
            if (mains != AssemblyLinker.ViewModelAssembly)
            {
                //more for view model assembly.
                mores = GetFilteredList(mains, "ViewModels");
                viewModelLists.AddRange(mores);
            }

            AssemblyLinker.ExtraViewModelLocations.ForEach(x =>
            {
                mores = GetFilteredList(x, "ViewModels");
                viewModelLists.AddRange(mores);
            });
            AssemblyLinker.ExtraViewLocations.ForEach(x =>
            {
                mores = GetFilteredList(x, "Views");
                viewLists.AddRange(mores);
            });
            viewModelLists.ForEach(x =>
            {
                string firstName;
                string toUse;
                toUse = "ViewModel";
                string genericName = "`1";
                bool useGenerics   = false;
                if (x.Name.EndsWith(genericName))
                {
                    useGenerics = true;
                }
                if (useGenerics == true)
                {
                    toUse += genericName;
                }
                if (x.Name.EndsWith(toUse) == false)
                {
                    toUse = "VM"; //only vm for abbreviation could be used sometimes.
                    if (useGenerics)
                    {
                        toUse += genericName;
                    }
                }
                if (x.Name.EndsWith(toUse) == true)
                {
                    firstName = x.Name.Substring(0, x.Name.Count() - toUse.Count());

                    Type type = viewLists.Where(y => y.Name == $"{firstName}View").SingleOrDefault();
                    if (type != null)
                    {
                        _linkList.Add(new ViewModelViewLinker
                        {
                            ViewModelType = x,
                            ViewType      = type
                        });
                    }
                }
            });


            viewLists.ForEach(x =>
            {
                cons !.RegisterInstanceType(x);
            });
            //i like the idea of also registering the manuellist as well
            ManuelVMList.ForEach(x =>
            {
                cons !.RegisterInstanceType(x.ViewType !);
            });
            _linkList.AddRange(ManuelVMList); //hopefully this simple.
        }
Exemple #11
0
        public static void PassOutCards <P, D>(this IPlayerCollection <P> playerList, ICustomBasicList <D> thisCol
                                               , int howMany, int testCount, bool noComputerPass, ref DeckRegularDict <D> leftOverList) where P : IPlayerObject <D>, new()
            where D : IDeckObject, new()
        {
            int players;

            players = playerList.Count();
            if (noComputerPass == true)
            {
                int subs = playerList.Count(Items => Items.PlayerCategory == EnumPlayerCategory.Computer);
                players -= subs;
            }
            int newcount;

            newcount  = players * howMany;
            newcount -= testCount; //because less is being dealt out.
            if (newcount > thisCol.Count)
            {
                throw new BasicBlankException("There needs to be at least " + newcount + " cards.  However, there are only " + thisCol.Count + " cards to pass out");
            }
            int x;

            if (newcount == thisCol.Count)
            {
                leftOverList = new DeckRegularDict <D>();
            }
            else
            {
                var loopTo = thisCol.Count;
                if (leftOverList == null)
                {
                    leftOverList = new DeckRegularDict <D>();
                }
                for (x = newcount + 1; x <= loopTo; x++)
                {
                    leftOverList.Add(thisCol[x - 1]);// because 0 based
                }
            }
            int y;

            y = 0;
            CustomBasicList <CustomBasicList <D> > thisList = new CustomBasicList <CustomBasicList <D> >();

            foreach (var newPlayer in playerList)
            {
                CustomBasicList <D> temps = new CustomBasicList <D>();
                temps.AddRange(newPlayer.StartUpList);
                thisList.Add(temps);
            }

            int z;
            var loopTo1 = howMany;

            for (x = 1; x <= loopTo1; x++)
            {
                z = 0;
                foreach (var newPlayer in playerList)
                {
                    if (newPlayer.PlayerCategory == EnumPlayerCategory.Computer && noComputerPass == true)
                    {
                    }
                    else
                    {
                        if (newPlayer.StartUpList.Count == 0)
                        {
                            var TempList = thisList[z];
                            TempList.Add(thisCol[y]);
                            y += 1;
                        }
                        else
                        {
                            newPlayer.StartUpList.RemoveFirstItem(); //i think because the card is implied being added.
                        }
                    }
                    z += 1;
                }
            }
            z = 0;
            foreach (var newPlayer in playerList)
            {
                if (newPlayer.PlayerCategory == EnumPlayerCategory.Computer && noComputerPass == true)
                {
                }
                else
                {
                    newPlayer.MainHandList.ReplaceRange(thisList[z]); // i think
                }
                z += 1;                                               //this could be it.
            }
        }
Exemple #12
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");
            }
        }
Exemple #13
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);
        }