The 2008 Winter Scripting Games

Advanced Event 10: Blackjack!

Important: The deadline for this event has passed. Solutions are available in VBScript, Windows PowerShell, and Perl.

In Blackjack! competitors must write a script that deals and plays a single hand of Blackjack (Twenty-One).

Not a native speaker of English? These event instructions are also available in the following languages: Chinese (Simplified); Chinese (Traditional); French; German; Japanese; Portuguese Brazilian; Russian; and Spanish. For more information, and to access these localized instructions, see the Scripting Games International page.

*
On This Page
About This EventAbout This Event
Event ScenarioEvent Scenario
How to EnterHow to Enter

About This Event

Division

Advanced

Deadline

Monday, March 3, 2008 (8:00 AM PST)

Points Awarded

10

Top of pageTop of page

Event Scenario

For the final event in the Advanced Division you must write a script that can deal – and play – a single hand of Blackjack (also known as Twenty-One). For the purposes of this event, we’ll be playing a simplified version of Blackjack, one that features the following rules:

No betting is involved. (Sorry; maybe next year.)

All aces are worth 11 points. And yes, we know: in standard Blackjack, aces can be worth either 1 point or 11 points. For Event 10, however, aces will only be worth 11 points. (We don’t want to make this event too complicated.)

Oh, OK: if you want to you can make aces worth 1 or 11. But you don’t have to do this unless you want to.

All face cards (Kings, Queens, Jacks) are worth 10 points.

All other cards are equal to their face value: the three of spades is worth 3 points, the 7 of diamonds is worth 7 points, etc.

Ties (pushes) go the dealer. Suppose, at the end of the hand, the player has 18 points and the dealer has 18 points. In that case, the dealer is declared the winner.

Your script should start by “shuffling” a standard deck of playing cards and then dealing two cards to the player and two more to the dealer. (Not sure what cards make up a ‘standard deck of playing cards?” Then click here for more information.) As in regular blackjack, the two cards to the player should be dealt “face up;” that is, both cards should be revealed:

Your cards:
Seven of Spades
Eight of Spades

By contrast, only one of the dealer’s cards should be revealed:

Dealer's cards:
Ace of Hearts

Note. Notice that we specified the cards by name. Don’t just list card values, like this:

7
8

That will cause your script to fail. Be specific when it comes to listing cards.

Again, following standard Blackjack rules, the player should be given the option to stay (play the two cards he or she was dealt) or hit (be dealt another card). In other words:

Stay (s) or hit (h) ?

If the player chooses “hit,” then he or she should be dealt another card. If the sum total of the three cards is more than 21, then the player automatically loses:

Stay (s) or hit (h) ?h
Seven of Spades
Eight of Spades
Seven of Diamonds
Over 21. Sorry, you lose.

If the sum total is 20 or less, then the player is given another opportunity to hit or stay. (If the sum total is 21 the player wins.) As soon as the player chooses to stay, the dealer (the computer) checks to see if its point total exceeds that of the player. For example, suppose the player has the seven of spades and the eight of spades; that means that the player has 15 points. Now suppose that the dealer has the ace of hearts and the six of diamonds. That means that the dealer has 17 points (11 + 6), which also means that the dealer automatically wins.

Now, suppose the player has 16 points and the dealer has 13. In that case, the dealer must be dealt another card. Let’s examine some possibilities for that next card:

The dealer is dealt a two, giving the dealer 15 points. That’s less than the player’s 16, so the dealer must go again.

The dealer is dealt a nine, giving it 22 points. 22 is more than 21, so the dealer loses.

The dealer is dealt a three, giving both the dealer and the player 16. Because ties go to the dealer, the dealer automatically wins.

A complete hand might play out something like this:

Your cards:
King of Hearts
Seven of Hearts

Dealer's cards:
Nine of Hearts

Stay (s) or hit (h)?s

You have 17.

Dealer’s cards:
Nine of Hearts
Seven of Diamonds

Dealers' cards:

Nine of Hearts
Seven of Diamonds
Five of Diamonds
The dealer has 21. Sorry, you lose.

See? That shouldn’t be too terribly hard, especially not for anyone who made it through the first nine events.

Note that it is perfectly acceptable (in fact, it’s preferred) that this hand of Blackjack take place in the command window. However, we will accept graphical versions (such as an HTA). Just remember that any graphical version is limited to the three Scripting Games languages: VBScript, Windows PowerShell, and Perl.

Top of pageTop of page

How to Enter

After completing the script, click the appropriate link to submit your entry:

Advanced VBScript

Advanced Windows PowerShell

Advanced Perl

If the link doesn’t automatically open a pre-addressed message, send email to scripter@microsoft.com with the subject line Advanced VBScript: Event 10; Advanced Windows PowerShell: Event 10; or Advanced Perl: Event 10.

All you have to do is paste your code into the body of the message and then send the mail. You may also include the following:

A name or nickname we can use to identify you when posting Scripting Games points leaders.

The name of the country you would like to represent. This might be your country of birth or the country you currently live in, but it doesn’t have to be; you can represent any country you wish.

The name of any user group that you belong to. This should be included if your user group is participating in the User Group Challenge.

You can simply type these items in at the top of the email. In that case, your email (assuming you’re submitting an entry for the VBScript division) might look something like this:

Ken Myer
USA
Northern Iowa User Group

For i = 1 to 100
    Wscript.Echo i
Next

Top of pageTop of page