Exemplo n.º 1
0
    private HandRank EvaluateHand(Card c1, Card c2)
    {
        List <Card> cards = new List <Card>();

        cards.Add(c1);
        cards.Add(c2);
        cards.Add(tableCards.GetCard(0));
        cards.Add(tableCards.GetCard(1));
        cards.Add(tableCards.GetCard(2));
        cards.Add(tableCards.GetCard(3));
        cards.Add(tableCards.GetCard(4));

        cards.Sort(new CardCopare());

        Dictionary <CardSuit, int> suitsInHand = new Dictionary <CardSuit, int>();
        Dictionary <CardFace, int> faceInHand  = new Dictionary <CardFace, int>();

        foreach (int suit in System.Enum.GetValues(typeof(CardSuit)))
        {
            suitsInHand.Add((CardSuit)suit, 0);
        }

        foreach (int face in System.Enum.GetValues(typeof(CardFace)))
        {
            faceInHand.Add((CardFace)face, 0);
        }

        for (int i = 0; i < cards.Count; i++)
        {
            suitsInHand[cards[i].suit] += 1;
            faceInHand[cards[i].face]  += 1;
        }

        //get a sorted list of all face values
        List <int> allFace = new List <int>();

        foreach (Card c in cards)
        {
            allFace.Add((int)c.face);
        }

        //royal flush and straigth flush

        if (suitsInHand.ContainsValue(5))
        {
            //create a range of values from ten to ace, create a remaning list with all values that are not in the new range
            List <int> _rangeList = Enumerable.Range((int)CardFace.Ten, (int)CardFace.Ace).ToList();
            List <int> _Remaing   = allFace.Except(allFace).ToList();

            //if there is no remaning numbers that means that there is a sequence of a royal flush
            if (_Remaing.Count <= 0)
            {
                return(HandRank.RoyalFlush);
            }

            //if there is not royal flush check for a straigth flush

            //get last and first face value
            int _first = allFace.First();
            int _last  = allFace.Last();

            //create a range of values from first to last, create a remaning list with all values that are not in the list of face values
            _rangeList = Enumerable.Range(_first, _last - _first + 1).ToList();
            _Remaing   = _rangeList.Except(allFace).ToList();

            //if there is no remaning numbers that means that there is a sequence
            if (_Remaing.Count <= 0)
            {
                return(HandRank.StraightFlush);
            }
        }

        //four of a kind
        if (faceInHand.ContainsValue(4))
        {
            return(HandRank.FourKind);
        }

        // full house
        if (faceInHand.ContainsValue(3) && faceInHand.ContainsValue(2))
        {
            return(HandRank.FullHouse);
        }

        //flush
        if (suitsInHand.ContainsValue(5))
        {
            return(HandRank.Flush);
        }

        //straigth
        //get last and first face value
        int first = allFace.First();
        int last  = allFace.Last();

        //create a range of values from first to last, create a remaning list with all values that are not in the list of face values
        List <int> rangeList = Enumerable.Range(first, last - first + 1).ToList();
        List <int> remaing   = rangeList.Except(allFace).ToList();

        //if there is no remaning numbers that means that there is a sequence
        if (remaing.Count <= 0)
        {
            return(HandRank.Straight);
        }


        //three of a kind
        if (faceInHand.ContainsValue(3))
        {
            return(HandRank.ThreeKind);
        }

        //two pair
        int count = 0;

        foreach (var input in faceInHand)
        {
            if (input.Value == 2)
            {
                count++;
            }
        }

        if (count >= 2)
        {
            return(HandRank.TwoPair);
        }

        if (faceInHand.ContainsValue(2))
        {
            return(HandRank.Pair);
        }

        return(HandRank.HighCard);
    }
Exemplo n.º 2
0
    public IEnumerator CalculateBet(float currenBet, int cardsDelt, float topCurrency, PokerTableCards table, int deckSize, int turn)
    {
        //use neural network here
        betting = true;

        if (isAi)
        {
            //inputs = { totalCount, heartsCount, dimondCount, spadeCount, clubsCount, hand1, hand2, table1, table2, table3, table4, table5, turn, cash }

            float[] inputs =
            {
                cardsDelt / (52 * deckSize),                                                                                                  //noramlize cards dealt agains size of one deck
                (float)cardCount.GetSuitCount(CardSuit.Heart) / (float)(14 * deckSize),                                                       //noramlize suits dealt agains max amount of suits in deck
                (float)cardCount.GetSuitCount(CardSuit.Dimond) / (float)(14 * deckSize),
                (float)cardCount.GetSuitCount(CardSuit.Spades) / (float)(14 * deckSize),
                (float)cardCount.GetSuitCount(CardSuit.Clubs) / (float)(14 * deckSize),
                (float)((int)cardLocations[0].card.suit + (int)cardLocations[0].card.face) / (float)((int)CardSuit.Clubs * (int)CardFace.Ace), //normalize card agains all possible cards
                (float)((int)cardLocations[1].card.suit + (int)cardLocations[1].card.face) / (float)((int)CardSuit.Clubs * (int)CardFace.Ace),
                0, 0, 0, 0,                                                                                                                    //set 0 for now and add cards in depeding on turn
                turn / 3,                                                                                                                      //normalize betting turn
                currenCurrency / topCurrency                                                                                                   //normalzie own currenzy against top currency
            };

            if (turn >= 2)
            {
                inputs[7] = (float)((int)table.GetCard(0).suit + (int)table.GetCard(0).face) / (float)((int)CardSuit.Clubs * (int)CardFace.Ace);    //normalize card agains all possible cards
                inputs[8] = (float)((int)table.GetCard(1).suit + (int)table.GetCard(1).face) / (float)((int)CardSuit.Clubs * (int)CardFace.Ace);
                inputs[9] = (float)((int)table.GetCard(2).suit + (int)table.GetCard(2).face) / (float)((int)CardSuit.Clubs * (int)CardFace.Ace);
            }

            if (turn >= 3)
            {
                inputs[10] = (float)((int)table.GetCard(3).suit + (int)table.GetCard(3).face) / (float)((int)CardSuit.Clubs * (int)CardFace.Ace);   //normalize card agains all possible cards
            }

            float[] outputs = network.SendInputs(inputs);

            float topOut   = 0;
            int   outIndex = 0;

            //find larges ouput
            for (int i = 0; i < outputs.Length; i++)
            {
                if (topOut < outputs[i])
                {
                    topOut   = outputs[i];
                    outIndex = i;
                }
            }

            //do decision based on largets value
            switch (outIndex)
            {
            case 0:
                Raise(currenBet);
                break;

            case 1:
                Call(currenBet);
                break;

            case 2:
                Fold();
                break;
            }
        }
        else
        {
            //show buttons
            ChangeButtonVisability(true);
            betPlayer = currenBet;

            //wait for player to press button
            yield return(new WaitWhile(() => betting == true));

            //hide buttons
            ChangeButtonVisability(false);
        }



        yield return(new WaitForSeconds(betDeley));

        betting = false;
        yield return(null);
    }