gpt4 book ai didi

python 老虎机 : Calculating Line Payouts

转载 作者:太空宇宙 更新时间:2023-11-04 04:17:31 27 4
gpt4 key购买 nike

我是一名 Python 新手,正在尝试创建一个模拟真机支出的老虎机模拟器。我在计算线路支出时遇到了问题,我确信有一种更智能的方法可以遍历线路并计算它们。

定义一些我将要使用的常量:

SymbolMap = ["Boats","Bonus","Buoys","Clams","Light Houses","Lobsters","Scatter","Seagulls","Starfish","Tuna","Wilds"]

#The ints in reels below are a simpler way to express the SymbolMap above

Reels = [[9,8,3,4,6,3,8,1,5,6,2,3,8,2,3,8,5,4,3,10,7,8,10,1,3,0,8,9,3,8,9,5,3,8,0,4,3,8,0,9,2,7,5,3,8,0,7],
[3,2,4,3,2,4,1,7,3,0,7,9,0,1,8,7,10,1,7,4,5,10,2,3,1,7,3,6,5,9,7,6,8,3,0,5,7,3,1,8,7,2,4,3,9,7,0],
[0,8,3,1,4,0,5,8,1,4,8,1,9,8,3,7,8,10,1,4,7,8,9,3,0,9,8,1,9,4,8,6,4,5,7,8,6,2,9,5,1,8,4,7,2,0,9],
[7,9,2,7,6,2,8,7,9,10,2,9,8,5,7,9,10,5,4,2,7,0,3,8,4,7,0,3,2,7,0,4,8,9,7,2,8,3,2,7,8,3,5,10,2,7,8],
[3,10,0,5,2,8,4,9,8,4,7,10,9,2,0,3,9,2,8,3,6,2,8,9,3,2,0,4,9,5,4,7,3,5,8,0,4,9,7,8,4,3,5,7,8,3,7]]


# Lines are the row to look for on each reel. i.e. Lines[0] is a straight line of the 2nd row.
# Lines[3] starts in top left corner of matrix, and forms inverted V shape.

Lines = [[1,1,1,1,1],
[0,0,0,0,0],
[2,2,2,2,2],
[0,1,2,1,0],
[2,1,0,1,2],
[2,2,1,0,0],
[0,0,1,2,2],
[1,2,1,0,1],
[1,0,1,2,1],
[2,1,1,1,0],
[0,1,1,1,2],
[1,2,2,1,0],
[1,0,0,1,2],
[1,1,2,1,0],
[1,1,0,1,2]]

#Payouts are how many credits won for symbols in a row. For example, Symbols[0] is Boats.
#2 boats is 0 credits, 3 boats is 25 credits, 4 boats is 100 credits, 5 boats is 500 credits.
#They must be continuous and from left to right. I.e. BOAT-BOAT-CLAM-BOAT-BOAT on a payline wins 0.
#Similarly, CLAM-CLAM-BOAT-BOAT-BOAT wins 0.

Payouts = [[0,25,100,500],
[0,0,0,0],
[0,25,100,500],
[0,5,30,200]]

#Initializing a 3X5 matrix to represent reels

SpinValues = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]

#Initializing message
Message = ''

#Initializing TotalWin
TotalWin = 0

自旋逻辑,可正确生成 3X5 随机数矩阵。 是否有更好的方法来处理“如果前 3 个符号匹配”部分,因为我必须再次重复 4 个符号和 5 个符号?由于每行只能获得一次支付,我将从 5 个符号的支出开始,然后逐渐减少到 2 个。我从 3 个开始,因为它最常见,也最容易测试。我还必须考虑一个 wild equals any symbol,我还没有尝试解决这个问题。同样,有一个分散支付(这意味着如果您在矩阵中的任何位置有 X 个分散符号,您将获得支付。这部分很容易)。还有一个奖励游戏,我稍后会处理:

def spin(linesPlayed, wager):
for i, object in enumerate(Reels):
length = len(Reels[i])
StopValue = random.randint(0,length-1)
SpinValues[1][i] = Reels[i][StopValue]
if StopValue == 0:
SpinValues[0][i] = Reels[i][-1]
else:
SpinValues[0][i] = Reels[i][StopValue - 1]
if StopValue == len(Reels[i])-1:
SpinValues[2][i] = Reels[i][0]
else:
SpinValues[2][i] = Reels[i][StopValue +1]
print(SpinValues[0])
print("\n")
print(SpinValues[1])
print("\n")
print(SpinValues[2])

for i in range(linesPlayed):
#if first 3 symbols match
if SpinValues[Lines[i][0]] == SpinValues[Lines[i][1]] == SpinValues[Lines[i][2]]:
PayTable(i,wager,3,SpinValues[Lines[i][0]])
#if first 4 symbols match
#if first 5 symbols match
#handle scatter pay
#wilds?
#handle bonus trigger

处理胜利:

def PayTable(i,wager,symbolCount,symbol):
LineWin = Payouts[symbol][symbolCount] * wager
TotalWin += Payouts[symbol][symbolCount] * wager
Message += "Line " + str(i) +" wins " + str(LineWin) + " credits with " + str(symbolCount) + " " + SymbolMap[symbol] + "!" + "\n"

我收到 TotalWin 和 Message 都未定义的错误。我认为我可以在全局范围内定义它们?

最佳答案

您需要在每个函数中使用 global 关键字来访问在父函数中定义的变量。例如:

def PayTable(i,wager,symbolCount,symbol):    
global TotalWin
global Message

关于 python 老虎机 : Calculating Line Payouts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55145090/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com