Refactor into packages

This commit is contained in:
Chris Proctor 2022-05-11 16:28:22 -04:00
parent 26f3869ec7
commit cc50795d43
7 changed files with 19 additions and 18 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
*.swp
*.swo
__pycache__/*
**/__pycache__/*

View File

@ -1,6 +1,6 @@
from ttt_game import TTTGame
from ttt_view import TTTView
from ttt_player import TTTHumanPlayer
from ttt.game import TTTGame
from ttt.view import TTTView
from ttt.player import TTTHumanPlayer
player0 = TTTHumanPlayer("Player 1")
player1 = TTTHumanPlayer("Player 2")

View File

@ -1,16 +1,6 @@
from types import MethodType
from random import choice
class RandomStrategy:
"""A Strategy which randomly chooses a move. Not a great choice.
"""
def __init__(self, game):
self.game = game
def choose_action(self, state):
possible_actions = self.game.get_actions(state)
return choice(possible_actions)
class LookaheadStrategy:
"""A Strategy which considers the future consequences of an action.

View File

@ -0,0 +1,11 @@
from random import choice
class RandomStrategy:
"""A Strategy which randomly chooses a move. Not a great choice.
"""
def __init__(self, game):
self.game = game
def choose_action(self, state):
possible_actions = self.game.get_actions(state)
return choice(possible_actions)

View File

@ -1,6 +1,6 @@
from click import Choice, prompt
from strategy import RandomStrategy
from ttt_game import TTTGame
from strategy.random_strategy import RandomStrategy
from ttt.game import TTTGame
import random
class TTTHumanPlayer:

View File

@ -1,4 +1,4 @@
from ttt_game import TTTGame
from ttt.game import TTTGame
import click
class TTTView:
@ -64,7 +64,7 @@ class TTTView:
self.print_board(state)
if self.game.check_winner(state, 'X'):
winner = self.players['X']
elif self.game.check_winner(game.state, 'O'):
elif self.game.check_winner(state, 'O'):
winner = self.players['O']
else:
winner = None