public void NewCard_2c_HasCorrectValue()
        {
            Card card = new Card("2", "c");

            Assert.AreEqual("2c", card.CardStringValue);
            Assert.AreEqual(0, card.CardIntValue);
        }
        public void NewCard_aS_CorrectsCapitalization()
        {
            Card card = new Card("a", "S");

            Assert.AreEqual("As", card.CardStringValue);
            Assert.AreEqual(51, card.CardIntValue);
        }
        public void NewCard_Th_HasCorrectValue()
        {
            Card card = new Card("T", "h");

            Assert.AreEqual("Th", card.CardStringValue);
            Assert.AreEqual(34, card.CardIntValue);
        }
        public void NewCard_As_HasCorrectValue()
        {
            Card card = new Card("A", "s");

            Assert.AreEqual("As", card.CardStringValue);
            Assert.AreEqual(51, card.CardIntValue);
        }
        public void NewCard_Td_HasCorrectValue()
        {
            Card card = new Card("T", "d");

            Assert.AreEqual("Td", card.CardStringValue);
            Assert.AreEqual(21, card.CardIntValue);
        }
        public void TestCard_FromIntValue_2cAs9h()
        {
            var card = Card.GetCardFromIntValue(0);
            Assert.AreEqual("2c", card.ToString());

            card = Card.GetCardFromIntValue(51);
            Assert.AreEqual("As", card.ToString());

            card = new Card("9","h");
            Assert.AreEqual("9h", Card.GetCardFromIntValue(card.CardIntValue).ToString());
        }
 public static HoleCards FromCards(string playerName, Card[] cards)
 {
     switch (cards.Length)
      {
          case 0:
              return NoHolecards(playerName);
          case 2:
              return ForHoldem(playerName, cards[0], cards[1]);
          case 4:
              return ForOmaha(playerName, cards[0], cards[1], cards[2], cards[3]);
          default:
              throw new ArgumentException("Hole cards must contain atleast 0, 2 or 4 cards.");
      }
 }
 public void NewCard_Performance()
 {
     const int numberOfCards = 20000000;
     System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
     timer.Start();
     for (int i = 0; i < numberOfCards; i++)
     {
         Card card = new Card("T", "h");
     }
     timer.Stop();
     double elapsedMillis = timer.Elapsed.TotalMilliseconds;
     Console.Write("Time in milliseconds to generate " + numberOfCards + " cards: " + elapsedMillis);
     bool ExecutionTimeLessThanFiveSeconds = (elapsedMillis < 1000);
     Assert.IsTrue(ExecutionTimeLessThanFiveSeconds, "Should take less than one seconds: Time Taken: " + elapsedMillis + "ms");
 }
