Refactor into packages
This commit is contained in:
parent
26f3869ec7
commit
cc50795d43
|
@ -1,3 +1,3 @@
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
__pycache__/*
|
**/__pycache__/*
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from ttt_game import TTTGame
|
from ttt.game import TTTGame
|
||||||
from ttt_view import TTTView
|
from ttt.view import TTTView
|
||||||
from ttt_player import TTTHumanPlayer
|
from ttt.player import TTTHumanPlayer
|
||||||
|
|
||||||
player0 = TTTHumanPlayer("Player 1")
|
player0 = TTTHumanPlayer("Player 1")
|
||||||
player1 = TTTHumanPlayer("Player 2")
|
player1 = TTTHumanPlayer("Player 2")
|
|
@ -1,16 +1,6 @@
|
||||||
from types import MethodType
|
from types import MethodType
|
||||||
from random import choice
|
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:
|
class LookaheadStrategy:
|
||||||
"""A Strategy which considers the future consequences of an action.
|
"""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 click import Choice, prompt
|
||||||
from strategy import RandomStrategy
|
from strategy.random_strategy import RandomStrategy
|
||||||
from ttt_game import TTTGame
|
from ttt.game import TTTGame
|
||||||
import random
|
import random
|
||||||
|
|
||||||
class TTTHumanPlayer:
|
class TTTHumanPlayer:
|
|
@ -1,4 +1,4 @@
|
||||||
from ttt_game import TTTGame
|
from ttt.game import TTTGame
|
||||||
import click
|
import click
|
||||||
|
|
||||||
class TTTView:
|
class TTTView:
|
||||||
|
@ -64,7 +64,7 @@ class TTTView:
|
||||||
self.print_board(state)
|
self.print_board(state)
|
||||||
if self.game.check_winner(state, 'X'):
|
if self.game.check_winner(state, 'X'):
|
||||||
winner = self.players['X']
|
winner = self.players['X']
|
||||||
elif self.game.check_winner(game.state, 'O'):
|
elif self.game.check_winner(state, 'O'):
|
||||||
winner = self.players['O']
|
winner = self.players['O']
|
||||||
else:
|
else:
|
||||||
winner = None
|
winner = None
|
Loading…
Reference in New Issue