From 75956545ba65770f5d70551bcc27f4711ee31cd6 Mon Sep 17 00:00:00 2001 From: PritamP20 <102867939+PritamP20@users.noreply.github.com> Date: Fri, 7 Oct 2022 19:05:09 +0530 Subject: [PATCH] Create player.py --- scripts/MiniMaxAlgo/player.py | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scripts/MiniMaxAlgo/player.py 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