Esempio n. 1
0
        public PokerPattern Match(PokerPile pile, int heartHostCount, List <Poker> pokers)
        {
            PokerPileChain ppc     = new PokerPileChain(pile, heartHostCount);
            MatchResult    matched = MatchTree.Match(ppc);

            PostProcess(matched, pokers);
            return(new PokerPattern(matched.PatternType, ppc.FirstPile, matched.MajorNumType, pokers));
        }
Esempio n. 2
0
        public PokerPattern Match(List <Poker> pokers)
        {
            PokerPileChain ppc     = BuildPPC(pokers);
            MatchResult    matched = MatchTree.Match(ppc);

            PostProcess(matched, pokers);

            return(new PokerPattern(matched.PatternType, ppc.FirstPile, matched.MajorNumType, pokers));
        }
Esempio n. 3
0
        public MatchResult Match(PokerPileChain ppc)
        {
            if (ppc.IsEmpty)
            {
                return(new MatchResult(PatternType.BUCHU, PokerNumType.NULL));
            }

            if (ppc.PileCount == 0)
            {
                if (!ppc.ContainHeartHost)
                {
                    return(new MatchResult(PatternType.NULL, PokerNumType.NULL));
                }

                MatchNode root = GetRoot(ppc.HeartHostCount);
                if (root == null)
                {
                    return(new MatchResult(PatternType.NULL, PokerNumType.NULL));
                }

                return(root.MatchHeartHost(ppc.Head, ppc.HeartHostCount));
            }

            PokerPile firstPile = ppc.FirstPile;

            if (!ppc.ContainHeartHost)
            {
                MatchNode root = GetRoot(firstPile.Count);
                if (root != null)
                {
                    return(root.Match(null, firstPile, 0));
                }
                else
                {
                    return(new MatchResult(PatternType.NULL, PokerNumType.NULL));
                }
            }
            else
            {
                MatchResult result = new MatchResult(PatternType.NULL, PokerNumType.NULL);
                for (int i = ppc.HeartHostCount; i >= 0; i--)
                {
                    int       pokerCount = firstPile != null ? firstPile.Count : 0;
                    MatchNode root       = GetRoot(pokerCount + i);
                    if (root != null)
                    {
                        result = root.Match(null, firstPile, ppc.HeartHostCount);
                        if (!result.IsPatternNull)
                        {
                            break;
                        }
                    }
                }

                return(result);
            }
        }
Esempio n. 4
0
        public PokerPileChain BuildPPC(List <Poker> pokers)
        {
            List <PokerPile> pileList = new List <PokerPile>();

            List <Poker> pokerList = new List <Poker>();

            if (pokers != null && pokers.Count > 0)
            {
                pokerList.AddRange(pokers);
            }

            List <Poker> heartHosts = RemoveHeartHost(pokerList);

            if (pokerList.Count > 0)
            {
                List <PokerPile> xd = RemoveXD(pokerList);

                Dictionary <int, PokerPile> piles = new Dictionary <int, PokerPile>();
                foreach (var p in pokerList)
                {
                    PokerPile pi = null;

                    if (piles.ContainsKey(p.NumType))
                    {
                        pi = piles[p.NumType];
                    }

                    if (pi == null)
                    {
                        pi = new PokerPile(p.NumType);
                        if (piles.ContainsKey(p.NumType))
                        {
                            piles[p.NumType] = pi;
                        }
                        else
                        {
                            piles.Add(p.NumType, pi);
                        }
                    }

                    pi.AddPoker(1);
                }

                pileList.AddRange(piles.Values);

                if (heartHosts.Count <= 0)
                {
                    ListUtil.QuickSort(pileList, _fullStraightComparer);
                }
                else
                {
                    if (pileList.Count == 2)
                    {
                        if (pokerList.Count + heartHosts.Count == 5)
                        {
                            if (Math.Abs(pileList[0].Count - pileList[1].Count) <= heartHosts.Count)
                            {
                                ListUtil.QuickSort(pileList, _halfComparer);
                            }
                            else
                            {
                                ListUtil.QuickSort(pileList, _fullComparer);
                            }
                        }
                        else if (pokerList.Count + heartHosts.Count == 6)
                        {
                            ListUtil.QuickSort(pileList, _halfStraightComparer);
                        }
                    }
                    else if (pileList.Count >= 3)
                    {
                        ListUtil.QuickSort(pileList, _halfStraightComparer);
                    }
                    else
                    {
                    }
                }

                pileList.AddRange(xd);

                for (int i = 0; i < pileList.Count - 1; i++)
                {
                    pileList[i].Next = pileList[i + 1];
                }
            }

            PokerPile      pile = pileList.Count > 0 ? pileList[0] : null;
            PokerPileChain ppc  = new PokerPileChain(heartHosts.Count);

            ppc.FirstPile = pile;
            return(ppc);
        }