public static HandCardResult GetHandCardResult(HandCard handCard)
        {
            HandCardResult result = new HandCardResult();

            for (int i = 0; i < _judgeList.Count; i++)
            {
                JudgeFunction judgeFunction = _judgeList[i];
                int           cardNumLimit  = judgeFunction.CardNumLimit;
                if ((cardNumLimit != 0) && (cardNumLimit != handCard.Count))
                {
                    continue;
                }
                if (judgeFunction.Fun.Invoke(handCard))
                {
                    result.Level = judgeFunction.Level;
                    result.Odds  = judgeFunction.Odds;
                    if (judgeFunction.Odds == 0)
                    {
                        result.Odds = CaculateOdds(judgeFunction.Level, handCard);
                    }
                    break;
                }
            }

            // list.Count == 2是因为获取hash时需要OnesDigit
            if ((handCard.Count == 2) || (result.Level >= CardLevel.onesDigitIsZero))
            {
                result.OnesDigit = handCard.OnesDigit;
            }
            return(result);
        }
Esempio n. 2
0
 private static Result JudgeByOnesDigit(HandCardResult a, HandCardResult b)
 {
     if (a.OnesDigit > b.OnesDigit)
     {
         return(Result.win);
     }
     else if (a.OnesDigit == b.OnesDigit)
     {
         return(Result.draw);
     }
     return(Result.lose);
 }
Esempio n. 3
0
        public static int GetOdds(Judger.Result result, HandCardResult a, HandCardResult b)
        {
            int odds = int.MinValue;

            if (result == Judger.Result.win)
            {
                odds = a.Odds;
            }
            else if (result == Judger.Result.lose)
            {
                odds = b.Odds;
            }
            return(odds);
        }
Esempio n. 4
0
        public static void Get(List <Card> cardList, out HandCardResult result)
        {
            int hash = GetHash(cardList);

            if (!_dict.ContainsKey(hash))
            {
                Wrapper        wrapper        = new Wrapper();
                HandCard       handCard       = new HandCard(cardList);
                HandCardResult handCardResult = CardLevelJudgement.GetHandCardResult(handCard);
                wrapper.Result = handCardResult;
                _dict.Add(hash, wrapper);
            }
            result = _dict[hash].Result;
        }
Esempio n. 5
0
        public static Result Judge(HandCardResult a, HandCardResult b)
        {
            if ((a.Level == CardLevel.invalid) || (b.Level == CardLevel.invalid))
            {
                return(Result.invalid);
            }
            //个位数为零 胜 双王
            if ((a.Level == CardLevel.onesDigitIsZero) && (b.Level == CardLevel.twoJoker))
            {
                return(Result.win);
            }
            if (a.Level < b.Level)
            {
                if (a.Level <= CardLevel.straight)
                {
                    return(Result.win);
                }
                else
                {
                    return(JudgeByOnesDigit(a, b));
                }
            }
            else if (a.Level == b.Level)
            {
                if (a.Level <= CardLevel.straight)
                {
                    return(Result.draw);
                }
                else
                {
                    return(JudgeByOnesDigit(a, b));
                }
            }
            else
            //a.Level > b.level
            {
                if (b.Level > CardLevel.straight)
                {
                    return(JudgeByOnesDigit(a, b));
                }
            }

            return(Result.lose);
        }
Esempio n. 6
0
 public LogWrapper(string twoCardHash, HandCardResult resultOfTwoCard, HandCardResult resultOfThreeCard)
 {
     this.TwoCardHash       = twoCardHash;
     this.ResultOfTwoCard   = resultOfTwoCard;
     this.ResultOfThreeCard = resultOfThreeCard;
 }