/// <summary> /// Deals out a number of hands to their default /// </summary> /// <param name="numberOfHands">Number of hands to deal.</param> /// <param name="handSize">Number of cards in the hand.</param> /// <returns></returns> public IEnumerable <IHand <TElement> > Deal(int numberOfHands, uint handSize) { Contract.Requires(handSize > 0); CheckOperation(Options.Hands.Enabled, "Hands are not a part of this deck."); Events.Dealing(ref numberOfHands, ref handSize); var hands = new Internal.IHandInternal <TElement> [numberOfHands]; for (var i = 0; i < hands.Length; ++i) { hands[i] = new Hand <TElement>(this); } for (var card = 0; card < handSize; ++card) { for (var deck = 0; deck < hands.Length; ++deck) { hands[deck].Add(((Internal.IDrawPileInternal <TElement>)_drawPile).Draw()); } } HandSet.AddRange(hands); Events.Dealt(numberOfHands, handSize); return(hands); }
/// <summary> /// Mucks all hands, putting them back into the discard pile. /// </summary> /// <returns>This deck (for fluent purposes) </returns> public IDeck <TElement> Muck() { var hands = HandSet.ToArray(); hands.Apply(h => h.Muck()); return(this); }
public bool TryGetCard() { if (GlobalSet.Count > 0) { var firstCard = GlobalSet[0]; GlobalSet.RemoveAt(0); HandSet.Add(firstCard); return(true); } return(false); }
public static void Initialize(Game game) { HandSet playerHands = game.PlayerHandSet; List <Hand> active = new List <Hand>(); active.Add(playerHands.ActiveHand); bool allBusted = true; int numBusted = 0; foreach (Hand hand in game.PlayerHandSet) { if (!hand.Finished) { if (hand != playerHands.ActiveHand) { active.Add(hand); } } else { if (hand.IsBust()) { numBusted++; } else { if (!hand.IsSplit()) { allBusted = false; } } } } SHand[] shands = new SHand[active.Count]; for (int i = 0; i < shands.Length; i++) { shands[i] = new SHand(active[i]); } int[] shoe = game.Shoe.Counts; shoe[game.DealerHand[1].PointValue - 1]++; int upcard = game.DealerHand[0].PointValue; InitializeEvaluation(shands, shands.Length, allBusted, numBusted, upcard, shoe, game.Bet); }
/// <summary> /// Determines if an area contains an element. /// </summary> /// <param name="element">The element to look for.</param> /// <param name="location">The location to check.</param> /// <returns><see langword="true"/> if the element is in that location.</returns> public bool Contains(TElement element, Location location = Location.DrawPile) { Contract.Requires(Enum.IsDefined(typeof(Location), location)); switch (location) { case Location.DiscardPile: return(DiscardPile.Contains(element)); case Location.Hand: return(HandSet.Any(hand => hand.Contains(element))); case Location.Table: return(Table.Contains(element)); case Location.DrawPile: return(DrawPile.Contains(element)); default: throw new NotImplementedException($"The value of {location} wasn't coded for."); } return(false); }
/// <summary> /// Removes a hand from those that the deck is aware of. /// </summary> /// <param name="hand">The hand to remove.</param> void Internal.IDeckInternal <TElement> .RemoveHand(IHand <TElement> hand) { HandSet.Remove(hand); }