GR.Gambling.Blackjack.Game.IsValidAction C# (CSharp) Méthode

IsValidAction() public méthode

public IsValidAction ( ActionType action ) : bool
action ActionType
Résultat bool
        public bool IsValidAction(ActionType action)
        {
            // can always hit
            if (action == ActionType.Hit)
                return true;

            // can always stand
            if (action == ActionType.Stand)
                return true;

            // surrender only available on the first two cards
            // and when no other action has been yet made
            if (action == ActionType.Surrender)
            {
                if (player_handset.HandCount == 1 && !player_handset.ActiveHand.Acted)
                    return true;

                return false;
            }

            // double is available as a first action on hand
            // and the hand isn't blackjack, or on splits
            if (action == ActionType.Double)
            {
                if (!player_handset.ActiveHand.Acted)
                    return true;

                return false;
            }

            // split is available as long as split cap hasn't been
            // reached and there's no other action done and the hand is a pair
            if (action == ActionType.Split)
            {
                if (split_count < rules.Splits &&
                    !player_handset.ActiveHand.Acted &&
                    player_handset.ActiveHand.IsPair())
                    return true;
                return false;
            }

            // should never reach here
            return false;
        }

Usage Example

Exemple #1
0
        public override ActionType GetBestAction(Game game)
        {
            Console.WriteLine("Upcard: " + game.Upcard() + " | Hand: " +
                              game.PlayerHandSet.ActiveHand + " (" +
                              game.PlayerHandSet.ActiveHand.PointCount() + ")");

            if (game.IsValidAction(ActionType.Hit))
            {
                Console.Write("(H)it ");
            }
            if (game.IsValidAction(ActionType.Stand))
            {
                Console.Write("(S)tand ");
            }
            if (game.IsValidAction(ActionType.Surrender))
            {
                Console.Write("Sur(r)ender ");
            }
            if (game.IsValidAction(ActionType.Split))
            {
                Console.Write("S(p)lit ");
            }
            if (game.IsValidAction(ActionType.Double))
            {
                Console.Write("(D)ouble ");
            }

            string input = Console.ReadLine();

            if (input[0] == 'h')
            {
                return(ActionType.Hit);
            }
            if (input[0] == 's')
            {
                return(ActionType.Stand);
            }
            if (input[0] == 'r')
            {
                return(ActionType.Surrender);
            }
            if (input[0] == 'p')
            {
                return(ActionType.Split);
            }
            if (input[0] == 'd')
            {
                return(ActionType.Double);
            }

            Console.WriteLine("Ops");
            return(ActionType.Surrender);
        }
All Usage Examples Of GR.Gambling.Blackjack.Game::IsValidAction