Пример #1
0
        public static PokerPile Pile(int numType, int count)
        {
            var pile = new PokerPile(numType);

            pile.AddPoker(count);
            return(pile);
        }
Пример #2
0
        private PokerPattern SelectBiggerXXXX(PokerPattern lastChuPai, int fromPokerCount, int toPokerCount,
                                              int heartHostCount)
        {
            for (int availableHeartHost = 0; availableHeartHost <= heartHostCount; availableHeartHost++)
            {
                for (int pokerCount = fromPokerCount - availableHeartHost; pokerCount <= toPokerCount; pokerCount++)
                {
                    List <PokerPile> piles = null;
                    if (_pilePool.ContainsKey(pokerCount))
                    {
                        piles = _pilePool[pokerCount];
                    }

                    if (piles != null && piles.Count > 0)
                    {
                        if (pokerCount + availableHeartHost == lastChuPai.PokerCount)
                        {
                            for (int n = 0; n < piles.Count; n++)
                            {
                                PokerPile pile = piles[n];
                                if (_value.Compare(pile.NumType, lastChuPai.MajorNumType) == CompareResult.BIGGER)
                                {
                                    pile.AddPoker(availableHeartHost);
                                    return(new PokerPattern(
                                               PatternType.XXXX,
                                               pile,
                                               pile.NumType,
                                               GetAllPokers(pile, false)));
                                }
                            }
                        }
                        else if (pokerCount + availableHeartHost > lastChuPai.PokerCount)
                        {
                            PokerPile pile = piles[0];
                            pile.AddPoker(availableHeartHost);
                            return(new PokerPattern(
                                       PatternType.XXXX,
                                       pile,
                                       pile.NumType,
                                       GetAllPokers(pile, false)));
                        }
                    }
                }
            }

            return(PokerPattern.NULL);
        }
Пример #3
0
        public void RestoreChaiPaiPile(int numType, int fromPool, int count)
        {
            List <PokerPile> origin = null;

            if (_pilePool.ContainsKey(fromPool))
            {
                origin = _pilePool[fromPool];
            }

            List <PokerPile> to = null;

            if (_pilePool.ContainsKey(fromPool - count))
            {
                to = _pilePool[fromPool - count];
            }

            int leftCount = 0;

            for (int i = 0; i < to.Count; i++)
            {
                PokerPile cur = to[i];
                if (cur.NumType == numType)
                {
                    leftCount = cur.Count;
                    to.RemoveAt(i);
                    break;
                }
            }

            var found = false;

            for (int i = 0; i < origin.Count; i++)
            {
                PokerPile cur = origin[i];
                if (cur.NumType == numType)
                {
                    cur.AddPoker(count + leftCount);
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                InsertPile(new PokerPile(numType, count + leftCount), origin);
            }
        }
Пример #4
0
        public List <PokerPile> RemoveXD(List <Poker> pokers)
        {
            List <Poker> xd = new List <Poker>();
            PokerPile    x  = new PokerPile(PokerNumType.PX, 0);
            PokerPile    d  = new PokerPile(PokerNumType.PD, 0);

            for (int i = 0; i < pokers.Count; i++)
            {
                Poker p = pokers[i];
                if (p.NumType == PokerNumType.PX || p.NumType == PokerNumType.PD)
                {
                    xd.Add(p);
                    if (p.NumType == PokerNumType.PX)
                    {
                        x.AddPoker(1);
                    }
                    else
                    {
                        d.AddPoker(1);
                    }
                }
            }

            if (xd.Count > 0)
            {
                foreach (var p in xd)
                {
                    pokers.Remove(p);
                }
            }

            List <PokerPile> xdPile = new List <PokerPile>();

            if (x.Count > 0)
            {
                xdPile.Add(x);
            }
            if (d.Count > 0)
            {
                xdPile.Add(d);
            }

            return(xdPile);
        }
Пример #5
0
        public MatchResult MatchHeartHost(PokerPile current, int heartHostCount)
        {
            if (current == null)
            {
                return(new MatchResult(PokerLogic.PatternType.NULL, PokerNumType.NULL));
            }

            if (PokerCount > heartHostCount)
            {
                return(new MatchResult(PokerLogic.PatternType.NULL, PokerNumType.NULL));
            }

            if (PokerCount <= heartHostCount)
            {
                if (heartHostCount % PokerCount != 0)
                {
                    return(new MatchResult(PokerLogic.PatternType.NULL, PokerNumType.NULL));
                }

                int       pileCount = heartHostCount / PokerCount;
                PokerPile cur       = current;
                for (int i = 0; i < pileCount; i++)
                {
                    PokerPile newPile = new PokerPile(PokerNumType.PHost);
                    newPile.AddPoker(PokerCount);
                    cur.Next = newPile;
                    cur      = newPile;
                }

                MatchNode nextMatchNode = this;
                for (int i = 0; i < pileCount - 1; i++)
                {
                    if (nextMatchNode != null)
                    {
                        nextMatchNode = nextMatchNode.Next(PokerCount);
                    }
                    else
                    {
                        break;
                    }
                }

                if (nextMatchNode != null)
                {
                    int majorType = nextMatchNode.IsMajor
                        ? (current.NumType == PokerNumType.NULL ? PokerNumType.PHost : current.NumType)
                        : PokerNumType.NULL;

                    if (majorType != PokerNumType.NULL &&
                        majorType != PokerNumType.PHost &&
                        majorType != PokerNumType.PA &&
                        PokerLogic.PatternType.IsStraight(nextMatchNode.PatternType))
                    {
                        int maxPokerNumber =
                            majorType + PokerLogic.PatternType.GetMajorPileCount(nextMatchNode.PatternType);
                        if (maxPokerNumber > PokerNumType.PA)
                        {
                            majorType = majorType - (maxPokerNumber - PokerNumType.PA - 1);
                        }
                    }
                    return(new MatchResult(nextMatchNode.PatternType, majorType));
                }
                else
                {
                    return(new MatchResult(PokerLogic.PatternType.NULL, PokerNumType.NULL));
                }
            }

            if (OrderedNodes.Count <= 0)
            {
                return(new MatchResult(PokerLogic.PatternType.NULL, PokerNumType.NULL));
            }

            for (int i = 0; i < OrderedNodes.Count; i++)
            {
                MatchResult result = OrderedNodes[i].MatchHeartHost(current, heartHostCount);
                if (!result.IsPatternNull)
                {
                    return(result);
                }
            }

            return(new MatchResult(PokerLogic.PatternType.NULL, PokerNumType.NULL));
        }