コード例 #1
0
ファイル: HandStatProcessor.cs プロジェクト: nurdyguy/MDU
 public HandStatProcessor(HandStatRequest request)
 {
     hCalc = new HandCalculator();
     StartHands = new List<Hand>();
     OrderedStartHands = new List<Hand>();
     BoardCards = new List<Card>();
     DeadCards = new List<Card>();
     SetUpStartHands(request);
     if (request.BoardCardIds != null && request.BoardCardIds.Count > 0)
         SetUpBoardCards(request);
     if (request.DeadCardIds != null && request.DeadCardIds.Count > 0)
         SetUpDeadCards(request);
 }
コード例 #2
0
ファイル: Game.cs プロジェクト: nurdyguy/MDU
 public Game(int numPlayers = 2)
 {
     Deck = new Deck();
     Players = new List<Player>();
     PlayerWins = new List<long>();
     hCalc = new HandCalculator();
     iCalc = new IterationCalculator();
     Board = new List<Card>();
     for (var i = 0; i < numPlayers; i++)
     {
         Players.Add(new Player());
         PlayerWins.Add(0);
     }
 }
コード例 #3
0
ファイル: Game.cs プロジェクト: nurdyguy/MDU
        // plays a basic game
        public Game PlayRounds(int num = 1)
        {
            var watch = new Stopwatch();

            watch.Start();

            var startingHands = PokerRepository.GetNextCalcBatch(50);

            Timers.Add(watch.Elapsed.TotalSeconds);
            watch.Restart();

            //var startingHands = new List<HeadToHeadStat>()
            //{
            //    new HeadToHeadStat()
            //    {
            //        Id = 13463039,
            //        Hand0Id = 1346,
            //        Hand1Id = 3039
            //    },
            //    new HeadToHeadStat()
            //    {
            //        Id = 13463040,
            //        Hand0Id = 1346,
            //        Hand1Id = 3040
            //    },
            //    new HeadToHeadStat()
            //    {
            //        Id = 13463041,
            //        Hand0Id = 1346,
            //        Hand1Id = 3041
            //    },
            //    new HeadToHeadStat()
            //    {
            //        Id = 13463042,
            //        Hand0Id = 1346,
            //        Hand1Id = 3042
            //    }

            //};
            //13463039 13463040  13463041  13463042
            var chopCount = new List<int>() { 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            Parallel.ForEach(startingHands, new ParallelOptions() { MaxDegreeOfParallelism = 3 }, sh =>
            //startingHands.ForEach(sh =>
            {
                Hand h0 = new Hand(sh.Hand0Id);
                Hand h1 = new Hand(sh.Hand1Id);
                //h0.Cards = new List<Card>() { Card.Diamond2, Card.Spade9 };
                //h1.Cards = new List<Card>() { Card.Heart6, Card.Spade2 };
                List<Hand> hands = new List<Hand>() { h0, h1 };

                Deck d = new Deck();
                HandCalculator hc = new HandCalculator();
                long h0w = 0;
                long h1w = 0;
                long chops = 0;

                d.RemoveCards(h0.Cards);
                d.RemoveCards(h1.Cards);
                List<Card> currBoard = new List<Card>(5);
                List<Card> nextBoard = new List<Card>(d.DealNextCards(5));
                //nextBoard = new List<Card>()
                //{
                //    Card.Diamond3, Card.Spade3, Card.Heart2, Card.Club2, Card.Diamond7
                //};
                long score = 0;
                while (nextBoard != null)
                {
                    d.AddCardsBackToDeckInOrder(currBoard);
                    currBoard = d.DealCards(nextBoard);

                    //var result = hc.CalculateWinner(hands , currBoard);
                    var result = hc.CalculateWinnerDll(hands, currBoard);
                    score = result.WinningScore;
                    if (result.WinningPlayerNumbers.Count > 1)
                    {
                        chopCount[(int)(score / 10000000000)]++;
                        chops++;
                    }
                    else if (result.WinningPlayerNumbers[0] == 0)
                        h0w++;
                    else if (result.WinningPlayerNumbers[0] == 1)
                        h1w++;
                    nextBoard = iCalc.GetNextHand(nextBoard, d.Cards);

                    //nextBoard = null;
                }

                PokerRepository.UpdateHeadToHeadStatValues(sh.Id, h0w, h1w, chops);
                Debug.WriteLine("------------");
                Debug.WriteLine("Id: " + sh.Id);
                Debug.WriteLine("h0: " + h0w);
                Debug.WriteLine("h1: " + h1w);
                Debug.WriteLine("chops: " + chops);
                //Debug.WriteLine("score: " + score);
                Debug.WriteLine("------------");
            });

            Timers.Add(watch.Elapsed.TotalSeconds);

            watch.Stop();
            return this;
        }