Exemplo n.º 1
0
        public PlayerHandInfo GetPlayerHandInfo(HoleCards holeCards, List <Card> boardCards = null)
        {
            HandType handType = HandType.Invalid;

            Colour handColour = Colour.Invalid;
            Rank   mainRank   = Rank.Invalid;
            Rank   secondRank = Rank.Invalid;

            if (boardCards != null)
            {
                handType = EvaluateHand(holeCards, boardCards, out handColour, out mainRank, out secondRank);
            }
            else
            {
                handType = EvaluateHand(holeCards);
            }

            PlayerHandInfo playerHandInfo;

            playerHandInfo.HandType   = handType;
            playerHandInfo.HandColour = handColour;
            playerHandInfo.MainRank   = mainRank;
            playerHandInfo.SecondRank = secondRank;

            return(playerHandInfo);
        }
Exemplo n.º 2
0
        public static HoleCards GetHandByString(string handString)
        {
            HoleCards holeCards = new HoleCards();

            Card firstCard  = GetCardByChar(handString[0]);
            Card secondCard = GetCardByChar(handString[1]);

            if (firstCard == null || secondCard == null)
            {
                Debug.LogError("GetHandByString: could not create cards!");
                return(holeCards);
            }

            holeCards.First  = firstCard;
            holeCards.Second = secondCard;

            // TODO: 3rd simbol can be o, s or *, 4th can be *. Process all this

            // just in case, make cards colour different for pocket pairs
            if (firstCard.Rank == secondCard.Rank)
            {
                secondCard.Colour = Colour.Clubs;
            }
            else if (handString.Length > 2)
            {
                // change second card colour for offsuit hands
                if (handString[2] == 'o')
                {
                    secondCard.Colour = Colour.Clubs;
                }
            }

            return(holeCards);
        }
Exemplo n.º 3
0
 private void ParsePreflopOpenRaiseRange(Position position, JsonData openRaiseRange)
 {
     for (int handIndex = 0; handIndex < openRaiseRange.Count; handIndex++)
     {
         string    handString = openRaiseRange[handIndex].ToString();
         HoleCards hand       = Utils.GetHandByString(handString);
         PlayerAI.Instance.AddHandToPreflopOpenRaiseRange(position, hand);
     }
 }
Exemplo n.º 4
0
 private Rank GetHighestCardRank(HoleCards holeCards)
 {
     if (holeCards.First.Rank > holeCards.Second.Rank)
     {
         return(holeCards.First.Rank);
     }
     else
     {
         return(holeCards.Second.Rank);
     }
 }
Exemplo n.º 5
0
        private HandType EvaluateHand(HoleCards holeCards)
        {
            //if (!IsHoleCardsNumberCorrect(holeCards)) {
            //    Debug.LogError("EvaluateHand: incorrect number of hole cards!");
            //    return HandType.Invalid;
            //}

            if (holeCards.IsPocketPair)
            {
                return(HandType.Pair);
            }
            else
            {
                return(HandType.HighCard);
            }
        }
Exemplo n.º 6
0
        private void ParsePreflopColdCallRange(Position position, JsonData coldCallRange)
        {
            for (int vsPositionIndex = 0; vsPositionIndex < coldCallRange.Count; vsPositionIndex++)
            {
                string   vsPositionString = coldCallRange[vsPositionIndex]["VsPosition"].ToString();
                Position vsPosition       = Utils.GetPositionByString(vsPositionString);

                JsonData callingRange = coldCallRange[vsPositionIndex]["Range"];

                for (int handIndex = 0; handIndex < callingRange.Count; handIndex++)
                {
                    string    handString = callingRange[handIndex].ToString();
                    HoleCards hand       = Utils.GetHandByString(handString);
                    PlayerAI.Instance.AddHandToPreflopColdCallRange(position, vsPosition, hand);
                }
            }
        }
