Refactor into packages
This commit is contained in:
parent
26f3869ec7
commit
cc50795d43
|
@ -1,3 +1,3 @@
|
|||
*.swp
|
||||
*.swo
|
||||
__pycache__/*
|
||||
**/__pycache__/*
|
||||
|
|
|
@ -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")
|
|
@ -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.
|
||||
|
|
@ -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)
|
|
@ -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:
|
|
@ -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
|
Loading…
Reference in New Issue