- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到的主要问题是当我选择 stay
时会发生什么上hand_one
,然后 hit
上hand_two
.
而不是让我hit or stay
上hand_two
再次,它让我回到hit or stay
上hand_one
,当我已经选择留在 hand_one 时,所以 hand_one 应该没有更多选择。这会导致出现多个打印语句和不正确的游戏的问题。
我的代码有什么问题,就像导致它循环回到 hand_one
.
完整代码在这里:http://labs.codecademy.com/Bjaf/2#:workspace
这是可能导致问题的部分。
def hit_or_stay(person):
hit_or_stay = raw_input("Do you want to hit or stay? You can type h or s.")
if hit_or_stay == 'h' or hit_or_stay == 'hit':
deal_one_card(person)
value_of_current_cards(person)
number_value_of_hand()
elif hit_or_stay == 's'or hit_or_stay == 'stay':
print "You stayed"
return
else:
hit_or_stay(person)
def number_value_of_hand():
if number_of_hands > 0:
value_of_hand_one = value_of_current_cards(hand_one)
if value_of_hand_one < 18:
print "\n" "You have %i" % (value_of_hand_one)
hit_or_stay(hand_one)
elif value_of_hand_one > 18:
print "You Lose"
return
elif value_of_hand_one == 18:
print "You hit HOT 18!!!"
return
if number_of_hands > 1:
value_of_hand_two = value_of_current_cards(hand_two)
if value_of_hand_two < 18:
print "\n" "Your second hand has %i" % (value_of_hand_two)
hit_or_stay(hand_two)
elif value_of_hand_two > 18:
print "You Lose"
return
elif value_of_hand_two == 18:
print "You hit HOT 18!!!"
return
number_value_of_hand()
谁能明白为什么它会循环回来给hand_one另一个选择?以及我该如何解决它?非常感谢!
最佳答案
您的问题出现在这一步:
hit_or_stay(hand_two)
当你点击 hand_two 时,你的代码会执行以下操作:
deal_one_card(person)
value_of_current_cards(person)
number_value_of_hand()
问题就在那里,因为 number_value_of_hand()
将您带回到该函数的开头,并再次遍历 hand_one 选项。
您可能需要重写 number_value_of_hand()
函数以包含一个参数,告诉它从哪里开始(hand_one、hand_two 等)
我可能会创建一个手牌列表,并遍历该列表。然后,您可以调用 number_of_hands(hands[i])
来获取第 i
手。
关于python - Blackjack 风格的 Python(计算机)游戏循环不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20481181/
我正在研究二十一点游戏,作为面向对象编程类(class)的期末项目。我一生都无法弄清楚为什么我的牌无法正确渲染(未显示的牌的值仍然被考虑在内 - 这意味着如果我有二十一点并且我只能看到我的一张牌,我仍
我已分配使用老师提供的 JFrame 和卡片图像编写一个基本的 BlackJack 窗口程序。我按照我认为应该有效的方式写下了所有内容,但是当我编译它时它根本没有显示出来。我是不是错过了什么? 当我编
#include #include #include #include typedef enum {Clubs, Diamonds, Hearts, Spades} suit_t; ty
我正在创建一个二十一点程序。我目前正处于“号码检查”过程中。因此,一旦发牌并且玩家要求“Hit”,我需要检查他们所发的牌是否超过 21 张。我试过这个: if(pCard1+pCard2+pCard3
第一次在这里发帖。我听说过很多关于社区的好消息。我是一名业余程序员,到目前为止已经涉足过 C++ 和 Java。无论如何,我一直在绞尽脑汁地研究这个在过去几天里随意组合的 Java 二十一点游戏。基本
我的代码有问题。它会产生随机错误,我不知道为什么。我是 C++ 的新手,所以请多多包涵 >.> 这是有问题的代码: while (!IsGameOver) { struct decktype
很抱歉,这没有达到应有的详细程度,但我的时间实在是太紧迫了。我正在尝试编写一个程序来模拟 Blackjack 游戏,该程序使用代表输入文件(模拟牌组)中的纸牌的字符。我还没有完成,但正如我所说,我几乎
我正在使用 openaigym 来制作二十一点的 AI。 但我不擅长 python 和gym,所以不知道如何完成代码。 我一直在尝试编写一个简单的代码来使用 Q-learning 构建人工智能。 但我
我的 child 有一项家庭作业是用 Java 编写 Blackjack。我帮了他一点忙,但大部分都是他自己做的,而且实际上演奏得很好。他甚至发现了一个我在计算手牌值(value)时没有看到的错误。然
所以我在玩 Java 二十一点游戏时遇到了一些麻烦。我已经不再使用 HashMap 来表示卡名称和值,并将其转换为 String[],因为它更容易。然而,我似乎破坏了其中的一些代码: private
尝试创建二十一点游戏,但我在弄清楚如何打印纸牌和纸牌阵列时遇到了一些麻烦。 因此,当玩家看到前两张牌后,他们可以选择要牌或停牌。 当他们选择击中时,我希望它从我创建的数组中打印一张随机卡,并将卡的整数
想想二十一点游戏...我创建了一个方法,它可以简单计算计算机是否应该抽牌,并且只是对规则进行硬编码。我想让它变得更加“智能”,从而使游戏变得更加难以预测,即使对于创作者(我)来说也是如此。 我可以在这
我正在用 Java 编写一个经典的二十一点游戏程序。 规则是一样的,我们作为玩家和庄家(CPU)在一定的规则下进行选择。 我的代码,即下面的,制作了 2 堆独立的牌组,一组用于玩家,一组用于经销商,每
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我正在尝试使用 PHP 制作 BlackJack 游戏,但我遇到了以下问题: 我制作了以下数组: function random_card(){ $cards = array( 1
这是我的代码: import java.util.*; import java.util.Scanner; public class Assignment2 { public static v
我正在尝试在 java 中玩二十一点,但在尝试从类创建对象时遇到问题。代码是: 参与者:此类为玩家和荷官生成一手牌。 public abstract class Participant { prote
我正在对 Elm 进行独立研究,我感觉我又重新开始学习编程了!作为一个学习语言的项目,我试图让一个简单的二十一点启动并运行,但是一旦我开始,我意识到我仍然没有掌握多少。我可以从一副牌中抽取卡片并将它们
锁定。这个问题及其答案是locked因为这个问题是题外话,但具有历史意义。它目前不接受新的答案或互动。 挑战 按字符数计算的最短代码,用于从给定的号码牌列表中输出最佳情况下的二十一点手牌。 输入是由空
我正在用 Java 创建一个 BlackJack 游戏,并尝试在创建它时使用 MVC 设计。到目前为止我已经创建了以下类:- 卡:持有创建卡- 牌组:创建一副包含全部 52 张牌的牌组- 手牌:持有一
我是一名优秀的程序员,十分优秀!