Example #1
0
        public float CalCardsScore(CardFace[] cardFaces)
        {
            CardsTypeCreater cardCreater = new CardsTypeCreater();

            cardCreater.CreateAllCardsTypeArray(cardFaces);
            CardsTypeInfo info = cardCreater.GetMaxScoreCardsTypeInfo();

            CardInfo[] otherCards = CardsTransform.Instance.CreateRemoveFaceValues(cardFaces, info.cardFaceValues);

            return(CalCardsScore(info, otherCards));
        }
        /// <summary>
        /// 计算确定的牌型CardFaces
        /// </summary>
        /// <returns></returns>
        public CardFace[] ComputeCardFaces(CardFace[] cardFaces, ref CardsType cardsType)
        {
            CardsTypeInfo typeInfo;

            CardInfo[] cardInfos;
            CardFace[] removeLaizi = new CardFace[5];
            CardFace[] computedCardFaces;
            CardFace[] resultCardFaces;
            CardFace[] cardFaces2;
            int        idx = 0;

            if (cardsType == CardsType.None)
            {
                CardsTypeCreater creater = new CardsTypeCreater();
                creater.SetLaizi(laizi);
                creater.CreateAllCardsTypeArray(cardFaces);
                typeInfo    = creater.GetMaxScoreCardsTypeInfo();
                cardsType   = typeInfo.type;
                cardInfos   = CardsTransform.Instance.CreateRemoveFaceValues(cardFaces, typeInfo.cardFaceValues);
                cardFaces2  = CardsTransform.Instance.CreateCardFaces(cardInfos);
                removeLaizi = new CardFace[5];
                cardFaces2  = CardsTransform.Instance.RemoveLaiziByCount(cardFaces2, laizi, typeInfo.laiziCount, removeLaizi);

                computedCardFaces = ComputeCardFaces(typeInfo);
                resultCardFaces   = new CardFace[cardFaces.Length];
                for (int i = 0; i < computedCardFaces.Length; i++)
                {
                    resultCardFaces[idx++] = computedCardFaces[i];
                }
                for (int i = 0; i < cardFaces2.Length; i++)
                {
                    resultCardFaces[idx++] = cardFaces2[i];
                }

                return(resultCardFaces);
            }

            int laiziCount = 0;

            CardInfo[] cards = CardsTransform.Instance.CreateFormatCards(cardFaces, laizi, ref laiziCount);

            typeInfo = new CardsTypeInfo()
            {
                cardFaceValues = CardsTransform.Instance.CreateCardFaces(cards),
                laiziCount     = laiziCount,
                type           = cardsType
            };

            cardInfos   = CardsTransform.Instance.CreateRemoveFaceValues(cardFaces, typeInfo.cardFaceValues);
            cardFaces2  = CardsTransform.Instance.CreateCardFaces(cardInfos);
            removeLaizi = new CardFace[5];
            cardFaces2  = CardsTransform.Instance.RemoveLaiziByCount(cardFaces2, laizi, typeInfo.laiziCount, removeLaizi);

            computedCardFaces = ComputeCardFaces(typeInfo);
            resultCardFaces   = new CardFace[cardFaces.Length];
            for (int i = 0; i < computedCardFaces.Length; i++)
            {
                resultCardFaces[idx++] = computedCardFaces[i];
            }
            for (int i = 0; i < cardFaces2.Length; i++)
            {
                resultCardFaces[idx++] = cardFaces2[i];
            }

            return(resultCardFaces);
        }
