views:

36

answers:

1

In alpha, beta pruning algorithm, I have a class in which a fucntion def getAction(self,gamestate) id defined. I made 2 more function in def getAction

Like:

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)-

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 made alpha nd beta local variables or How acan I make it possible to work correctly.

+1  A: 

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

The output will be

Hello World!
Hello World!
djondal