public void AddHand(int playerId, Hand playerHand)
        {
            var i = 0;
            var bAdded = false;

            while (i < HandRanks.Count && !bAdded)
            {
                var listHand = HandRanks[i].Hand;
                var compareResult = playerHand.Compare(listHand);

                if ( compareResult == 1)
                {
                    // player hand is better than hand in list so insert before
                    HandRanks.Insert(i, new HandRankInfo(playerId, playerHand));
                    bAdded = true;
                }
                else if (compareResult == 0)
                {
                    // Hands are same value so add playerId to existing handRank
                    HandRanks[i].AddPlayer(playerId);
                    bAdded = true;
                }

                i++;
            }

            if (!bAdded)
            {
                // lowest (or first) hand. Add hand to end of list
                HandRanks.Add(new HandRankInfo(playerId, playerHand));
            }
        }
Exemple #2
0
 public void SeePlayerHand(int playerNum, Card hole1, Card hole2, Hand bestHand)
 {
     // this is called to inform you of another players hand during the show down. 
     // bestHand is the best hand that they can form with their hole cards and the five board cards
     System.Threading.Thread.Sleep(_sleepMilliSeconds);
 }
Exemple #3
0
 public void SeePlayerHand(int playerNum, Card hole1, Card hole2, Hand bestHand)
 {
     // this is called to inform you of another players hand during the show down. 
     // bestHand is the best hand that they can form with their hole cards and the five board cards
 }
Exemple #4
0
 public void SeePlayerHand(int playerNum, Card hole1, Card hole2, Hand bestHand)
 {
 }
        public void SeePlayerHand(int playerShowingHand, Card hole1, Card hole2, Hand bestHand)
        {
            if (_botTimeOutMilliSeconds > 0)
            {
                if (!IsBotBusy())
                {
                    _task = Task.Run(() => { RunSeePlayerHand(playerShowingHand, hole1, hole2, bestHand); });

                    // wait X amount of time for task to complete
                    if (!_task.Wait(_botTimeOutMilliSeconds))
                    {
                        // Note that the task is still running in the background
                        _bIsBotBusy = true;
                        Logger.Log("TIMEOUT: {0} Player {1}", MethodBase.GetCurrentMethod().Name, PlayerNum);
                    }
                }
                else
                {
                    // bot is busy still running the previous task
                    Logger.Log("BOT BUSY: {0} Player {1}", MethodBase.GetCurrentMethod().Name, PlayerNum);
                }
            }
            else
            {
                // timeout code disabled - just called method directly
                RunSeePlayerHand(playerShowingHand, hole1, hole2, bestHand);
            }
        }
 private void RunSeePlayerHand(int playerShowingHand, Card hole1, Card hole2, Hand bestHand)
 {
     try
     {
         _player.SeePlayerHand(playerShowingHand, hole1, hole2, bestHand);
     }
     catch (Exception e)
     {
         Logger.Log(string.Format("EXCEPTION: {0} Player {1} : {2}", MethodBase.GetCurrentMethod().Name, PlayerNum, e.Message));
     }
 }
Exemple #7
0
        // -1 = hand1 is better
        // 0  = hands are equal
        // 1  = hand2 is better
        public static int CompareHands(Hand pHand1, Hand pHand2)
        {
            if (pHand1.HandRank() > pHand2.HandRank())
            {
                return -1;
            }

            if (pHand2.HandRank() > pHand1.HandRank())
            {
                return 1;
            }

            // Hands are of same rank, compare sub ranks

            //		assert(pHand1.numSubRanks() == pHand2.numSubRanks());

            var numSubRanks = pHand1.NumSubRanks();
            int currSubRank;

            for (currSubRank = 0; currSubRank < numSubRanks; currSubRank++)
            {
                if (pHand1.SubRank(currSubRank) > pHand2.SubRank(currSubRank))
                {
                    return -1;
                }

                if (pHand2.SubRank(currSubRank) > pHand1.SubRank(currSubRank))
                {
                    return 1;
                }
            }

            return 0;
        }
Exemple #8
0
        private void BroadcastPlayerHand(int playerNum, Hand playerBestHand)
        {
            Logger.Log("Player {0} Best Hand =  {1} {2}", playerNum, playerBestHand.HandValueStr(), playerBestHand.HandRankStr());
            var card1 = _players[playerNum].HoleCards()[0];
            var card2 = _players[playerNum].HoleCards()[1];

            foreach (var player in _players)
            {
                player.SeePlayerHand(playerNum, card1, card2, playerBestHand);
            }
        }
