public static Card Clone(Card card) { return new Card(card.FaceValue); }
/// <summary> /// Places the specified card back into its respective CardSource /// </summary> /// <param name="card">The card to replace</param> /// <returns>True if the discard was successful (the card was in the Hand and was removed), false otherwise.</returns> public Card Discard(Card card) { if (cards.Contains(card)) { return Discard((uint)cards.IndexOf(card)); } return null; }
public void AddCard(Card c) { cards.Add(c); if (c.Rank == Ranks.Ace) aces++; if (aces > 0) { int temp = 0; foreach (var card in cards) if (card.Rank != Ranks.Ace) temp += card.HighValue; int soft = temp + 10 + aces; if (soft <= 21) { Value = soft; Soft = true; } else { Value = temp + aces; Soft = false; } } else Value += c.HighValue; }
private Image GetImageForCard(Card card) { Image image = new Image(); image.Margin = new Thickness(2); image.Source = new BitmapImage(new Uri(GetImageFileNameForCard(card), UriKind.Relative)); return image; }
private string GetImageFileNameForCard(Card card) { int col = -1; switch (card.Suit) { case "Spades": col = 0; break; case "Clubs": col = 1; break; case "Hearts": col = 2; break; case "Diamonds": col = 3; break; } int row = -1; if (card.Rank == "Ace") { row = 0; } else { row = 14 - card.GetValue(); } return "Images/" + (row * 4 + col + 1).ToString() + ".png"; }
/// <summary> /// Creates a new shoe with the specified number of 52-card decks. /// </summary> /// <param name="decks"></param> public Shoe(int decks) { _shoe = new Card[decks * CARDS_PER_DECK]; int idx = 0; // For each deck in the shoe. for (int i = 0; i < decks; i++) // For each rank in a deck. for (int j = 0; j < 10; j++) // For each suit in a deck. for (int k = 0; k < 4; k++, idx++) { // Since T, J, Q, and K are all lumped // together, we need to add 4x as many // tens in the deck as every other card. if (j == 8) { _shoe[idx++] = new Card((Ranks)j); _shoe[idx++] = new Card((Ranks)j); _shoe[idx++] = new Card((Ranks)j); } // Add a card to the shoe. _shoe[idx] = new Card((Ranks)j); } }
internal bool add(Card c) { if (count(c) < original_deck_size) { cards.Add(c); return true; } return false; }
public void AddCard(Card card) { this.cards.Add(card); if (this.Changed != null) { this.Changed(this, EventArgs.Empty); } }
static void TestCardClass() { Card aceOfSpades = new Card("Spades", "Ace"); Console.WriteLine(aceOfSpades.GetFace() + " " + aceOfSpades.GetValue()); Card sevenOfHearts = new Card("Hearts", "7"); Console.WriteLine(sevenOfHearts.GetFace() + " " + sevenOfHearts.GetValue()); Card jackOfDiamonds = new Card("Diamonds", "Jack"); Console.WriteLine(jackOfDiamonds.GetFace() + " " + jackOfDiamonds.GetValue()); }
// Deck Constructor public Deck() { Cards = new Card[52]; int cardsPos = 0; foreach (string rank in Card.ValidRanks()) { foreach (string suit in Card.ValidSuits()) { Cards[cardsPos++] = new Card(suit, rank); } } Randomizer = new Random(); }
/// <summary> /// Method fills a deck with cards sequentially from 2♥ to A♠ /// </summary> public void UnpackNew() { cards.Clear(); for (byte i = 0; i < DECK_SIZE; i++) { Card card = new Card(); card.setNumber( i ); // for testing blackjacks (only Q,K and A are generated) //card.setNumber((byte)(r.Next() % 3 + 49) ); AddCard( card ); } }
public Deck() { Cards = new Card[52]; int index = 0; foreach (string rank in Card.ValidRanks()) { foreach (string suit in Card.ValidSuits()) { Cards[index] = new Card(suit, rank); index = index + 1; } } RandomGenerator = new Random(); }
private void AddCardToDisplay(Blackjack.Card c, int left, bool dealer) { var cardPath = HideDealerFirstCard(left, dealer) ? @"C:\Data\SideProjects\BlackJack\Cards\b1fv.png" : functions_and_stuff.GetPathFor(c); var panel = new Panel { Height = CARD_HEIGHT, Width = CARD_WIDTH, BackgroundImage = Image.FromFile(cardPath), Left = left }; if (dealer) { AddCardToPanel(pnlDealer, panel); } else { AddCardToPanel(pnlPlayer, panel); } }
public PlayAction Play(Hand hand, Card dealersTopCard) { var returnValue = (PlayAction)_random.Next(6); if (returnValue == PlayAction.DoubleOrHit) { returnValue = hand.CanDouble ? PlayAction.Double : PlayAction.Hit; } else if (returnValue == PlayAction.DoubleOrStay) { returnValue = hand.CanDouble ? PlayAction.Double : PlayAction.Stay; } if (returnValue == PlayAction.Double && !hand.CanDouble) { returnValue = PlayAction.Hit; } return returnValue; }
public Shoe(int decks) { _shoe = new Card[decks * CARDS_PER_DECK]; int idx = 0; for (int i = 0; i < decks; i++) for (int j = 0; j < 10; j++) for (int k = 0; k < 4; k++, idx++) { if (j == 8) { _shoe[idx++] = new Card((Ranks)j, (Suits)k); _shoe[idx++] = new Card((Ranks)j, (Suits)k); _shoe[idx++] = new Card((Ranks)j, (Suits)k); } _shoe[idx] = new Card((Ranks)j, (Suits)k); } }
/// <summary> /// Adds a card to the hand and recalculates its /// value. /// </summary> public void AddCard(Card c) { // Add the card to the collection. cards.Add(c); // If the new card is an ace, increment the counter. if (c.Rank == Ranks.Ace) aces++; // If we have at least one ace in our hand, we need // to consider soft values. if (aces > 0) { int temp = 0; // First calculate the base value not including aces. foreach (var card in cards) if (card.Rank != Ranks.Ace) temp += card.HighValue; // The soft value would be using one ace as 11. int soft = temp + 10 + aces; // If the soft value isn't a bust (> 21), // then it must be the closest to 21. if (soft <= 21) { Value = soft; Soft = true; } else { Value = temp + aces; Soft = false; } } // If we don't have any aces, we can just take the high value. else Value += c.HighValue; }
public void calculate_win2() { // Card c1 = new Card(7, "C7"); Card c2 = new Card(10, "DH"); Player p = new Player(); p.add_card(c1); p.add_card(c2); int starting_bet = 10; int final_bet = 0; p.Player_Bet = starting_bet; p.bets[0] = 10; Dealer d = new Dealer(); d.Hand_Value = 18; //act p.calculate_win(d.Hand_Value); int actual = p.Player_Bet; //Assert Assert.AreEqual(final_bet, actual, "Dealer wins!"); }
/* * Functions */ public void add_card(Card c) { hand[active_hand].Add(c); set_value(); }
public Hand(string who, Card card1, Card card2) { this.Who = who; this.Cards.Add(card1); this.Cards.Add(card2); }
public PlayAction Play(Hand hand, Card dealersTopCard) { var dealerCardValue = dealersTopCard.Value; var softValue = hand.SoftValue; // TODO: complete split functionality //if (this.Hand.CanSplit) //{ // return _splitTable[,dealerCardValue - 1]; //} PlayAction returnValue; if (null != softValue) { softValue -= 12; softValue = Math.Min(softValue.Value, 6); returnValue = _softTable[softValue.Value, dealerCardValue - 1]; } else { var index = hand.HardValue - 8; index = Math.Max(index, 0); index = Math.Min(index, 9); returnValue = _hardTable[index, dealerCardValue - 1]; } if (returnValue == PlayAction.DoubleOrHit) { if (hand.CanDouble) { returnValue = PlayAction.Double; } else { returnValue = PlayAction.Hit; } } else if (returnValue == PlayAction.DoubleOrStay) { if (hand.CanDouble) { returnValue = PlayAction.Double; } else { returnValue = PlayAction.Stay; } } return returnValue; }
public void LookAtCard(Card current) { if (current.Value == 10) { highCardsSeen++; } else if(current.Value <= 4) { lowCardsSeen++; } else { midCardsSeen++; } }
/// <summary> /// Gets the point value of the passed Card, ace high /// </summary> /// <param name="c">A Card to determine the point value of</param> /// <returns>the point value of the passed Card</returns> public static uint cardValue(Card c) { switch (c.Rank) { case Rank.Ace: return 11; case Rank.Two: return 2; case Rank.Three: return 3; case Rank.Four: return 4; case Rank.Five: return 5; case Rank.Six: return 6; case Rank.Seven: return 7; case Rank.Eight: return 8; case Rank.Nine: return 9; case Rank.Ten: case Rank.Jack: case Rank.Queen: case Rank.King: return 10; default: throw new ArgumentException("That Rank is not recognized! Are you doing any funny casting business? Bad programmer!"); } }
internal void giveCards(Card a, Card b) { Draw(); while (!this[0].Equals(a)) { Discard(0); Draw(); } Draw(); while (!this[1].Equals(b)) { Discard(1); Draw(); } }
public void AddCard(Card card) { // Take a card dealerHand.Add(card); }
public bool TakeCard(Card card) { Hand.Add(card); return Hand.IsBusted; }
public PlayAction Play(Hand hand, Card dealersTopCard) { return _strategy.Play(hand, dealersTopCard); }
private uint count(Card c) { uint sum = 0; foreach (Card card in cards) { if (c.Equals(card)) { sum++; } } return sum; }
public void CountCard( Card newCard ) { if( plyrMethod != null ) plyrMethod.CountCard( newCard ); }
public void add_card(int h, Card c) { hand[h].Add(c); }
public void split_add_card(Card c) { int s = nr_of_hands; hand[active_hand + (nr_of_hands - active_hand)].Add(c); }
bool PlayHand(Player player, Card dealerTopCard, Shoe shoe) { PlayAction play = player.Play(player.Hand, dealerTopCard); if (play == PlayAction.Stay) { return true; } if (play == PlayAction.Hit) { Card card = shoe.GetNextCard(); bool bust = player.TakeCard(card); if (bust) return false; return PlayHand(player, dealerTopCard, shoe); } if (play == PlayAction.Double) { if (player.Hand.Count() != 2) throw new Exception("only double on first"); var bust = player.TakeCard(shoe.GetNextCard()); if (bust) return false; return true; } throw new InvalidOperationException("shouldn't be here"); }