Example #1
0
        private void UpdateScore(CardHand hand, string playerId)
        {
            int sub_points = 0;
            int ace_count  = 0;

            Card[]          theCards = new Card[hand.GetNumCardsInHand()];
            BlackJackData[] theAces  = new BlackJackData[4];
            BlackJackData[] theHand  = new BlackJackData[hand.GetNumCardsInHand()];
            for (int i = 0; i < hand.GetNumCardsInHand(); i++)
            {
                theCards[i] = hand.GetCard(i);
                bjData      = new BlackJackData();
                bjData.AddCardData(theCards[i], 10);
                theHand[i] = bjData;
            }
            var sorted = theHand.OrderBy(i => i.m_value).ToArray <BlackJackData>();

            if (theCards.Length >= 2)
            {
                foreach (BlackJackData c in sorted)
                {
                    if (c.m_id != 1)
                    {
                        sub_points += c.m_value;
                    }
                    else
                    {
                        theAces[ace_count] = c;
                        ++ace_count;
                    }
                }
                if (ace_count > 0)
                {
                    while (ace_count > 0)
                    {
                        if (sub_points + 11 > 21)
                        {
                            if (theAces[ace_count - 1].m_id == 1)
                            {
                                sub_points += 1;
                            }
                        }
                        else
                        {
                            sub_points += 11;
                        }
                        --ace_count;
                    }
                }
            }
            if (playerId == "p1")
            {
                scoreP1 = sub_points;
            }
            else    //"p2"
            {
                scoreP2 = sub_points;
            }
        }
Example #2
0
 /// <summary>
 /// add Deck into BlackJackDataList
 /// </summary>
 /// <param name="deck"></param>
 public void AddDeckData(Deck deck)
 {
     for (int j = 0; j < deck.CardCount(); j++)
     {
         Card          card = deck.GetCard(j);
         BlackJackData data = new BlackJackData();
         data.AddCardData(card, deck.InternalDeckId());
         m_list.Add(data);
     }
 }