Example #3
0
        static void Main(string[] args)
        {
            CardFace[] cardValues = new CardFace[]
            {
                CardFace.Heart_2,
                CardFace.Heart_2,
                CardFace.Heart_5,
                CardFace.Heart_10,
                CardFace.Heart_10,
            };

            CardsTypeDict dict = CardsTypeDict.Instance;


            /////////////////////////////////////////////////
            //2.获取普通牌型组合
            CardsTypeCreater creater = new CardsTypeCreater();

            creater.CreateAllCardsTypeArray(cardValues);
            //获取cardValues牌中的三条牌型表
            List <CardsTypeInfo> santiaos = creater.SantiaoList;

            List <CardsTypeInfo> tonghuaShun  = creater.TonghuashunList;
            List <CardFace>      cardFaceList = new List <CardFace>();
            int idx = 3;

            //for (int i = 0; i < santiaos[idx].cardFaceValues.Length; i++)
            //    cardFaceList.Add(santiaos[idx].cardFaceValues[i]);

            //for (int i = 0; i < santiaos[idx].laiziCount; i++)
            //    cardFaceList.Add(CardFace.RedJoker);

            //CardsTypeMatch match = new CardsTypeMatch();
            //MatchCardFacesInfo info = match.ComputeMatchCardFacesInfo(cardFaceList.ToArray());



            /////////////////////////////////////////////////
            //3.特殊牌型检查
            SpecCardsCheck specCard = new SpecCardsCheck();

            //存储特殊牌型结果(已排好序)
            CardFace[]    outCards         = new CardFace[13];
            CardFace[]    outComputedCards = new CardFace[13];
            SpecCardsType type             = specCard.Check(cardValues, outCards, outComputedCards);

            /////////////////////////////////////////////////
            //4.测试牌型估值
            List <SlotCardsEvalInfo> evalInfoList;
            CardsTypeEvaluation      eval = new CardsTypeEvaluation();
            //eval.SetOptimalSlotCardsEvalInfoCount(10);

            string text = "开始计时";

            Console.WriteLine(text);
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();

            //
            evalInfoList = eval.Evaluation(cardValues);

            stopwatch.Stop();
            //
            long ms = stopwatch.ElapsedMilliseconds;

            text = "用时:" + ms + "毫秒";
            Console.WriteLine(text);
            Console.ReadLine();
        }
        /// <summary>
        /// 判断是否为三顺子
        /// </summary>
        /// <param name="formatCards">CardInfo[] formatCards = CardsTransform.Instance.CreateFormatCards(cardValues, ref laiziCount);</param>
        /// <param name="laiziCount"></param>
        /// <param name="outFaceValues"></param>
        /// <returns></returns>
        public bool IsSanShunZi(CardInfo[] formatCards, int laiziCount, CardFace[] outFaceValues, CardFace[] outComputedFaceValues)
        {
            CardInfo[] cards = formatCards;

            bool ret = false;
            int  n   = 0;
            List <CardsTypeInfo> shunziList  = new List <CardsTypeInfo>();
            List <CardsTypeInfo> shunziList2 = new List <CardsTypeInfo>();

            CardsTypeCreater creater = new CardsTypeCreater();

            creater.CreateShunziArray(cards, laiziCount);
            shunziList.Clear();
            shunziList.AddRange(creater.ShunziList);
            shunziList.AddRange(creater.TonghuashunList);

            for (int i = 0; i < shunziList.Count; i++)
            {
                CardInfo[] cards2      = CardsTransform.Instance.CreateRemoveFaceValues(cards, shunziList[i].cardFaceValues);
                int        laiziCount2 = laiziCount - shunziList[i].laiziCount;
                if (laiziCount2 < 0)
                {
                    continue;
                }

                CardsTypeCreater creater2 = new CardsTypeCreater();
                creater2.CreateShunziArray(cards2, laiziCount2);
                shunziList2.Clear();
                shunziList2.AddRange(creater2.ShunziList);
                shunziList2.AddRange(creater2.TonghuashunList);

                for (int j = 0; j < shunziList2.Count; j++)
                {
                    CardInfo[] cards3      = CardsTransform.Instance.CreateRemoveFaceValues(cards2, shunziList2[j].cardFaceValues);
                    int        laiziCount3 = laiziCount2 - shunziList2[j].laiziCount;
                    if (laiziCount3 < 0)
                    {
                        continue;
                    }

                    if (cards3.Length == 3 &&
                        cards3[0].value + 1 == cards3[1].value &&
                        cards3[1].value + 1 == cards3[2].value)
                    {
                        for (int m = 0; m < 3; m++)
                        {
                            outFaceValues[n++] = CardsTransform.Instance.GetCardFace(cards3[m].value, cards3[m].suit);
                        }
                    }
                    else if (cards3.Length == 2 && laiziCount3 >= 1 &&
                             (cards3[0].value + 1 == cards3[1].value || cards3[0].value + 2 == cards3[1].value))
                    {
                        outFaceValues[n++] = CardsTransform.Instance.GetCardFace(cards3[0].value, cards3[0].suit);
                        outFaceValues[n++] = CardsTransform.Instance.GetCardFace(cards3[1].value, cards3[1].suit);
                        outFaceValues[n++] = CardFace.RedJoker;
                    }
                    else if (cards3.Length == 1 && laiziCount3 >= 2)
                    {
                        outFaceValues[n++] = CardsTransform.Instance.GetCardFace(cards3[0].value, cards3[0].suit);
                        outFaceValues[n++] = CardFace.RedJoker;
                        outFaceValues[n++] = CardFace.RedJoker;
                    }
                    else if (cards3.Length == 0 && laiziCount3 >= 3)
                    {
                        outFaceValues[n++] = CardFace.RedJoker;
                        outFaceValues[n++] = CardFace.RedJoker;
                        outFaceValues[n++] = CardFace.RedJoker;
                    }
                    else
                    {
                        continue;
                    }

                    for (int m = 0; m < shunziList[i].cardFaceValues.Length; m++)
                    {
                        outFaceValues[n++] = shunziList[i].cardFaceValues[m];
                    }
                    for (int m = shunziList[i].cardFaceValues.Length; m < 5; m++)
                    {
                        outFaceValues[n++] = CardFace.RedJoker;
                    }

                    for (int m = 0; m < shunziList2[j].cardFaceValues.Length; m++)
                    {
                        outFaceValues[n++] = shunziList2[j].cardFaceValues[m];
                    }
                    for (int m = shunziList2[j].cardFaceValues.Length; m < 5; m++)
                    {
                        outFaceValues[n++] = CardFace.RedJoker;
                    }

                    ret = true;
                    break;
                }

                if (ret == true)
                {
                    break;
                }
            }

            if (ret == false)
            {
                return(false);
            }

            //
            CardsTypeMatch match = new CardsTypeMatch();

            match.SetLaizi(laizi);

            List <CardFace> cardFaceList = new List <CardFace>();

            for (int i = 0; i <= 2; i++)
            {
                cardFaceList.Add(outFaceValues[i]);
            }
            MatchCardFacesInfo matchInfo1 = match.ComputeMatchCardFacesInfo(cardFaceList.ToArray(), CardsType.ShunZi);

            //
            cardFaceList.Clear();
            for (int i = 3; i <= 7; i++)
            {
                cardFaceList.Add(outFaceValues[i]);
            }
            MatchCardFacesInfo matchInfo2 = match.ComputeMatchCardFacesInfo(cardFaceList.ToArray(), CardsType.ShunZi);

            //
            cardFaceList.Clear();
            for (int i = 8; i <= 12; i++)
            {
                cardFaceList.Add(outFaceValues[i]);
            }
            MatchCardFacesInfo matchInfo3 = match.ComputeMatchCardFacesInfo(cardFaceList.ToArray(), CardsType.ShunZi);

            int k = 0;

            n = 0;

            for (int i = 0; i < matchInfo1.laiziCardFaces.Length; i++)
            {
                if (matchInfo1.laiziCardFaces[i] == CardFace.RedJoker)
                {
                    outFaceValues[n++]         = CardFace.Laizi;
                    outComputedFaceValues[k++] = matchInfo1.computedCardFaces[i];
                }
                else
                {
                    outFaceValues[n++] = matchInfo1.laiziCardFaces[i];
                }
            }

            for (int i = 0; i < matchInfo2.laiziCardFaces.Length; i++)
            {
                if (matchInfo2.laiziCardFaces[i] == CardFace.RedJoker)
                {
                    outFaceValues[n++]         = CardFace.Laizi;
                    outComputedFaceValues[k++] = matchInfo2.computedCardFaces[i];
                }
                else
                {
                    outFaceValues[n++] = matchInfo2.laiziCardFaces[i];
                }
            }

            for (int i = 0; i < matchInfo3.laiziCardFaces.Length; i++)
            {
                if (matchInfo3.laiziCardFaces[i] == CardFace.RedJoker)
                {
                    outFaceValues[n++]         = CardFace.Laizi;
                    outComputedFaceValues[k++] = matchInfo3.computedCardFaces[i];
                }
                else
                {
                    outFaceValues[n++] = matchInfo3.laiziCardFaces[i];
                }
            }

            return(true);
        }
