Esempio n. 1
0
 public int ValueOf(PokerPattern pattern)
 {
     if (PatternType.IsStraight(pattern.Type))
     {
         if (pattern.MajorNumType == PokerNumType.PA)
         {
             return(1);
         }
         else
         {
             return(NumValues[pattern.MajorNumType]);
         }
     }
     else
     {
         if (pattern.MajorNumType == CurrentHost)
         {
             return(PokerNumType.PHost);
         }
         else
         {
             return(NumValues[pattern.MajorNumType]);
         }
     }
 }
Esempio n. 2
0
        public PokerPattern SelectSuperABCDE(PokerPattern lastABCDE, int heartHostCount, bool chaiPai)
        {
            if (lastABCDE == null || lastABCDE.IsNull)
            {
                lastABCDE = NULL_ABCDE;
            }

            List <SelectNode> selectChain = BuildSelectChain(lastABCDE);

            PokerPile selected =
                SelectNormal(PatternType.IsStraight(lastABCDE.Type), selectChain, 0, null, heartHostCount, chaiPai, 5);

            while (selected != null)
            {
                List <Poker> pokers = GetAllPokers(selected, true);
                if (pokers != null)
                {
                    return(_matcher.Match(pokers));
                }
                else
                {
                    var validator = (PRSelectRoot)selectChain[0].Validator;
                    validator.NumType = selected.NumType;
                    BuildPokerPool();
                    selected = SelectNormal(PatternType.IsStraight(lastABCDE.Type), selectChain, 0, null,
                                            heartHostCount,
                                            true, 5);
                }
            }

            return(PokerPattern.NULL);
        }
Esempio n. 3
0
        public List <SelectNode> BuildSelectChain(PokerPattern pattern)
        {
            var list     = new List <SelectNode>();
            var pileList = new List <PokerPile>();
            var headPile = pattern.HeadPile;

            if (headPile == null)
            {
                return(null);
            }

            var nextPile = headPile;

            while (nextPile != null)
            {
                pileList.Add(nextPile);
                nextPile = nextPile.Next;
            }

            var majorCount = PatternType.GetMajorPileCount(pattern.Type);

            if (majorCount > pileList.Count)
            {
                return(null);
            }

            var majorPile = pileList[majorCount - 1];
            var majorNode = _matcher.GetRoot(majorPile.Count);

            if (majorNode == null)
            {
                return(null);
            }

            IPileRelation rootRelation = null;

            if (pattern.Type == PatternType.XXXX)
            {
                rootRelation = new PRSelectXXXX(majorPile.NumType, majorPile.Count, _value);
            }
            else
            {
                rootRelation = new PRSelectRoot(majorPile.NumType, PatternType.IsStraight(pattern.Type),
                                                PatternType.GetMajorPileCount(pattern.Type), _value);
            }

            var rootNode = new SelectNode(majorNode.PokerCount, rootRelation);

            list.Add(rootNode);

            var curNode = majorNode;

            for (int i = majorCount - 2; i >= 0; i--)
            {
                var pile = pileList[i];
                curNode = curNode.Next(pile.Count);
                if (curNode == null)
                {
                    return(null);
                }

                list.Add(new SelectNode(curNode));
            }

            for (int i = pileList.Count - 1, n = majorCount - 1; i > n; i--)
            {
                var pile = pileList[i];
                curNode = curNode.Next(pile.Count);
                if (curNode == null)
                {
                    return(null);
                }

                list.Add(new SelectNode(curNode));
            }

            return(list);
        }
Esempio n. 4
0
        public PokerPattern GetSmallestPatternBiggerThan(PokerPattern lastChuPai, bool chaiPai, bool needBomb,
                                                         int endSelectSize)
        {
            BuildPokerPool();

            if (lastChuPai == null ||
                lastChuPai.IsNull ||
                lastChuPai.Type == PatternType.BUCHU)
            {
                return(SelectChuPai());
            }

            if (lastChuPai.Type == PatternType.XXDD)
            {
                // 如果是王炸就没必要再找下去了。
                return(PokerPattern.NULL);
            }

            if (PatternType.IsBomb(lastChuPai.Type))
            {
                if (needBomb)
                {
                    return(SelectBiggerXXXXOrSuperABCDE(lastChuPai, _heartHosts.Count, chaiPai));
                }
                else
                {
                    return(PokerPattern.NULL);
                }
            }

            var selectChain = BuildSelectChain(lastChuPai);

            if (selectChain == null)
            {
                return(PokerPattern.NULL);
            }

            PokerPile result = SelectNormal(PatternType.IsStraight(lastChuPai.Type), selectChain, 0, null,
                                            _heartHosts.Count, chaiPai, endSelectSize);

            if (result != null)
            {
                int majorNumType = result.NumType == PokerNumType.PHost ? _value.CurrentHost : result.NumType;
                result = AdjustPileOrder(result, lastChuPai.Type);
                return(new PokerPattern(
                           lastChuPai.Type,
                           result,
                           majorNumType,
                           GetAllPokers(result, false)
                           ));
            }
            else
            {
                if (needBomb)
                {
                    return(SelectBiggerXXXXOrSuperABCDE(null, _heartHosts.Count, chaiPai));
                }
                else
                {
                    return(PokerPattern.NULL);
                }
            }
        }