diff --git a/ttt_game.py b/ttt_game.py index 0043ab6..9f0a292 100644 --- a/ttt_game.py +++ b/ttt_game.py @@ -1,7 +1,5 @@ - class TTTGame: - """Models a tic-tac-toe game. - """ + "Models a tic-tac-toe game." def __init__(self, playerX, playerO): self.board = [None] * 9 diff --git a/ttt_player.py b/ttt_player.py index 88dc823..c130775 100644 --- a/ttt_player.py +++ b/ttt_player.py @@ -1,13 +1,30 @@ from click import Choice, prompt import random -class TTTPlayer: - "A tic tac toe player." +class TTTHumanPlayer: + "A human tic tac toe player." def __init__(self, name): "Sets up the player." self.name = name + def choose_move(self, game): + "Chooses a move by prompting the player for a choice." + choices = Choice([str(i) for i in game.get_valid_moves()]) + move = prompt("> ", type=choices, show_choices=False) + return int(move) + +class TTTComputerPlayer: + "A computer tic tac toe player" + + def __init__(self, name): + "Sets up the player." + self.name = name + + def choose_move(self, game): + "Chooses a random move from the moves available." + return random.choice(game.get_valid_moves()) + def get_symbol(self, game): "Returns this player's symbol in the game." if game.players['X'] == self: @@ -16,20 +33,3 @@ class TTTPlayer: return 'O' else: raise ValueError(f"Player {self.name} isn't in this game!") - -class TTTHumanPlayer(TTTPlayer): - "A human tic tac toe player." - - def choose_move(self, game): - "Chooses a move by prompting the player for a choice." - choices = Choice([str(i) for i in game.get_valid_moves()]) - move = prompt("> ", type=choices, show_choices=False) - return int(move) - -class TTTComputerPlayer(TTTPlayer): - "A computer tic tac toe player" - - def choose_move(self, game): - "Chooses a random move from the moves available." - return random.choice(game.get_valid_moves()) - diff --git a/ttt_view.py b/ttt_view.py index 992c09f..5f8dc4c 100644 --- a/ttt_view.py +++ b/ttt_view.py @@ -1,8 +1,7 @@ import click class TTTView: - """Handles user interaction with a tic-tac-toe game. - """ + "Handles user interaction with a tic-tac-toe game." greeting = "Welcome to tic-tac-toe" goodbye = "Well, that's a wrap." divider = "---+---+---"