Пример #1
0
 public Hand(Hand h)
 {
     Cards = new List<Card>(h.Cards.OrderBy(c => c.Id));
     if(h.HandId == 0)
     {
         for (int i = 0; i < Cards.Count; i++)
             HandId += (int)Math.Pow(100, (Cards.Count - i - 1)) * Cards[i].Id;
     }
     else
         HandId = h.HandId;
 }
Пример #2
0
 public StartingHand(Hand h1, Hand h2)
 {
     if (h1.Cards[0].Id < Hand2.Cards[0].Id)
     {
         Hand1 = new Hand(h1);
         Hand2 = new Hand(h2);
     }
     else
     {
         Hand1 = new Hand(h2);
         Hand2 = new Hand(h1);
     }
 }
Пример #3
0
        public JsonResult CalculatePerms(Hand startHand)
        {
            Hand nextHand = new Hand();

            //startHand.cards.

            var response = new Object()
            {

            };

            return Json(nextHand);
        }
Пример #4
0
 public Player()
 {
     Hand = new Hand();
 }
Пример #5
0
 private void PrintRound(Hand h0, Hand h1, List<Card> board, RoundResult result)
 {
     Debug.WriteLine("----------------------------");
     PrintCards(h0.Cards);
     PrintCards(h1.Cards);
     PrintCards(board);
     Debug.WriteLine("Score: " + result.WinningScore);
     string str = "";
     for (var i = 0; i < result.WinningPlayerNumbers.Count; i++)
         str += " Player " + result.WinningPlayerNumbers[i].ToString();
     Debug.WriteLine(str);
     Debug.WriteLine("----------------------------");
 }
Пример #6
0
        private RoundResult CalculateWinner()
        {
            var winners = new List<Player>();
            var winnerNumbers = new List<int>();
            //var commCards = Board;

            long highScore = 0;
            long handScore = 0;

            Hand hand;

            for(int i = 0; i < Players.Count; i++)
            //foreach(var player in Players)
            {
                hand = new Hand(Players[i].Hand);
                hand.Cards.AddRange(Board);

                //handScore = hCalc.CalculateHandScore(hand, highScore);
                if (handScore == highScore)
                {
                    winners.Add(Players[i]);
                    winnerNumbers.Add(i);
                }
                else if (handScore > highScore)
                {
                    highScore = handScore;
                    winners = new List<Player>() { Players[i] };
                    winnerNumbers = new List<int>() { i };
                }
            }

            //return { 'players': arrWinners, 'score': highScore }
            return new RoundResult() { WinningScore = highScore, WinningPlayerNumbers = winnerNumbers };
        }
Пример #7
0
        // 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;
        }
Пример #8
0
 public ActionResult CalculateHand(Hand h)
 {
     return null;
 }