SoftTotal() public method

public SoftTotal ( ) : int
return int
        private double GetActionEV(Shoe tmp_shoe, CardSet active_hand, ActionType action, Card dealer_upcard)
        {
            Hand hand = new Hand(active_hand);

            SHand shand;
            int   soft_total = hand.SoftTotal();

            if (soft_total <= 21 && hand.HasAce())
            {
                shand.Total = soft_total;
                shand.Soft  = true;
            }
            else
            {
                shand.Total = hand.HardTotal();
                shand.Soft  = false;
            }

            int[] shoe_counts = tmp_shoe.ToArray();
            int   upcard      = dealer_upcard.PointValue;

            switch (action)
            {
            case ActionType.Stand:

                return(Eval.StandEv(shand, upcard, shoe_counts));

            case ActionType.Hit:

                return(Eval.HitEv(shand, upcard, shoe_counts));

            case ActionType.Double:

                return(Eval.DoubleEv(shand, upcard, current_bet, shoe_counts));

            case ActionType.Split:

                return(Eval.SplitEv(active_hand[0].PointValue, upcard, current_bet, max_splits - split_count, shoe_counts));

            case ActionType.Surrender:

                return(Eval.SurrenderEv());
            }

            return(-1);
        }
        private double GetActionEV(Shoe tmp_shoe, CardSet active_hand, ActionType action, Card dealer_upcard)
        {
            Hand hand = new Hand(active_hand);

            SHand shand;
            int soft_total = hand.SoftTotal();
            if (soft_total <= 21 && hand.HasAce())
            {
                shand.Total = soft_total;
                shand.Soft = true;
            }
            else
            {
                shand.Total = hand.HardTotal();
                shand.Soft = false;
            }

            int[] shoe_counts = tmp_shoe.ToArray();
            int upcard = dealer_upcard.PointValue;

            switch (action)
            {
                case ActionType.Stand:

                    return Eval.StandEv(shand, upcard, shoe_counts);

                case ActionType.Hit:

                    return Eval.HitEv(shand, upcard, shoe_counts);

                case ActionType.Double:

                    return Eval.DoubleEv(shand, upcard, current_bet, shoe_counts);

                case ActionType.Split:

                    return Eval.SplitEv(active_hand[0].PointValue, upcard, current_bet, max_splits - split_count, shoe_counts);

                case ActionType.Surrender:

                    return Eval.SurrenderEv();
            }

            return -1;
        }
示例#3
0
        public void DealRound()
        {
            player_handset.ActiveHand.AddCard(shoe.ExtractTop());
            dealer_hand.AddCard(shoe.ExtractTop());
            player_handset.ActiveHand.AddCard(shoe.ExtractTop());
            dealer_hand.AddCard(shoe.ExtractTop());


            bool dealer_natural;

            dealer_natural = dealer_hand.IsNatural();

            // check if player has blackjack
            if (player_handset.ActiveHand.IsNatural())
            {
                if (dealer_natural)
                {
                    // push, return initial bet
                    player_money += bet;
                    EndRound();
                    return;
                }
                else
                {
                    // player wins with blackjack, pay out 1.5:1 (with 10$ at stake, return 15$)
                    player_money += (int)(1.5 * bet) + bet;
                    EndRound();
                    return;
                }
            }

            int insurance = 0;

            // offer insurance
            if (Upcard().IsAce())
            {
                if (agent.TakeInsurance(this))
                {
                    insurance     = (int)(0.5 * bet);
                    player_money -= insurance;
                    AddPartyPoints(insurance);
                }
            }

            // dealer has blackjack
            if (dealer_natural)
            {
                if (insurance > 0)
                {
                    //??????
                    // insurance bet pays 2:1, initial bet is lost
                    player_money += (2 * insurance) + insurance;
                    EndRound();
                    return;
                }
                else
                {
                    // dealer wins with blackjack
                    EndRound();
                    return;
                }
            }

            // main loop
            // keeps asking player for actions for unfinished hands until
            // no unfinished hands remains
            while (!player_handset.AllFinished())
            {
                ActionType action = agent.GetBestAction(this);

                if (!IsValidAction(action))
                {
                    Console.WriteLine("Player made invalid action!");
                    return;
                }

                // player decides to stand, hand is over, move to next one
                if (ActionType.Stand == action)
                {
                    player_handset.ActiveHand.Stand();
                }
                else if (ActionType.Hit == action)
                {
                    player_handset.ActiveHand.Hit(shoe.ExtractTop());
                }
                else if (ActionType.Surrender == action)
                {
                    player_handset.ActiveHand.Surrender();
                }
                else if (ActionType.Double == action)
                {
                    player_handset.ActiveHand.Double(shoe.ExtractTop());
                    player_money -= bet;
                    AddPartyPoints(bet);
                }
                else if (ActionType.Split == action)
                {
                    player_handset.Split(shoe.ExtractTop(), shoe.ExtractTop());
                    player_money -= bet;
                    AddPartyPoints(bet);
                    split_count++;
                }
                else
                {
                    Console.WriteLine("Unknown action");
                }

                player_handset.NextActiveHand();
            }

            // each hand should be here in either some of these states:
            // busted, standed, doubled, surrendered

            // if all hands are busted, dealer doesn't draw, only reveals his hand and the round is over
            if (player_handset.AllBusted())
            {
                EndRound();
                return;
            }

            // player surrendered
            if (player_handset.ActiveHand.Surrendered)
            {
                // return half of the initial bet
                player_money += (int)(0.5 * bet);
                EndRound();
                return;
            }

            // handle the dealer logic
            while (true)
            {
                // must hit on soft 17's
                if (dealer_hand.HasAce() && dealer_hand.SoftTotal() == 17)
                {
                    dealer_hand.AddCard(shoe.ExtractTop());
                    continue;
                }

                // finish condition
                if (dealer_hand.PointCount() >= 17)
                {
                    break;
                }

                dealer_hand.AddCard(shoe.ExtractTop());
            }

            // payouts
            foreach (Hand hand in player_handset)
            {
                // skip split hands
                if (hand.IsSplit())
                {
                    continue;
                }

                int hand_bet = (hand.Doubled) ? (bet * 2) : bet;

                if (dealer_hand.IsBust())
                {
                    /*
                     * // both busted, it's a push
                     * if (hand.IsBust())
                     *      player_money += hand_bet;
                     * else // not busted hand wins dealer's busted hand 2:1 payout
                     *      player_money += 2 * hand_bet;
                     */

                    if (!hand.IsBust())
                    {
                        player_money += 2 * hand_bet;
                    }
                }
                else
                {
                    // do nothing, we lose our bet
                    if (hand.IsBust())
                    {
                    }
                    else
                    {
                        int player_total = hand.PointCount();
                        int dealer_total = dealer_hand.PointCount();

                        if (player_total < dealer_total)
                        {
                            // do nothing, we lose our bet
                        }                         // we win, 2:1 payout
                        else if (dealer_total < player_total)
                        {
                            player_money += 2 * hand_bet;
                        }                         // push
                        else
                        {
                            player_money += hand_bet;
                        }
                    }
                }
            }

            // round is over
            EndRound();
        }
示例#4
0
 public SHand(Hand hand)
 {
     int soft_total = hand.SoftTotal();
     if (soft_total <= 21 && hand.HasAce())
     {
         this.Total = soft_total;
         this.Soft = true;
     }
     else
     {
         this.Total = hand.HardTotal();
         this.Soft = false;
     }
 }