Beispiel #1
0
 public int WhoWon(CustomBasicList <YahtzeeResults> resultList) // either 1 or 2.
 {
     if (resultList.Count == 1)
     {
         return(1);// can be only 1
     }
     if (resultList.Count != 2)
     {
         throw new BasicBlankException("Must have 2 items to show the best hands from the players; not " + resultList.Count);
     }
     if (resultList.First().Points > resultList.Last().Points)
     {
         return(1);
     }
     if (resultList.Last().Points > resultList.First().Points)
     {
         return(2);
     }
     if (resultList.First().NumberUsed > resultList.Last().NumberUsed)
     {
         return(1);
     }
     if (resultList.Last().NumberUsed > resultList.First().NumberUsed)
     {
         return(2);
     }
     return(1);
 }
 public void PopulateBoard(CustomBasicList <int> thisList) //this means i can test some conditions.
 {
     if (thisList.Count != 8)
     {
         throw new BasicBlankException("The list must be 8 items");
     }
     _privateBoard.ForEach(thisSpace =>
     {
         if (!(thisSpace.Vector.Column == 3 && thisSpace.Vector.Row == 3))
         {
             thisSpace.Text = thisList.First().ToString();
             thisList.RemoveFirstItem();
             thisSpace.Color = cs.Navy;
         }
         else
         {
             thisSpace.Text  = ""; //just in case i did not clear the board.
             thisSpace.Color = cs.Black;
         }
     });
     if (thisList.Count != 0)
     {
         throw new BasicBlankException("Did not use up all the list. Rethink");
     }
 }
 public string GetWord()
 {
     if (CompletedWord() == false)
     {
         throw new BasicBlankException("Has to complete a word before it can get the word");
     }
     return(_completeList.First().ToString().ToLower() + _completeList[1].ToString().ToLower() + _completeList.Last().ToString().ToLower());
 }
        //this will do without the canexceute version.
        public static CustomBasicList <BoardCommand> GetBoardCommandList(this ISeveralCommands vm)
        {
            CustomBasicList <BoardCommand> output = new CustomBasicList <BoardCommand>();

            Type type = vm.GetType();
            CustomBasicList <MethodInfo> methods = type.GetMethods().ToCustomBasicList(); //decided to just show all methods period.

            //must have no
            methods.ForEach(x =>
            {
                output.Add(new BoardCommand(vm, x, vm.Command, x.Name));
            });
            BoardCommand board = output.First();

            return(output);
        }
Beispiel #5
0
        public static int DominoToPlay(out int whichOne, DominosRegularMainGameClass mainGame, GameBoardCP gameboard)
        {
            whichOne = 0; //until proven otherwise.
            CustomBasicList <MoveInfo> moveList = new CustomBasicList <MoveInfo>();

            mainGame.SingleInfo !.MainHandList.ForEach(thisDomino =>
            {
                for (int x = 1; x <= 2; x++)
                {
                    if (gameboard.IsValidMove(x, thisDomino))
                    {
                        MoveInfo thisMove = new MoveInfo();
                        thisMove.Deck     = thisDomino.Deck;
                        thisMove.WhichOne = x;
                        thisMove.Points   = thisDomino.Points;
                        moveList.Add(thisMove);
                    }
                }
            });
            if (moveList.Count == 0)
            {
                return(0);
            }
            moveList.Sort();
            var finalMove = moveList.First();
            int howMany   = moveList.Count(items => items.Deck == finalMove.Deck);

            if (howMany == 1)
            {
                whichOne = finalMove.WhichOne;
                return(finalMove.Deck);
            }
            RandomGenerator rs = mainGame.MainContainer.Resolve <RandomGenerator>();

            whichOne = rs.GetRandomNumber(2);
            return(finalMove.Deck);
        }
