在pythonα+β剪枝 [英] alpha beta pruning in python
问题描述
在α,β剪枝算法, 我在其中定义的函数高清的getAction(个体经营,游戏状态)ID一类。我在DEF的getAction
In alpha, beta pruning algorithm, I have a class in which a function def getAction(self,gamestate) id defined. I made 2 more function in def getAction
像:
class BAC:
def you(self,gamestate):
def me(gamestate,depth,alpha, beta):
------
return v
def both(gamestate,depth,alpha, beta):
-------------------
return v
return me(gamestate,0,alpha, beta)-
我需要把α,β函数我和两个。但是,在我定义的α和β值。如果我定义的α和β的高清我和高清两种则会发生错误,因为全局名称字母不是present。
I need to put alpha, beta in functions me and both. But where do I define alpha and beta values. If I define alpha and beta in def me and def both then error occurs as there global name alpha is not present.
如何使α和β的局部变量或者我怎样才能使人们有可能正常工作?
How do I make alpha and beta local variables or How can I make it possible to work correctly?
推荐答案
我猜你whant做定义的α和β为你的类属性。
I guess that you whant to do define alpha and beta as your classes' attribute.
您可能需要一个类的构造函数初始化你的变量。
You may need a class constructor that initializes your variables.
class BAC:
def __init__(self):
self.alpha= 'Hello '
self.beta= 'World!'
def me(self):
print self.alpha + self.beta
或者,您可以初始化属性变量,如:
Or you can initialize your attributes variables like:
class BAC:
def me(self,alpha,beta):
self.alpha = alpha
self.beta= beta
print self.alpha + self.beta
所有你需要的是指阶级的属性,如果你想持久性。
All you need is to refer to the classes' attribute if you want persistence.
如果你选择第一个解决方案:
If you choose the first solution:
my_bac = Bac()
print my_bac.alpha + my_bac.beta
的输出将是
Hello World!
Hello World!
这篇关于在pythonα+β剪枝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!