예제 #1
0
 public RecursiveSevenCardEvaluator(PokerHandEvaluator outerClass)
 {
     outer = outerClass;
     for (int i = 0; i < 7; i++)
     {
         _UsedCardIdx[i] = false;
     }
 }
예제 #2
0
        //The method each thread runs
        private void Simulate(int simulationsToRun, int unknownCards, Card[] cardsArray)
        {
            PokerHandEvaluator handEvaluator = new PokerHandEvaluator();
            Random             rand          = RandomHelper.Instance; //ensures each thread gets a unique seed :)
            Card temp;

            Card[] cards = new Card[7];             //copy of array, avoids locking of cardsArray
            for (int i = 0; i < 7; i++)
            {
                cards[i] = cardsArray[i];
            }

            //Run simulations
            for (int i = 0; i < simulationsToRun; i++)
            {
                //Deal random cards
                for (int u = 0; u < unknownCards; u++)
                {
                    temp = new Card((Rank)rand.Next(13) + 1, (Suit)rand.Next(4));
                    if (cards.Contains(temp))
                    {
                        u--;
                    }
                    else
                    {
                        cards[cards.Length - 1 - u] = temp;
                    }
                }

                //Work out hand value
                PokerHand value = handEvaluator.Evaluate(cards);
                lock (_Locker)
                {
                    _Events[(int)value]++;
                    _SimulationsRan++;
                }

                //Clear dealt cards (otherwise it won't deal them in the next iteration, distorting the calculation)
                for (int u = cards.Length - 1; u > cards.Length - 1 - unknownCards; u--)
                {
                    cards[u].IsKnown = false;
                }
            }

            _SimulationsDone.RemoveParticipant();             //like SignalAndWait but doesn't wait (no need)
        }