21点程序,经销商识别Ace值有问题[python]

2024-06-16 13:29:58 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,伙计们玩21点的时候,庄家会知道王牌可以是1或11,但当机会来了,它发挥它作为1,它失败了。例如:

从2个a开始,技术上你有2分,12分,或者22分。在

假设庄家拿到的第一张牌是杰克牌。在

因此,你有一个12,一个22,或一个32。 因此,计算机保持12姿态,并加上插孔使其成为22和失去。在

这是密码

def evaluateHand(self, dHand):
        DValue = 0

        for card in dHand:
            rank = card.getRank()
            if rank > 10:
                rank = 10
            elif rank == 1 and DValue + 11 <= 21:
                rank = 11
            DValue = DValue + rank


        return DValue 

这里是我定义ace值的地方,我很确定它在elif语句中,但是我尝试的其他方法都没有效果。 有什么建议吗?在


Tags: 密码def计算机card技术机会elifrank
1条回答
网友
1楼 · 发布于 2024-06-16 13:29:58

你可以在一只手上有很多a,但是只有一个可以估价为11而不被破坏。在

  • 首先使用值为1的aces评估手的值

  • 然后,如果手的值是<;12,并且手上有一个ace,则将该ace的值设为11(在hand值上加上10)

  • 返回正确的指针值。

下面是一些可能的代码(由于您没有指定数据结构,所以使用了一些伪代码)

def get_hand_value(self, hand):       
    hand_value = 0
    for card in hand:
        hand_value += card.get_value()      # this evaluates the hand with all aces at 1
    if hand_value < 12 and ace in hand:     # this line is pseudocode, IDK your data structure
                                            # it evaluates one ace (if any) at 11 (if possible w/o busting)
        hand_value += 10
    return hand_value

相关问题 更多 >