예제 #1
0
        public void TestDeskCheckError()
        {
            Desk tempDesk1 = new Desk();
            int  coloum = 0, row = 0;

            for (Card.Type type = Card.Type.Diamonds; type <= Card.Type.Club; type++)
            {
                for (int i = 1; i <= 13; i++)
                {
                    tempDesk1.AddNewCardInColoum(coloum, new Card(type, (Card.Number)i));
                    coloum++;
                    if (coloum == tempDesk1.AllCardOnDesk.ColoumCard.GetLength(0))
                    {
                        row++;
                        coloum = 0;
                    }
                }
            }
            tempDesk1.CheckError();

            Card tempCard = tempDesk1.RemoveLastCardInColoum(0);

            try
            {
                tempDesk1.CheckError();
                throw new Exception("Test failed");
            }
            catch (ErrorInDeskException)
            {
            }
            tempDesk1.AllCardOnDesk.FreeCard[0] = tempCard;
            tempDesk1.CheckError();

            Desk tempDesk2 = new Desk();

            for (Card.Type type = Card.Type.Diamonds; type <= Card.Type.Spade; type++)
            {
                for (int i = 1; i <= 13; i++)
                {
                    tempDesk2.AddNewCardInColoum(coloum, new Card(type, (Card.Number)i));
                    coloum++;
                    if (coloum == tempDesk2.AllCardOnDesk.ColoumCard.GetLength(0))
                    {
                        row++;
                        coloum = 0;
                    }
                }
            }
            for (Card.Number i = Card.Number.Arch; i <= Card.Number.King; i++)
            {
                tempDesk2.AddNewCardInSortedCard(new Card(Card.Type.Club, i), true);
            }

            tempDesk2.CheckError();
        }
예제 #2
0
        public List <InferResult> Infer()
        {
            List <InferResult> outputResults = new List <InferResult>();
            int nextInferLayer = InferLayer + 1;

            _isInferred = true;

            Desk copyedDesk;
            bool IsMoveToSortedCard = false;

            //Check is there any coloum cards to move to sorted card.
            for (int i = 0; i < CurrentDesk.AllCardOnDesk.ColoumCard.GetLength(0); i++)
            {
                Card tempCard = CurrentDesk.GetLastCardInfoInColoum(i);
                if (tempCard == null)
                {
                    continue;
                }
                if (CurrentDesk.AddNewCardInSortedCard(tempCard))
                {
                    copyedDesk = CurrentDesk.DeepClone();
                    copyedDesk.AddNewCardInSortedCard(tempCard, true);
                    copyedDesk.RemoveLastCardInColoum(i);
                    float winPercent = copyedDesk.CalculateWinPercent();
                    outputResults.Add(new InferResult(copyedDesk, nextInferLayer, winPercent, $"Move {tempCard.Pretty()} to sorted card", Id));
                    IsMoveToSortedCard = true;
                }
            }
            if (IsMoveToSortedCard)
            {
                return(outputResults);
            }

            //Check is there any free cards to move to sorted card.
            for (int i = 0; i < CurrentDesk.AllCardOnDesk.FreeCard.Length; i++)
            {
                Card tempCard = CurrentDesk.GetCardInfoFreeCard(i);
                if (tempCard == null)
                {
                    continue;
                }
                if (CurrentDesk.AddNewCardInSortedCard(tempCard))
                {
                    copyedDesk = CurrentDesk.DeepClone();
                    copyedDesk.AddNewCardInSortedCard(tempCard, true);
                    copyedDesk.RemoveCardInFreeCard(i);
                    float winPercent = copyedDesk.CalculateWinPercent();
                    outputResults.Add(new InferResult(copyedDesk, nextInferLayer, winPercent, $"Move {tempCard.Pretty()} to sorted card", Id));
                    IsMoveToSortedCard = true;
                }
            }

            //Return if any cards moved to sorted card
            if (IsMoveToSortedCard)
            {
                return(outputResults);
            }

            //Check is there any free cards to move to a coloum card.
            copyedDesk = CurrentDesk.DeepClone();
            for (int i = 0; i < CurrentDesk.AllCardOnDesk.FreeCard.Length; i++)
            {
                Card tempCard = CurrentDesk.GetCardInfoFreeCard(i);
                if (tempCard == null)
                {
                    continue;
                }

                for (int coloum = 0; coloum < Config.NumberOfColoum; coloum++)
                {
                    if (copyedDesk.MoveCardFromFreeToColoum(coloum, tempCard))
                    {
                        copyedDesk.RemoveCardInFreeCard(i);
                        float winPercent = copyedDesk.CalculateWinPercent();
                        outputResults.Add(new InferResult(copyedDesk, nextInferLayer, winPercent, $"Move {tempCard.Pretty()} to coloum {coloum}", Id));
                        copyedDesk = CurrentDesk.DeepClone();
                    }
                }
            }

            //Check is there any cards which can be moved to another coloum
            copyedDesk = CurrentDesk.DeepClone();
            for (int sourceColoum = 0; sourceColoum < Config.NumberOfColoum; sourceColoum++)
            {
                if (CurrentDesk.GetLastCardInfoInColoum(sourceColoum) == null)
                {
                    continue;
                }
                for (int sortedCardCounter = 0; sortedCardCounter <= CurrentDesk.GetSortedCardCountInColoum(sourceColoum); sortedCardCounter++)
                {
                    for (int targetColoum = 0; targetColoum < Config.NumberOfColoum; targetColoum++)
                    {
                        if (sourceColoum != targetColoum)
                        {
                            if (copyedDesk.MoveCardFromColoumToColoum(sourceColoum, sortedCardCounter, targetColoum))
                            {
                                float winPercent = copyedDesk.CalculateWinPercent();
                                outputResults.Add(new InferResult(copyedDesk, nextInferLayer, winPercent,
                                                                  $"Move {CurrentDesk.GetCardInfo(sourceColoum, CurrentDesk.GetCardCountInColoum(sourceColoum) - sortedCardCounter - 1).Pretty()} to coloum {targetColoum}",
                                                                  Id));
                                copyedDesk = CurrentDesk.DeepClone();
                            }
                        }
                    }
                }
            }

            //Randomly move a card to free card
            copyedDesk = CurrentDesk.DeepClone();
            for (int freeLoc = 0; freeLoc < Config.NumberOfFreeCardPosition; freeLoc++)
            {
                if (CurrentDesk.GetCardInfoFreeCard(freeLoc) == null)
                {
                    for (int coloum = 0; coloum < Config.NumberOfColoum; coloum++)
                    {
                        if (CurrentDesk.GetLastCardInfoInColoum(coloum) != null)
                        {
                            Card movedCard = copyedDesk.RemoveLastCardInColoum(coloum);
                            copyedDesk.AddNewCardInFreeCard(movedCard);
                            float winPercent = copyedDesk.CalculateWinPercent();
                            outputResults.Add(new InferResult(copyedDesk, nextInferLayer, winPercent, $"Move {movedCard.Pretty()} to free card {freeLoc}", Id));
                            copyedDesk = CurrentDesk.DeepClone();
                        }
                    }
                }
            }

            return(outputResults);
        }