diff --git a/notes.md b/notes.md index dabd140..b8f1167 100644 --- a/notes.md +++ b/notes.md @@ -30,15 +30,23 @@ available actions generated For each of the following board states, if you are playing as X and it's your turn, which action would you take? Why? - | O | O | | O | X | X | O | + | O | O | | O x | X | X | O | ---+---+--- ---+---+--- ---+---+--- ---+---+--- - X | X | | X | X | O | O | | + X | X | x | X | x X | O | O | x | ---+---+--- ---+---+--- ---+---+--- ---+---+--- - | | | | O | | | | + | | | | O | | | | + +For #1, choosing 6 wins the game. For #2, choosing 6 blocks O from winning. +For #3, choosing 0 gives a win on the next turn regardless of where O blocks. +For #4, choosing 4 means O has to block, then if X chooses 6 on the next turn, +there is a guaranteed win in 2 or 3 regardless of where O blocks. ### Initial game state You can get the inital game state using game.get_initial_state(). What is the current and future reward for this state? What does this mean? +The current and future reward for this state is 0 which tells me there are as many +games where x wins as loses and most games end in a draw? Does this mean it's a +fair game? diff --git a/play_ttt.py b/play_ttt.py index afce7cb..867b3e5 100644 --- a/play_ttt.py +++ b/play_ttt.py @@ -3,7 +3,7 @@ from ttt.view import TTTView from ttt.player import TTTHumanPlayer, TTTComputerPlayer player0 = TTTHumanPlayer("Player 1") -player1 = TTTHumanPlayer("Player 2") +player1 = TTTComputerPlayer("Robot") game = TTTGame() view = TTTView(player0, player1) diff --git a/ttt/game.py b/ttt/game.py index 26d6f35..eba02ca 100644 --- a/ttt/game.py +++ b/ttt/game.py @@ -67,9 +67,9 @@ class TTTGame: for i in range(3): if currentState[i] == symbol and currentState[i+3] == symbol and currentState[i+6] == symbol: return True - if currentState[0] == symbol and currentState[4] == symbol and currentState[8] == symbol: + if currentState[4] == symbol and currentState[0] == symbol and currentState[8] == symbol: return True - if currentState[2] == symbol and currentState[4] == symbol and currentState[6] == symbol: + if currentState[4] == symbol and currentState[2] == symbol and currentState[6] == symbol: return True return False diff --git a/ttt/player.py b/ttt/player.py index bfbbe15..300f919 100644 --- a/ttt/player.py +++ b/ttt/player.py @@ -1,5 +1,5 @@ from click import Choice, prompt -from strategy.random_strategy import RandomStrategy +from strategy.lookahead_strategy import LookaheadStrategy from ttt.game import TTTGame import random @@ -24,7 +24,7 @@ class TTTComputerPlayer: def __init__(self, name): "Sets up the player." self.name = name - self.strategy = RandomStrategy(TTTGame()) + self.strategy = LookaheadStrategy(TTTGame(), deterministic=False) def choose_action(self, state): "Chooses a random move from the moves available."