From 25200368af76164184b83a34c7dce9ce17429b2e Mon Sep 17 00:00:00 2001 From: louiscooper136 Date: Mon, 12 Feb 2024 22:52:44 -0500 Subject: [PATCH] (Commit summary. Replace this with a one-line description of this commit.) initial commit What I changed (Replace this with a description of what you changed in this commit. This should be 1-2 sentences.) added notes.md Why I changed it (Describe why you made these changes. Were you working toward a goal? Did you reorganize your code? This should be 1-2 sentences.) explained states Estimate for remaining time to finish assignment: [1 day] --- notes.md | 10 ++++++++-- play_ttt.py | 2 +- ttt/game.py | 4 ++-- ttt/player.py | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/notes.md b/notes.md index fbfc752..21be322 100644 --- a/notes.md +++ b/notes.md @@ -24,15 +24,21 @@ TTTHuman player class, allows user to play actions base on list of availible act 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 | | | | + For #1, choosing 6 wins the game For # 2 choosing 6 blocks 0 from winning. + For #3 choosing 0 gives a win on the next turn regardless of where 0 blocks. + For #4 choosing 4 means 0 has block, then if x chooses 6 then win in 2 or 3. + ### 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? +I think 0 menas the game is fair, 1 is more x wins a negative is more o wins. + diff --git a/play_ttt.py b/play_ttt.py index 24a123f..d2ffa09 100644 --- a/play_ttt.py +++ b/play_ttt.py @@ -6,7 +6,7 @@ from ttt.player import TTTHumanPlayer, TTTComputerPlayer creates new player0, player1, game and view objects? ''' player0 = TTTHumanPlayer("Player 1") -player1 = TTTHumanPlayer("Player 2") +player1 = TTTComputerPlayer("Player 2") game = TTTGame() view = TTTView(player0, player1) diff --git a/ttt/game.py b/ttt/game.py index 13dc3f1..8d74baf 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 fb10a01..3451721 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 #may need to delete ttt for this to work 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."