Exemplo 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]);
         }
     }
 }
Exemplo 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);
        }
Exemplo n.º 3
0
        public PokerPile AdjustPileOrder(PokerPile head, int patternType)
        {
            var       piles = new List <PokerPile>();
            PokerPile next  = head;

            while (next != null)
            {
                piles.Add(next);
                next = next.Next;
            }

            int majorCount = PatternType.GetMajorPileCount(patternType);

            if (piles.Count < majorCount)
            {
                return(null);
            }

            for (int i = majorCount - 1; i > 0; i--)
            {
                piles[i].Next = piles[i - 1];
            }

            piles[0].Next = null;

            if (piles.Count > majorCount)
            {
                for (int i = piles.Count - 1; i > majorCount; i--)
                {
                    piles[i].Next = piles[i - 1];
                }

                piles[majorCount].Next = null;
                piles[0].Next          = piles[piles.Count - 1];
            }

            return(piles[majorCount - 1]);
        }
Exemplo n.º 4
0
 public override string ToString()
 {
     return(PatternType.LabelOf(Type));
 }
Exemplo n.º 5
0
        public int Compare(PokerPattern p1, PokerPattern p2)
        {
            if (p1 == null || p2 == null)
            {
                return(CompareResult.PATTERN_NOT_MATCH);
            }

            if (p1.IsNull && !p2.IsNull)
            {
                return(CompareResult.SMALLER);
            }

            if (!p1.IsNull && p2.IsNull)
            {
                return(CompareResult.BIGGER);
            }

            if (p1.IsNull && p2.IsNull)
            {
                return(CompareResult.EQUAL);
            }

            if (p1.Type == PatternType.XXDD)
            {
                return(CompareResult.BIGGER);
            }

            if (p2.Type == PatternType.XXDD)
            {
                return(CompareResult.SMALLER);
            }

            if (PatternType.IsBomb(p1.Type) && !PatternType.IsBomb(p2.Type))
            {
                return(CompareResult.BIGGER);
            }

            if (!PatternType.IsBomb(p1.Type) && PatternType.IsBomb(p2.Type))
            {
                return(CompareResult.SMALLER);
            }

            if (PatternType.IsBomb(p1.Type) && PatternType.IsBomb(p2.Type))
            {
                float c1 = 0;
                float c2 = 0;

                if (p1.Type == PatternType.XXXX)
                {
                    c1 = p1.PokerCount;
                }
                else if (p1.Type == PatternType.SuperABCDE)
                {
                    c1 = 5.5f;
                }

                if (p2.Type == PatternType.XXXX)
                {
                    c2 = p2.PokerCount;
                }
                else if (p2.Type == PatternType.SuperABCDE)
                {
                    c2 = 5.5f;
                }

                float res = c1 - c2;
                if (res > 0.4)
                {
                    return(CompareResult.BIGGER);
                }
                else if (res < -0.4)
                {
                    return(CompareResult.SMALLER);
                }
                else
                {
                    int v1 = ValueOf(p1);
                    int v2 = ValueOf(p2);

                    if (v1 == v2)
                    {
                        return(CompareResult.EQUAL);
                    }

                    if (v1 > v2)
                    {
                        return(CompareResult.BIGGER);
                    }
                    else
                    {
                        return(CompareResult.SMALLER);
                    }
                }
            }

            if (p1.Type == p2.Type && p1.PokerCount == p2.PokerCount)
            {
                int v1 = ValueOf(p1);
                int v2 = ValueOf(p2);

                if (v1 == v2)
                {
                    return(CompareResult.EQUAL);
                }

                if (v1 > v2)
                {
                    return(CompareResult.BIGGER);
                }
                else
                {
                    return(CompareResult.SMALLER);
                }
            }

            return(CompareResult.PATTERN_NOT_MATCH);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
                }
            }
        }