IsBust() публичный Метод

public IsBust ( ) : bool
Результат bool
Пример #1
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();
        }
Пример #2
0
        private int ExpectedMoney(Hand dealer, Hand[] player)
        {
            int game_bet       = 100 * current_bet;
            int expected_money = 0;

            if (insurance_taken)
            {
                expected_money -= game_bet / 2;

                if (dealer.IsNatural())
                {
                    expected_money += 3 * game_bet / 2;
                }
            }

            if (surrendered)
            {
                expected_money -= game_bet / 2;
            }
            else
            {
                foreach (Hand hand in player)
                {
                    int hand_bet = hand.Doubled ? (game_bet * 2) : game_bet;

                    expected_money -= hand_bet;

                    if (dealer.IsNatural())
                    {
                        if (hand.IsNatural())
                        {
                            expected_money += hand_bet;
                        }
                    }
                    else if (split_count == 0 && hand.IsNatural())
                    {
                        expected_money += 2 * hand_bet + hand_bet / 2;
                    }
                    else if (dealer.IsBust())
                    {
                        if (!hand.IsBust())
                        {
                            expected_money += 2 * hand_bet;
                        }
                    }
                    else if (!hand.IsBust())
                    {
                        int player_total = hand.PointCount();
                        int dealer_total = dealer.PointCount();

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

            return(expected_money);
        }
Пример #3
0
        private int ExpectedMoney(Hand dealer, Hand[] player)
        {
            int game_bet = 100 * current_bet;
            int expected_money = 0;

            if (insurance_taken)
            {
                expected_money -= game_bet / 2;

                if (dealer.IsNatural()) expected_money += 3 * game_bet / 2;
            }

            if (surrendered)
            {
                expected_money -= game_bet / 2;
            }
            else
            {
                foreach (Hand hand in player)
                {
                    int hand_bet = hand.Doubled ? (game_bet * 2) : game_bet;

                    expected_money -= hand_bet;

                    if (dealer.IsNatural())
                    {
                        if (hand.IsNatural()) expected_money += hand_bet;
                    }
                    else if (split_count == 0 && hand.IsNatural())
                    {
                        expected_money += 2 * hand_bet + hand_bet / 2;
                    }
                    else if (dealer.IsBust())
                    {
                        if (!hand.IsBust())
                        {
                            expected_money += 2 * hand_bet;
                        }
                    }
                    else if (!hand.IsBust())
                    {
                        int player_total = hand.PointCount();
                        int dealer_total = dealer.PointCount();

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

            return expected_money;
        }