RMR
RMR

Reputation: 629

How to pass a function in the tuple argument in python?

How to pass a function in the tuple argument? *players is a tuple.

this is one function inside a class (TicTacToe)

def play_game(self, *players):
        state = self.initial
        while True:
            for player in players:
                move = player(self, state)
                state = self.result(state, move)
                if self.terminal_test(state):
                    self.display(state)
                    return self.utility(state, self.to_move(self.initial))

How can I pass the below function in *players arguments?

def alpha_beta_player(game, state):
    return alpha_beta_search(state, game)

My attempt is as follows:

ttt = MyTicTacToe()
u = ttt.play_game(alpha_beta_player,alpha_beta_player)
print(u)

Upvotes: 0

Views: 64

Answers (1)

wasif
wasif

Reputation: 15508

Enclose passed tuple in parentheses and unpack with *

ttt = MyTicTacToe()
u = ttt.play_game(*(alpha_beta_player,alpha_beta_player))
print(u)

Upvotes: 1

Related Questions