编程介的小学生 2019-09-23 21:54 采纳率: 20.5%
浏览 92

Blackjack 程序的书写

Description

In the Blackjack card game, the player and the dealer are dealt two cards initially. One of dealer's cards is dealt face up and is known to the player but the other one is dealt face down. Given the two initial cards you are dealt and the dealer's face-up card, you are asked to compute the probability that your two-card hand is better than the dealer's two-card hand. This is not simple: the probability changes as the game is played because cards are dealt from the decks without replacement. To simplify the problem, we will only compute the probability when the cards are first dealt from the decks. That is, no cards have been dealt from the decks before.

In this game, an Ace has a value of 1 or 11 (chosen by the person holding the cards), the face cards (K, Q, J) have a value of 10, and the values of the remaining cards are given by their numerical values. The player wins against the dealer if:
the total value of the player's hand does not exceed 21; and
the total value of his hand is higher than that of the dealer or the total value of the dealer's hand exceeds 21.

The value of an Ace is chosen to maximize the total value without exceeding 21. If we are only interested in two-card hands, it is impossible for the total value to exceed 21.

Skilled players remember which cards have already been dealt and make decisions accordingly. To make this difficult, many casinos use multiple decks of cards to play the game. Each deck has 52 cards, 4 of each of A, K, Q, J, T (10), 9, ..., and 2.
Input

The input consists of a number of test cases. Each test case starts with a line containing a positive integer n (n <= 10) indicating the number of decks used. This is followed by a line containing 3 characters (separated by a space) in the set {A, K, Q, J, T, 9, ..., 2}, representing the dealer's face-up card and your two cards in the hand. In each case, assume that the n decks have been shuffled together randomly. The end of input is specified by n = 0.
Output

For each hand dealt, print on a line the probability of winning as a percentage, rounded to 3 decimal places. Separate the output of each case by a blank line.
Sample Input

1
T A J
4
2 3 4
0
Sample Output

93.878%

21.951%

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 树莓派安卓APK系统签名
    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波