Beispiel #6
0
        private static void BindStandardCommands(CustomBasicList <VisualElement> controls, object viewModel, IEnumerable <MethodInfo> methods, IEnumerable <PropertyInfo> properties, IEnumerable <MethodInfo> predicates)
        {
            Type          type = viewModel.GetType();
            VisualElement view = controls.First();
            //i can use classid.  can't do name this time
            //the best i can do is classid.

            CustomBasicList <MethodInfo> specialList = methods.Where(x => x.HasOpenAttribute()).ToCustomBasicList();

            if (specialList.Count > 1)
            {
                throw new BasicBlankException("You had more than one open child attribute.  Rethink");
            }
            MethodInfo?  openRealMethod  = specialList.SingleOrDefault();
            PropertyInfo?openFunProperty = null;

            if (openRealMethod != null)
            {
                openFunProperty = properties.Where(x => x.Name == "CanOpenChild").SingleOrDefault();
                if (openFunProperty == null)
                {
                    throw new BasicBlankException("Did not detect CanOpenChild function in the view model.  Rethink");
                }
            }
            foreach (var method in methods)
            {
                if (method.ReturnType.Name != "Task" && method.ReturnType.Name != "Void")
                {
                    continue; //do more in the loop but can't consider this one because only void and task are supported.
                }
                bool   isOpenChild = method.Equals(openRealMethod);
                string searchName;
                searchName = GetSearchName(method);
                var controlList = controls.Where(x => x.GetName().Equals(searchName, StringComparison.InvariantCultureIgnoreCase) || x.GetName().Equals(method.Name, StringComparison.InvariantCultureIgnoreCase)).ToCustomBasicList();
                foreach (var foundControl in controlList)
                {
                    if (foundControl == null)
                    {
                        continue;
                    }
                    var        foundProperty = properties.FirstOrDefault(x => x.Name == "Can" + searchName);
                    MethodInfo?validateM     = null;
                    ICommand   command;
                    if (foundProperty == null && isOpenChild == false)
                    {
                        validateM = predicates.FirstOrDefault(x => x.Name == "Can" + searchName);
                    }
                    else if (isOpenChild == true && openFunProperty != null)
                    {
                        foundProperty = openFunProperty;
                    }
                    if (foundProperty != null && validateM != null)
                    {
                        throw new BasicBlankException("Cannot have the can for both property and method.  Rethink");
                    }

                    command = GetCommand(viewModel, method, validateM, foundProperty);


                    //if (foundControl is Button button)
                    //{
                    //    button.Command = command;
                    //}
                    //else if (foundControl is GraphicsCommand gg)
                    //{
                    //    gg.Command = command;
                    //}
                    TrySetCommand(foundControl, command);
                }
            }
        }