Example #5
0
        void CreateEvalInfo(EvalFuncParamDatas paramDatas)
        {
            CardFace[]               cardFaces            = paramDatas.cardFaces;
            CardsTypeInfo?           curtSlotCardTypeInfo = paramDatas.curtSlotCardTypeInfo;
            List <SlotCardsEvalInfo> slotCardsEvalGroup   = paramDatas.slotCardsEvalGroup;

            List <CardFace>[] evalDatas      = paramDatas.evalDatas;
            CardsTypeInfo?[]  cardsTypeInfos = paramDatas.cardsTypeInfos;
            int slotDepth = paramDatas.slotDepth;

            CardFace[] refLaizi = paramDatas.refLaizi;

            if (curtSlotCardTypeInfo != null)
            {
                //根据赖子牌使用数量,移除当前槽相同数量的赖子牌
                CardFace[] removeLaizi = new CardFace[5];
                cardFaces = CardsTransform.Instance.RemoveLaiziByCount(cardFaces, refLaizi, curtSlotCardTypeInfo.Value.laiziCount, removeLaizi);

                //移除当前槽已使用的牌型牌
                CardInfo[] cardInfos = CardsTransform.Instance.CreateRemoveFaceValues(cardFaces, curtSlotCardTypeInfo.Value.cardFaceValues);
                cardFaces = CardsTransform.Instance.CreateCardFaces(cardInfos);

                //添加数据
                evalDatas[slotDepth].AddRange(curtSlotCardTypeInfo.Value.cardFaceValues);
                evalDatas[slotDepth].AddRange(removeLaizi);
                cardsTypeInfos[slotDepth] = curtSlotCardTypeInfo;
            }

            if (slotDepth == 2)
            {
                int mustSingleCardCount = 5 - evalDatas[0].Count + 5 - evalDatas[1].Count + 3 - evalDatas[2].Count;
                if (cardFaces.Length < mustSingleCardCount)
                {
                    return;
                }

                int   n        = 0;
                int   valueIdx = 0;
                int[] value    = new int[5];

                //尾槽
                SlotCardsEvalInfo evalInfo = new SlotCardsEvalInfo();
                evalInfo.slotCardFaceList[0].AddRange(evalDatas[0]);
                for (int i = 0; i < 5 - evalDatas[0].Count; i++)
                {
                    value[valueIdx++] = CardsTransform.Instance.GetValue(cardFaces[n]);
                    evalInfo.slotCardFaceList[0].Add(cardFaces[n++]);
                }
                evalInfo.slotEval[0] = CalCardsScore(cardsTypeInfos[0].Value, value);


                //中槽
                valueIdx = 0;
                Array.Clear(value, 0, value.Length);
                evalInfo.slotCardFaceList[1].AddRange(evalDatas[1]);
                for (int i = 0; i < 5 - evalDatas[1].Count; i++)
                {
                    value[valueIdx++] = CardsTransform.Instance.GetValue(cardFaces[n]);
                    evalInfo.slotCardFaceList[1].Add(cardFaces[n++]);
                }
                evalInfo.slotEval[1] = CalCardsScore(cardsTypeInfos[1].Value, value);


                //头槽
                valueIdx = 0;
                Array.Clear(value, 0, value.Length);
                evalInfo.slotCardFaceList[2].AddRange(evalDatas[2]);
                for (int i = 0; i < 3 - evalDatas[2].Count; i++)
                {
                    value[valueIdx++] = CardsTransform.Instance.GetValue(cardFaces[n]);
                    evalInfo.slotCardFaceList[2].Add(cardFaces[n++]);
                }
                evalInfo.slotEval[2] = CalCardsScore(cardsTypeInfos[2].Value, value);

                //
                evalInfo.totalEval = evalInfo.slotEval[0] + evalInfo.slotEval[1] + evalInfo.slotEval[2];

                slotCardsEvalGroup.Add(evalInfo);
                return;
            }

            //为下一个槽准备数据
            CardsTypeCreater nextSlotCreater = new CardsTypeCreater();

            nextSlotCreater.CreateAllCardsTypeArray(cardFaces, refLaizi);

            CardsTypeInfo[] info;
            if (nextSlotCreater.IsExistNotSingleCardsType())
            {
                info = nextSlotCreater.GetAllCardsTypeInfo();
            }
            else
            {
                info = nextSlotCreater.GetAllCardsTypeInfo(false);
            }

            for (int i = 0; i < info.Length; i++)
            {
                EvalFuncParamDatas paramDatas2 = new EvalFuncParamDatas()
                {
                    cardFaces            = cardFaces,
                    curtSlotCardTypeInfo = info[i],
                    slotCardsEvalGroup   = slotCardsEvalGroup,
                    evalDatas            = evalDatas,
                    cardsTypeInfos       = cardsTypeInfos,
                    slotDepth            = slotDepth + 1,
                    refLaizi             = refLaizi
                };

                CreateEvalInfo(paramDatas2);
                evalDatas[slotDepth + 1].Clear();
                cardsTypeInfos[slotDepth + 1] = null;
            }
        }