Пример #1
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);
        }