Exemplo n.º 1
0
        public static StrategyDecisionType ConvertToStrategyDecision(DecisionTypePair pairDecision, Permits permits)
        {
            if (pairDecision == DecisionTypePair.SURRENDER_OR_SPLIT && permits.Surrender)
            {
                return StrategyDecisionType.SURRENDER;
            }
            else if (pairDecision == DecisionTypePair.SURRENDER_OR_SPLIT && !permits.Surrender)
            {
                pairDecision = DecisionTypePair.SPLIT;
            }
            if (pairDecision == DecisionTypePair.SPLIT && permits.Split)
            {
                return StrategyDecisionType.SPLIT;
            }

            return StrategyDecisionType.NA;
        }
Exemplo n.º 2
0
        public static StrategyDecisionType ConvertToStrategyDecision(DecisionType decision, Permits permits)
        {
            if (decision == DecisionType.STAND)
            {
                return StrategyDecisionType.STAND;
            }
            if (decision == DecisionType.HIT)
            {
                return StrategyDecisionType.HIT;
            }
            if (decision == DecisionType.DOUBLE_OR_HIT && !permits.Double)
            {
                return StrategyDecisionType.HIT;
            }
            if (decision == DecisionType.DOUBLE_OR_HIT && permits.Double)
            {
                return StrategyDecisionType.DOUBLE;
            }
            if (decision == DecisionType.DOUBLE_OR_STAND && !permits.Double)
            {
                return StrategyDecisionType.STAND;
            }
            if (decision == DecisionType.DOUBLE_OR_STAND && permits.Double)
            {
                return StrategyDecisionType.DOUBLE;
            }
            if (decision == DecisionType.SURRENDER_OR_HIT && !permits.Surrender)
            {
                return StrategyDecisionType.HIT;
            }
            if (decision == DecisionType.SURRENDER_OR_HIT && permits.Surrender)
            {
                return StrategyDecisionType.SURRENDER;
            }
            if (decision == DecisionType.SURRENDER_OR_STAND && !permits.Surrender)
            {
                return StrategyDecisionType.STAND;
            }
            if (decision == DecisionType.DOUBLE_OR_STAND && permits.Surrender)
            {
                return StrategyDecisionType.SURRENDER;
            }

            return StrategyDecisionType.NA;
        }
Exemplo n.º 3
0
        public PlayHandOutcome PlayHand(Hand handPlayer, Hand handDealer, double betSize, CardShoe shoe,
            ref int numberOfSplits)
        {
            int trueCount = 0;
            if (shoe.Count != null)
            {
                trueCount = shoe.Count.TrueCount;
            }
            bool surrenderDone = false;
            bool splitDone = numberOfSplits > 0;
            var playHandOutcome = new PlayHandOutcome();
            handPlayer.BetSize = betSize;

            // consider insurance first
            double insuranceBet = 0;
            if (Configuration.GameRules.InsuranceAllowed && handDealer.IsAce(0) && !splitDone)
            {
                bool takeInsurance = Strategy.GetInsuranceDecision(handDealer, trueCount);
                if (takeInsurance)
                {
                    insuranceBet = 0.5 * betSize;
                }
            }

            // player's hand play
            bool continuePlay = true;
            while (handPlayer.Value() < 21 && !surrenderDone && !handDealer.IsBlackjack() && continuePlay)
            {
                Permits permits = new Permits(handPlayer, Configuration, numberOfSplits);
                if (shoe.Count != null)
                {
                    trueCount = shoe.Count.TrueCount;
                }
                StrategyDecisionType decision = Strategy.GetDecision(handPlayer, handDealer, trueCount, permits, Random);

                switch (decision)
                {
                    case StrategyDecisionType.STAND:
                        continuePlay = false;
                        break;

                    case StrategyDecisionType.HIT:
                        handPlayer.Hit(shoe);
                        break;

                    case StrategyDecisionType.DOUBLE:
                        handPlayer.DoubleDone = true;
                        betSize *= 2;
                        handPlayer.Hit(shoe);
                        continuePlay = false;
                        break;

                    case StrategyDecisionType.SPLIT:
                        var splitHands = handPlayer.Split(shoe);
                        numberOfSplits++;

                        var playHandOutcomeSplit1 = PlayHand(splitHands[1], handDealer, betSize, shoe, ref numberOfSplits);
                        var playHandOutcomeSplit2 = PlayHand(splitHands[0], handDealer, betSize, shoe, ref numberOfSplits);

                        playHandOutcome.AddHands(playHandOutcomeSplit1.HandsPlayed);
                        playHandOutcome.AddHands(playHandOutcomeSplit2.HandsPlayed);

                        double betTotal = playHandOutcomeSplit1.BetTotal + playHandOutcomeSplit2.BetTotal +
                            insuranceBet;

                        playHandOutcome.BetTotal = betTotal;
                        playHandOutcome.InsuranceBet = insuranceBet;

                        return playHandOutcome;

                    case StrategyDecisionType.SURRENDER:
                        surrenderDone = true;
                        break;

                    case StrategyDecisionType.NA:
                        throw new Exception("Strategy decision was not determined!");
                }
            }

            // return outcome
            playHandOutcome.HandsPlayed.Add(handPlayer);
            playHandOutcome.BetTotal = betSize + insuranceBet;
            playHandOutcome.InsuranceBet = insuranceBet;
            playHandOutcome.SurrenderDone = surrenderDone;

            return playHandOutcome;
        }