I'm working on a casino program that gets a bet (
I'm working on a casino program that gets a bet ($1-$50) from the user, then pulls a slot machine to display a three-string combination of "7", "cherries", "bar", or "(space)". Certain combinations will trigger a bet multiplier, and the user will win back this amount. The run should look like this: ask user for bet, show user the pull and their winnings, then ask user for a new bet, display a new pull, and so on.
我正在开发一个赌场程序,用户可以下注($ 1- $ 50),然后拉出老虎机显示“7”,“樱桃”,“酒吧”或“(空格)的三串组合)”。某些组合将触发投注倍数,用户将赢回此金额。运行应该如下所示:询问用户下注,向用户显示拉动和他们的奖金,然后询问用户新的下注,显示新的拉动,等等。
Right now, I have everything down except for a couple problems - I cannot make it so that the program generates a new random combination for each pull. Secondly, the main loop continues forever, printing the user's pull and winnings forever. Below is the method that generates either "7", "cherries", etc.
现在,除了一些问题之外,我已经把所有事情都解决了 - 我无法做到这一点,以便程序为每次拉动生成一个新的随机组合。其次,主循环永远持续,永远打印用户的拉动和奖金。以下是生成“7”,“樱桃”等的方法。
def rand_string(self):
random.seed(0)
# produces a number between 0 and 999
test_num = random.randrange(1000)
# precompute cutoffs
bar_cutoff = 10 * TripleString.BAR_PCT
cherries_cutoff = bar_cutoff + 10 * TripleString.CHERRIES_PCT
space_cutoff = cherries_cutoff + 10 * TripleString.SPACE_PCT
# bar = 38%, cherries = 40%, space = 7%, seven = 15%
if test_num < bar_cutoff:
return TripleString.BAR
elif test_num < cherries_cutoff:
return TripleString.CHERRIES
elif test_num < space_cutoff:
return TripleString.SPACE
else:
return TripleString.SEVEN
And here is the loop in main:
以下是main中的循环:
while(True):
if bet == 0: #a bet of $0 ends the program
print("Please come again!")
break
else:
print("whirrr...and your pull is " +\
object.pull())
object.display(None)
I thought I could solve this by somehow adding 1 to random.seed() for each loop (we begin with random.seed(0), but for each new pull 1 is added so that random.seed(1) and so on), but I don't know how to go about doing this and I'm not even sure if it's doable. If someone could point out my mistakes here, that'd be great. (sorry if this makes no sense, I'm very new to Python).
我想我可以通过以某种方式为每个循环添加1来增加1来解决这个问题(我们从random.seed(0)开始,但是对于每个新的pull 1都添加了以便random.seed(1)等等) ,但我不知道怎么做这个,我甚至不确定它是否可行。如果有人能在这里指出我的错误,那就太好了。 (对不起,如果没有意义,我对Python很新)。
1 个解决方案
#1
0
You should only call random.seed(0) once in the program. By seeding every time you are reseting the pseudo random number generator and forcing it to produce the same number.
你应该只在程序中调用一次random.seed(0)。每次重置伪随机数生成器并强制它生成相同的数字时播种。
random.seed(0)
while(True):
if bet == 0: #a bet of $0 ends the program
...
You can read more about random seeding here.
您可以在此处阅读有关随机种子的更多信息。
-) from the user, then pulls a slot machine to display a three-string combination of "7", "cherries", "bar", or "(space)". Certain combinations will trigger a bet multiplier, and the user will win back this amount. The run should look like this: ask user for bet, show user the pull and their winnings, then ask user for a new bet, display a new pull, and so on.I'm working on a casino program that gets a bet