/// <summary> /// Splits the hand. /// </summary> /// <param name="shoe">The shoe.</param> /// <param name="player">The player.</param> /// <returns></returns> public bool SplitHand(BjShoe shoe, BjPlayer player) { if (Cards.Count != 2) { return(false); } BjHand hand = null; var card1 = Cards[0]; var card2 = Cards[1]; if (card1 != null && card2 != null && card1.Face == card2.Face) { hand = new BjHand(Bet, card2); } if (hand == null) { return(false); } if (!Cards.Remove(hand.Cards.FirstOrDefault()) || !HitHand(shoe) || !hand.HitHand(shoe)) { return(false); } player.CurrentHands.Add(hand); return(true); }
/// <summary> /// Determines whether [is split success] [the specified hand]. /// </summary> /// <param name="hand">The hand.</param> /// <param name="shoe">The shoe.</param> /// <returns> /// <c>true</c> if [is split success] [the specified hand]; otherwise, <c>false</c>. /// </returns> public bool IsSplitSuccess(BjHand hand, BjShoe shoe) { if (!HandExists(hand)) { return(false); } return(hand.SplitHand(shoe, this)); }
/// <summary> /// Determines whether [is double down success] [the specified hand]. /// </summary> /// <param name="hand">The hand.</param> /// <param name="shoe">The shoe.</param> /// <returns> /// <c>true</c> if [is double down success] [the specified hand]; otherwise, <c>false</c>. /// </returns> public bool IsDoubleDownSuccess(BjHand hand, BjShoe shoe) { if (!HandExists(hand)) { return(false); } return(hand.HitHand(shoe)); }
public BjGame(BjDealer dealer, Vector3 location, List <BjPlayer> players, int minimumBet, int numberOfDecks, float blackjackBonus) { Location = location; Dealer = dealer; Players = players; MinimumBet = minimumBet; NumberOfDecks = numberOfDecks; Shoe = new BjShoe(numberOfDecks); BlackjackBonus = blackjackBonus; }
/// <summary> /// Performs the action. /// </summary> /// <param name="action">The action.</param> /// <param name="shoe">The shoe.</param> /// <returns></returns> public bool PerformAction(BjActionsEnum action, BjShoe shoe) { if (GetActiveHand == null) { return(false); } var success = false; switch (action) { case BjActionsEnum.DealNewHand: success = true; break; case BjActionsEnum.Hit: success = IsHitSuccess(GetActiveHand, shoe); break; case BjActionsEnum.Stand: GetActiveHand.IsStanding = true; success = true; break; case BjActionsEnum.DoubleDown: if (CurrentHands.Count >= MaxHands) { return(false); } success = IsDoubleDownSuccess(GetActiveHand, shoe); if (success) { Chips = Chips - GetActiveHand.Bet; } GetActiveHand.IsDoubleDown = success; break; case BjActionsEnum.Split: if (CurrentHands.Count >= MaxHands) { return(false); } success = IsSplitSuccess(GetActiveHand, shoe); if (success) { Chips = Chips - GetActiveHand.Bet; } break; } Log.Info($"PerformAction:hand={GetActiveHand},action={action},success={success}"); return(success); }
/// <summary> /// Deals the new round. /// </summary> /// <param name="shoe">The shoe.</param> /// <returns></returns> public bool DealNewRound(BjShoe shoe) { var hand = new BjHand(CurrentBet); if (!hand.HitHand(shoe)) { return(false); } CurrentHands = new List <BjHand> { hand }; return(true); }
/// <summary> /// Doubles down. /// </summary> /// <param name="shoe">The shoe.</param> /// <returns></returns> public bool DoubleDown(BjShoe shoe) { if (Cards.Count != 2) { return(false); } if (!DealCards(shoe, 1)) { return(false); } Bet = Bet + Bet; IsDoubleDown = true; return(true); }
/// <summary> /// Deals the cards. /// </summary> /// <param name="shoe">The shoe.</param> /// <param name="numberOfCards">The number of cards.</param> /// <returns></returns> public bool DealCards(BjShoe shoe, int numberOfCards) { var hand = shoe.DealCards(numberOfCards); if (hand == null) { return(false); } if (Cards == null) { Cards = new List <PlayingCard>(); } Cards.AddRange(hand); return(true); }
/// <summary> /// Deals the round starting cards. /// </summary> /// <param name="shoe">The shoe.</param> /// <param name="players">The players.</param> /// <returns></returns> public bool DealRoundStartingCards(BjShoe shoe, List <BjPlayer> players) { var allPlayersDealt = true; CurrentHand = new BjHand(); for (int i = 0; i < 2; i++) { foreach (var player in players) { if (player.CurrentBet <= 0 || player.CurrentBet > player.Chips || player.CurrentBet < Blackjack.CurrentGame.MinimumBet) { Log.Info($"DealRoundStartingCards: bet={player.CurrentBet},chips={player.Chips},minBet={Blackjack.CurrentGame.MinimumBet}"); allPlayersDealt = false; continue; } if (i == 0) { if (!player.DealNewRound(shoe)) { Log.Info($"Failed to deal player new round."); return(false); } } else { var hand = player.CurrentHands.FirstOrDefault(); if (!player.IsHitSuccess(hand, shoe)) { Log.Info($"Failed to deal player 2nd card."); return(false); } } } if (!CurrentHand.HitHand(shoe)) { Log.Info($"Failed to hit dealer."); return(false); } } return(allPlayersDealt); }
/// <summary> /// Hits the hand. /// </summary> /// <param name="shoe">The shoe.</param> /// <returns></returns> public bool HitHand(BjShoe shoe) { return(DealCards(shoe, 1)); }