Beispiel #7
0
        public DeckRegularDict <MexicanDomino> GetTrainList(DeckObservableDict <MexicanDomino> piecesCollection, int givenNumber)
        {
            DeckRegularDict <MexicanDomino> output;
            Dictionary <int, MexicanDomino> matchingPieces = new Dictionary <int, MexicanDomino>();
            List <int> Positions = new List <int>();
            DeckObservableDict <MexicanDomino> TempList = new DeckObservableDict <MexicanDomino>();

            foreach (var currentPiece in piecesCollection)
            {
                TempList.Add(currentPiece);
            }
            bool     anyPieceMatch = false;
            int      count         = 1;
            DateTime newTime;

            newTime = DateTime.Now.AddSeconds(5);
            foreach (var currentPiece in piecesCollection)
            {
                if ((currentPiece.CurrentFirst == givenNumber) | (currentPiece.CurrentSecond == givenNumber))
                {
                    MexicanDomino newPiece = new MexicanDomino();
                    newPiece.CurrentFirst  = currentPiece.CurrentFirst;
                    newPiece.CurrentSecond = currentPiece.CurrentSecond;
                    newPiece.Deck          = currentPiece.Deck;
                    newPiece.CurrentFirst  = currentPiece.CurrentFirst;
                    newPiece.Keeps         = currentPiece.Keeps;
                    newPiece.CurrentSecond = currentPiece.CurrentSecond;
                    newPiece.Status        = currentPiece.Status;
                    newPiece.Train         = currentPiece.Train;
                    Positions.Add(count);
                    matchingPieces.Add(count, newPiece);
                    anyPieceMatch = true;
                }
                count += 1;
            }
            if (anyPieceMatch == false)
            {
                return(new DeckRegularDict <MexicanDomino>());
            }
            CustomBasicList <CustomBasicList <MexicanDomino> > allTrains = new CustomBasicList <CustomBasicList <MexicanDomino> >();

            count = 1;
            // Searching for Trains
            foreach (var currentPiece in matchingPieces.Values)
            {
                // Searching for Train
                CustomBasicList <MexicanDomino> train = new CustomBasicList <MexicanDomino>();
                if (currentPiece.CurrentFirst != givenNumber)
                {
                    ReplacePieceFirstSecond(currentPiece);
                }
                train.Add(currentPiece);
                // All Pieces Clone with Removing the first matched
                var allPieces = CloneList(TempList);
                allPieces.RemoveAt(Positions[count - 1] - 1); // 0 based
                int           i        = 1;
                MexicanDomino trainEnd = currentPiece;
                CustomBasicList <CustomBasicList <MexicanDomino> > trainPieceList  = new CustomBasicList <CustomBasicList <MexicanDomino> >();
                CustomBasicList <CustomBasicList <MexicanDomino> > trainSecondList = new CustomBasicList <CustomBasicList <MexicanDomino> >();
                CustomBasicList <MexicanDomino> trainDominoList = new CustomBasicList <MexicanDomino>();
                CustomBasicList <int>           trainIndexList  = new CustomBasicList <int>();
                while (i <= allPieces.Count)
                {
                    MexicanDomino piece;
                    piece = allPieces[i - 1]; // because 0 based
                    if (piece.CurrentFirst == trainEnd.CurrentSecond)
                    {
                        trainPieceList.Add(CloneList(allPieces));
                        trainSecondList.Add(CloneList(train));
                        trainDominoList.Add(CloneDominoPiece(trainEnd));
                        train.Add(piece);
                        allPieces.RemoveAt(i - 1); // 0 based
                        trainEnd = piece;
                        i        = 1;
                    }
                    else if (piece.CurrentSecond == trainEnd.CurrentSecond)
                    {
                        trainPieceList.Add(CloneList(allPieces));
                        trainSecondList.Add(CloneList(train));
                        trainDominoList.Add(CloneDominoPiece(trainEnd));
                        trainIndexList.Add(i + 1);
                        ReplacePieceFirstSecond(piece);
                        train.Add(piece);
                        allPieces.RemoveAt(i - 1); // 0 based
                        trainEnd = piece;
                        i        = 1;
                    }
                    else
                    {
                        if (i < allPieces.Count)
                        {
                            i += 1;
                        }
                        else if ((trainPieceList.Count > 0) & (i >= allPieces.Count) & trainIndexList.Count > 0)
                        {
                            allTrains.Add(CloneList(train));
                            if (allPieces.Count == 0)
                            {
                                throw new BasicBlankException("allpieces has nothing left");
                            }
                            allPieces = trainPieceList.First();
                            trainPieceList.RemoveAt(0);
                            if (trainSecondList.Count == 0)
                            {
                                throw new BasicBlankException("trainsecondlist has nothing left");
                            }
                            train = trainSecondList.First();
                            trainSecondList.RemoveAt(0);
                            if (trainDominoList.Count == 0)
                            {
                                throw new BasicBlankException("traindominolist has nothing left");
                            }
                            trainEnd = trainDominoList.First();
                            trainDominoList.RemoveAt(0);
                            if (trainIndexList.Count == 0)
                            {
                                i++;
                            }
                            else
                            {
                                i = trainIndexList.First();
                                trainIndexList.RemoveAt(0);
                            }
                        }
                        else
                        {
                            // Saves the current list
                            allTrains.Add(CloneList(train));

                            // No more List possible
                            break;
                        }
                        if (DateTime.Now > newTime)
                        {
                            // MsgBox("taking too long")
                            break;
                        }
                    }
                }
                if (train.Count > 0)
                {
                    allTrains.Add(CloneList(train));
                }
                if (DateTime.Now > newTime)
                {
                    break;
                }
                count += 1;
            }
            int  j                   = 1;
            int  piecesCount         = 0;
            bool multiplePiecesCount = false;
            CustomBasicList <int> piecesPositions = new CustomBasicList <int>();

            while (j <= allTrains.Count)
            {
                CustomBasicList <MexicanDomino> currentTrain;
                currentTrain = allTrains[j - 1]; // 0 based
                if (currentTrain.Count > piecesCount)
                {
                    piecesCount         = currentTrain.Count;
                    multiplePiecesCount = false;
                    piecesPositions.Clear();
                    piecesPositions.Add(j);
                }
                else if (currentTrain.Count == piecesCount)
                {
                    multiplePiecesCount = true;
                    piecesPositions.Add(j);
                }
                j += 1;
            }
            CustomBasicList <MexicanDomino> tempCol;

            if (!multiplePiecesCount)
            {
                tempCol = allTrains[piecesPositions[0] - 1]; // try 0 based here
                output  = new DeckRegularDict <MexicanDomino>();
                MexicanDomino newDomino;
                foreach (var thisDomino in tempCol)
                {
                    newDomino = piecesCollection.GetSpecificItem(thisDomino.Deck);
                    newDomino.CurrentFirst  = thisDomino.CurrentFirst;
                    newDomino.CurrentSecond = thisDomino.CurrentSecond;
                    piecesCollection.RemoveObjectByDeck(newDomino.Deck); // try this way
                    output.Add(newDomino);
                }
                return(output);
            }
            else
            {
                int points;
                int bestPoints   = 0;
                int bestPosition = 0;
                var loopTo       = piecesPositions.Count - 1;
                for (points = 0; points <= loopTo; points++)
                {
                    int totalPoints = 0;
                    CustomBasicList <MexicanDomino> currentTrain = allTrains[piecesPositions[points] - 1]; // 0 based
                    foreach (var piece in currentTrain)
                    {
                        totalPoints += piece.Points;
                    }

                    if (totalPoints > bestPoints)
                    {
                        bestPosition = points;
                    }
                }
                tempCol = allTrains[piecesPositions[bestPosition] - 1]; // 0 based
                output  = new DeckRegularDict <MexicanDomino>();
                MexicanDomino NewDomino;
                foreach (var ThisDomino in tempCol)
                {
                    NewDomino = piecesCollection.GetSpecificItem(ThisDomino.Deck);
                    NewDomino.CurrentFirst  = ThisDomino.CurrentFirst;
                    NewDomino.CurrentSecond = ThisDomino.CurrentSecond;
                    piecesCollection.RemoveSpecificItem(NewDomino); // try this way
                    output.Add(NewDomino);
                }
                return(output);
            }
        }