I'm trying to make an AI that plays with the player but it keeps giving me a TypeError
:
TypeError: __init__() missing 1 required positional argument: 'sign'.
from random import choice
class Player:
def __init__(self, name, sign, board = None):
self.name = name # player's name
self.sign = sign # player's sign O or X
self.board = board
def get_sign(self):
# return an instance sign
return self.sign
def get_name(self):
# return an instance name
return self.name
def choose(self, board):
# prompt the user to choose a cell
# if the user enters a valid string and the cell on the board is empty, update the board
# otherwise print a message that the input is wrong and rewrite the prompt
# use the methods board.isempty(cell), and board.set(cell, sign)
while True:
cell = input(f"{self.name}, {self.sign}: Enter a cell [A-C][1-3]:\n")
cell = cell.upper()
#checks to see if input matches to a cell and if the cell is empty
if cell == "A1" or cell == "B1" or cell == "C1" or cell == "A2" or cell == "B2" or cell == "C2" or cell == "A3" or cell == "B3" or cell == "C3":
if board.isempty(cell):
board.set(cell, self.sign)
break
else:
print("You did not choose correctly.")
else:
print("You did not choose correctly.")
class AI(Player):
def __init__(self, name, sign, board = None):
super().__init__(board)
self.sign = sign
self.name = name
def choose(self, board):
valid_moves = ["A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"]
cell = choice(valid_moves)
board.set(cell, self.sign)
I call it in another file like this:
player1 = AI("Bob", "X", board)