示例#9
0
        /// <summary>
        /// Determines if it's possible to create straight using specified card
        /// </summary>
        /// <param name="playerCard"></param>
        /// <param name="boardCards"></param>
        /// <returns></returns>
        internal static bool IsOneCardStraight(Cards.Card playerCard, IEnumerable <Cards.Card> boardCards)
        {
            if (boardCards == null || boardCards.Count() < 4)
            {
                return(false);
            }
            var sortedBoardRanks = boardCards.Select(x => x.RankNumericValue).Distinct().ToList();

            sortedBoardRanks.Sort();
            if (sortedBoardRanks.Contains(Cards.Card.GetRankNumericValue(Cards.Card.PossibleRanksHighCardFirst.First())))
            {
                sortedBoardRanks.Insert(0, 1);
            }

            if (sortedBoardRanks.Count < 4)
            {
                return(false);
            }

            for (int i = 0; i <= sortedBoardRanks.Count - 4; i++)
            {
                var curCards = sortedBoardRanks.Skip(i);
                if (curCards.Count() >= 4)
                {
                    var list = new List <int>(curCards.Take(4));
                    list.Add(playerCard.RankNumericValue);

                    if (HandAnalyzerHelpers.IsStraight(list) && !boardCards.Any(x => x.RankNumericValue == playerCard.RankNumericValue))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        protected override BoardCards ParseCommunityCards(string[] handLines)
        {
            string boardCards = string.Empty;
            /*
             * <cards type="Flop" player="">D6 S9 S7</cards>
             * <cards type="Turn" player="">H8</cards>
             * <cards type="River" player="">D5</cards>
             * <cards type="Pocket" player="pepealas5">CA CK</cards>
             */

            string[] cardLines = GetCardLinesFromHandLines(handLines);

            for (int i = 0; i < cardLines.Length; i++)
            {
                string handLine = cardLines[i];
                handLine = handLine.TrimStart();

                //To make sure we know the exact character location of each card, turn 10s into Ts (these are recognized by our parser)
                handLine = handLine.Replace("10", "T");

                //The suit/ranks are reversed, so we need to reverse them when adding them to our board card string

                //Flop
                if (handLine[13] == 'F')
                {
                    boardCards += new Card(handLine[30], handLine[29]) + "," + new Card(handLine[33], handLine[32]) + "," + new Card(handLine[36], handLine[35]);
                }
                //Turn
                if (handLine[13] == 'T')
                {
                    boardCards += "," + new Card(handLine[30], handLine[29]);
                }
                //River
                if (handLine[13] == 'R')
                {
                    boardCards += "," + new Card(handLine[31], handLine[30]);
                    break;
                }
            }

            return BoardCards.FromCards(boardCards);
        }
示例#11
0
 public static BoardCards ForTurn(Card card1, Card card2, Card card3, Card card4)
 {
     return new BoardCards(card1, card2, card3, card4);
 }
示例#12
0
 public static BoardCards FromCards(Card[] cards)
 {
     return new BoardCards(cards);
 }
示例#13
0
 public static HoleCards ForOmaha(string playerName, Card card1, Card card2, Card card3, Card card4)
 {
     return new HoleCards(playerName, card1, card2, card3, card4);
 }
示例#14
0
 public static HoleCards ForOmaha(Card card1, Card card2, Card card3, Card card4)
 {
     return new HoleCards(string.Empty, card1, card2, card3, card4);
 }
示例#15
0
 public static HoleCards ForHoldem(string playerName, Card card1, Card card2)
 {
     return new HoleCards(playerName, card1, card2);
 }
示例#16
0
 public static BoardCards ForRiver(Card card1, Card card2, Card card3, Card card4, Card card5)
 {
     return new BoardCards(card1, card2, card3, card4, card5);
 }
示例#17
0
 /// <summary>
 /// Determines if specific hole card is top kicker
 /// </summary>
 /// <param name="unpairedCard">hole card</param>
 /// <param name="board">Collection of board cards</param>
 /// <returns></returns>
 internal static bool IsTopKicker(Cards.Card unpairedCard, IEnumerable <Cards.Card> board)
 {
     return(unpairedCard.Rank == GetTopKickerRank(board));
 }
        protected override BoardCards ParseCommunityCards(string[] handLines)
        {
            string[] cardLines = GetCardLinesFromHandLines(handLines);

            string boardCards = "";

            for (int i = 0; i < cardLines.Length; i++)
            {
                string handLine = cardLines[i];
                handLine = handLine.TrimStart();

                //To make sure we know the exact character location of each card, turn 10s into Ts (these are recognized by our parser)
                handLine = handLine.Replace("value=\"10\"", "value=\"T\"");

                boardCards += new Card(handLine[13], handLine[22]);
            }

            return BoardCards.FromCards(boardCards);
        }
示例#19
0
 /// <summary>
 /// Determines if specific hole card is weak kicker
 /// </summary>
 /// <param name="card">hole card</param>
 /// <param name="board">Collection of board cards</param>
 /// <returns></returns>
 internal static bool IsWeakKicker(Cards.Card card)
 {
     return(card.RankNumericValue <= Cards.Card.GetRankNumericValue("T"));
 }
示例#20
0
 /// <summary>
 /// Determines if specific hole card is decent kicker
 /// </summary>
 /// <param name="card">hole card</param>
 /// <param name="board">Collection of board cards</param>
 /// <returns></returns>
 internal static bool IsDecentKicker(Cards.Card card)
 {
     return(card.RankNumericValue > Cards.Card.GetRankNumericValue("T"));
 }
示例#21
0
 public static HoleCards ForHoldem(Card card1, Card card2)
 {
     return new HoleCards(string.Empty, card1, card2);
 }
示例#22
0
 public static BoardCards ForFlop(Card card1, Card card2, Card card3)
 {
     return new BoardCards(card1, card2, card3);
 }