diff --git a/scripts/MiniMaxAlgo/player.py b/scripts/MiniMaxAlgo/player.py new file mode 100644 index 0000000..2ffe8cc --- /dev/null +++ b/scripts/MiniMaxAlgo/player.py @@ -0,0 +1,38 @@ +import math +import random + + +class Player: + def __init__(self, letter): + self.letter = letter + + def get_move(self, game): + pass + + +class HumanPlayer(Player): + def __init__(self, letter): + super().__init__(letter) + + def get_move(self, game): + valid_square = False + val = None + while not valid_square: + square = input(self.letter + '\'s turn. Input move (0-9): ') + try: + val = int(square) + if val not in game.available_moves(): + raise ValueError + valid_square = True + except ValueError: + print('Invalid square. Try again.') + return val + + +class RandomComputerPlayer(Player): + def __init__(self, letter): + super().__init__(letter) + + def get_move(self, game): + square = random.choice(game.available_moves()) + return square