For context, I am trying to implement a minimax algorithm in python to play tic tac toe. Here's the relevant code:
TicTacToe.py
def dumbPlayer(game, gameType):
return game.successors()[0]
class minimax:
tree = None
def minimaxPlayer(self, game, gameType):
return game.successors()[0]
class TicTacToe:
def play(self, xPlayer=consolePlayer, oPlayer=consolePlayer, output=consolePrint):
while self.winner is None:
output(self)
if self.turn == 'X': self.move(xPlayer(self, TicTacToe))
elif self.turn == 'O': self.move(oPlayer(self, TicTacToe))
output(self, True)
return
main.py:
import TicTacToe as TTT
player2 = TTT.minimax.minimaxPlayer
test = TTT.TicTacToe()
test.play(TTT.dumbPlayer, player2)
Passing in the dumbPlayer function works fine, the problem comes with the minimaxPlayer function. When the play function calls the minimaxPlayer function, I get the following error:
TypeError: minimaxPlayer() missing 1 required positional argument: 'gameType'
From what I understand of python, the "self" parameter is automatically passed to the function and doesn't (or maybe can't) be passed explicitly, so as far as the play function is concerned,
def dumbPlayer(game, gameType)
and
def minimaxPlayer(self, game, gameType)
should be equivalent, but it appears that's not correct in this case.
Is there an easy fix for this? Or will I need to refactor my code? I already have some ideas for how I can restructure the code if I have to, but I'd rather not, and I'd like to know the underlying reason for why this doesn't work how I expect.