Exemplo n.º 7
0
        private bool IsHandInPreflop4BetRange(Position vsPosition)
        {
            Position  currentPlayerPosition = _currentGame.CurrentPlayer.Position;
            HoleCards holeCards             = _currentGame.CurrentPlayer.HoleCards;

            foreach (HoleCards hand in _preflop4BetRanges[currentPlayerPosition][vsPosition])
            {
                if (hand.First.Rank == holeCards.First.Rank)
                {
                    if (hand.Second.Rank == holeCards.Second.Rank)
                    {
                        if (hand.IsSuited == holeCards.IsSuited)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 8
0
 public void AddHandToPreflop4BetRange(Position position, Position vsPosition, HoleCards hand)
 {
     _preflop4BetRanges[position][vsPosition].Add(hand);
 }
Exemplo n.º 9
0
 public void AddHandToPreflopOpenRaiseRange(Position position, HoleCards hand)
 {
     _preflopOpenRaiseRanges[position].Add(hand);
 }
Exemplo n.º 10
0
        public string GetFullHandTypeString(out PlayerHandInfo playerHandInfo, HoleCards holeCards, List <Card> boardCards = null)
        {
            HandType handType = HandType.Invalid;

            Colour handColour = Colour.Invalid;
            Rank   mainRank   = Rank.Invalid;
            Rank   secondRank = Rank.Invalid;

            if (boardCards != null)
            {
                handType = EvaluateHand(holeCards, boardCards, out handColour, out mainRank, out secondRank);
            }
            else
            {
                handType = EvaluateHand(holeCards);
            }

            playerHandInfo.HandType   = handType;
            playerHandInfo.HandColour = handColour;
            playerHandInfo.MainRank   = mainRank;
            playerHandInfo.SecondRank = secondRank;

            if (handType == HandType.Invalid)
            {
                Debug.LogError("GetFullHandTypeString: could not evaluate hand type properly!");
                return("ERROR!");
            }

            string handTypeString = GetHandTypeString(handType);

            if (handType == HandType.HighCard)
            {
                if (boardCards == null)
                {
                    Rank   highestRank       = GetHighestCardRank(holeCards);
                    string highestRankString = GetRankString(highestRank);

                    return(handTypeString + highestRankString);
                }
                else
                {
                    List <Card> holeAndBoardCards = new List <Card>();
                    holeAndBoardCards.Add(holeCards.First);
                    holeAndBoardCards.Add(holeCards.Second);
                    holeAndBoardCards.AddRange(boardCards);
                    Rank   highestRank       = GetHighestCardRank(holeAndBoardCards);
                    string highestRankString = GetRankString(highestRank);

                    return(handTypeString + highestRankString);
                }
            }
            else if (handType == HandType.Pair)
            {
                if (boardCards == null)
                {
                    Rank   rank       = holeCards.First.Rank;
                    string rankString = GetRankString(rank);

                    return(handTypeString + rankString + "s");
                }
                else
                {
                    if (mainRank == Rank.Invalid)
                    {
                        Debug.LogError("GetFullHandTypeString: one pair - invalid rank.");
                        return("ERROR!");
                    }

                    return(handTypeString + GetRankString(mainRank) + "s");
                }
            }
            else if (handType == HandType.TwoPairs)
            {
                if (mainRank == Rank.Invalid || secondRank == Rank.Invalid)
                {
                    Debug.LogError("GetFullHandTypeString: two pairs - invalid rank.");
                    return("ERROR!");
                }

                return(handTypeString + GetRankString(mainRank) + "s and " + GetRankString(secondRank) + "s");
            }
            else if (handType == HandType.ThreeOfAKind)
            {
                if (mainRank == Rank.Invalid)
                {
                    Debug.LogError("GetFullHandTypeString: set - invalid rank.");
                    return("ERROR!");
                }

                return(handTypeString + GetRankString(mainRank) + "s");
            }
            else if (handType == HandType.Straight)
            {
                if (mainRank == Rank.Invalid)
                {
                    Debug.LogError("GetFullHandTypeString: straight - invalid rank.");
                    return("ERROR!");
                }

                return(handTypeString + GetRankString(mainRank) + " high");
            }
            else if (handType == HandType.Flush)
            {
                if (mainRank == Rank.Invalid)
                {
                    Debug.LogError("GetFullHandTypeString: flush - invalid rank.");
                    return("ERROR!");
                }

                if (handColour == Colour.Invalid)
                {
                    Debug.LogError("GetFullHandTypeString: flush - invalid colour.");
                    return("ERROR!");
                }

                return(handTypeString + GetRankString(mainRank) + " high");
            }
            else if (handType == HandType.FullHouse)
            {
                if (mainRank == Rank.Invalid || secondRank == Rank.Invalid)
                {
                    Debug.LogError("GetFullHandTypeString: full house - invalid rank.");
                    return("ERROR!");
                }

                return(handTypeString + GetRankString(mainRank) + "s full of " + GetRankString(secondRank) + "s");
            }
            else if (handType == HandType.FourOfAKind)
            {
                if (mainRank == Rank.Invalid)
                {
                    Debug.LogError("GetFullHandTypeString: quads - invalid rank.");
                    return("ERROR!");
                }

                return(handTypeString + GetRankString(mainRank) + "s");
            }
            else if (handType == HandType.StraightFlush)
            {
                if (mainRank == Rank.Invalid)
                {
                    Debug.LogError("GetFullHandTypeString: straight flush - invalid rank.");
                    return("ERROR!");
                }

                if (handColour == Colour.Invalid)
                {
                    Debug.LogError("GetFullHandTypeString: straight flush - invalid colour.");
                    return("ERROR!");
                }

                return(handTypeString + GetRankString(mainRank) + "high");
            }
            else if (handType == HandType.RoyalFlush)
            {
                if (handColour == Colour.Invalid)
                {
                    Debug.LogError("GetFullHandTypeString: royal flush - invalid colour.");
                    return("ERROR!");
                }

                return(handTypeString);
            }

            return("");
        }
Exemplo n.º 11
0
        private HandType EvaluateHand(HoleCards holeCards, List <Card> boardCards, out Colour handColour, out Rank mainRank, out Rank secondRank)
        {
            handColour = Colour.Invalid;
            mainRank   = Rank.Invalid;
            secondRank = Rank.Invalid;

            if (/*!IsHoleCardsNumberCorrect(holeCards) || */ !IsBoardCardsNumberCorrect(boardCards))
            {
                Debug.LogError("EvaluateHand: incorrect number of hole or board cards!");
                return(HandType.Invalid);
            }

            List <Card> holeAndBoardCards = new List <Card>();

            holeAndBoardCards.Add(holeCards.First);
            holeAndBoardCards.Add(holeCards.Second);
            holeAndBoardCards.AddRange(boardCards);

            // TODO: optimization: check set, two pair etc. in one loop through cards

            if (HasRoyalFlush(holeAndBoardCards, out handColour))
            {
                return(HandType.RoyalFlush);
            }
            else if (HasStraightFlush(holeAndBoardCards, out handColour, out mainRank))
            {
                return(HandType.StraightFlush);
            }
            else if (HasFourOfAKind(holeAndBoardCards, out mainRank))
            {
                return(HandType.FourOfAKind);
            }
            else if (HasFullHouse(holeAndBoardCards, out mainRank, out secondRank))
            {
                return(HandType.FullHouse);
            }
            else if (HasFlush(holeAndBoardCards, out handColour, out mainRank))
            {
                return(HandType.Flush);
            }
            else if (HasStraight(holeAndBoardCards, out mainRank))
            {
                return(HandType.Straight);
            }
            else if (HasThreeOfAKind(holeAndBoardCards, out mainRank))
            {
                return(HandType.ThreeOfAKind);
            }
            else if (HasTwoPairs(holeAndBoardCards, out mainRank, out secondRank))
            {
                return(HandType.TwoPairs);
            }
            else if (HasOnePair(holeAndBoardCards, out mainRank))
            {
                return(HandType.Pair);
            }
            else
            {
                return(HandType.HighCard);
            }
        }