Exemple #9
0
        public static Hand FindPlayersBestHand(IReadOnlyList<Card> cards)
        {
            if (cards.Count < 5)
            {
                throw new Exception("not enough cards to find best hand");
            }

            if (cards.Count > 7)
            {
                throw new Exception("too many cards to find best hand");
            }

            var currHandCards = new Card[5];
            var bestHand = new Hand(cards);   // if 5 cards just use them

            if (cards.Count == 6)
            {
                for (var i = 0; i < 6; i++)
                {
                    // exclude cards at indices i, make poker hand
                    // with the other 5 cards
                    var currCard = 0;
                    int k;
                    for (k = 0; k < 6; k++)
                    {
                        if (k != i)
                        {
                            currHandCards[currCard] = cards[k];
                            currCard++;
                        }
                    }

                    var currHand = new Hand(currHandCards);

                    // If this is better than current best rank (and sub ranks)
                    // then make this the new best hand
                    if (CompareHands(currHand, bestHand) == -1)
                    {
                        bestHand = currHand;
                    }
                }
            }
            else if (cards.Count == 7)
            {

                for (var i = 0; i < 7; i++)
                {
                    for (var j = i + 1; j < 7; j++)
                    {
                        // exclude cards at indices i and j, make poker hand
                        // with the other 5 cards
                        var currCard = 0;
                        int k;
                        for (k = 0; k < 7; k++)
                        {
                            if ((k != i) && (k != j))
                            {
                                currHandCards[currCard] = cards[k];
                                currCard++;
                            }
                        }

                        var currHand = new Hand(currHandCards);

                        // If this is better than current best rank (and sub ranks)
                        // then make this the new best hand
                        if (CompareHands(currHand, bestHand) == -1)
                        {
                            bestHand = currHand;
                        }
                    }
                }
            }

            return bestHand;
        }
Exemple #10
0
 // -1 = otherHand is better
 // 0  = hands are equal
 // 1  = this hand is better
 public int Compare(Hand otherHand)
 {
     return CompareHands(otherHand, this);
 }
Exemple #11
0
        // Given two pocket cards and five board cards,
        // determine the best poker hand that can be formed using any 5 of the 7 cards
        public static Hand FindPlayersBestHand(Card[] pocketCards, Card[] board)
        {
            Card[] cards = new Card[7];
            Card[] currHandCards = new Card[5];
            int i, j, k, currCard;
            Hand bestHand = new Hand(board);  // default to play board
            Hand currHand;

            // Put all cards togther
            cards[0] = pocketCards[0];
            cards[1] = pocketCards[1];
            cards[2] = board[0];
            cards[3] = board[1];
            cards[4] = board[2];
            cards[5] = board[3];
            cards[6] = board[4];

            for (i = 0; i < 7; i++)
            {
                for (j = i + 1; j < 7; j++)
                {
                    // exclude cards at indices i and j, make poker hand
                    // with the other 5 cards
                    currCard = 0;
                    for (k = 0; k < 7; k++)
                    {
                        if ((k != i) && (k != j))
                        {
                            currHandCards[currCard] = cards[k];
                            currCard++;
                        }
                    }

                    currHand = new Hand(currHandCards);

                    // If this is better than current best rank (and sub ranks)
                    // then make this the new best hand
                    if (Hand.compareHands(currHand, bestHand) == -1)
                    {
                        bestHand = currHand;
                    }
                }
            }

            return bestHand;
        }
Exemple #12
0
        private void BroadcastPlayerHand(int playerNum, Hand playerBestHand)
        {
            System.Console.WriteLine("Player {0} Best Hand =  {1} {2}\n", playerNum, playerBestHand.handValueStr(), playerBestHand.handRankStr());
            Card card1 = players[playerNum].HoleCards()[0];
            Card card2 = players[playerNum].HoleCards()[1];

            foreach (ServerHoldemPlayer player in players)
            {
                player.SeePlayerHand(playerNum, card1, card2, playerBestHand);
            }
        }
 public void SeePlayerHand(int playerNum, Card hole1, Card hole2, Hand bestHand)
 {
     player.SeePlayerHand(playerNum, hole1, hole2, bestHand);
 }