From ab309c8be8b2d084e48612e6be35f40daa059703 Mon Sep 17 00:00:00 2001 From: Justin Toombs Date: Mon, 12 Feb 2024 22:54:26 -0500 Subject: [PATCH] The computer player was trained to use more effective strategies. What I changed I replaced the random strategy class with the lookahead strategy class. Why I changed it By replacing the classes, the computer player stopped responding randomly and instead used data provided to integrate effective strategies. Estimate for remaining time to finish assignment: [1-2 hours depending on peer assistance] --- notes.md | 8 +++++--- play_ttt.py | 2 +- ttt/player.py | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/notes.md b/notes.md index e5ac000..7f230df 100644 --- a/notes.md +++ b/notes.md @@ -21,15 +21,17 @@ A player can choose which action to play on a turn from within the TTTHumanPlaye 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 the first board, it is simple to choose 6 to win the game. The second board in also 6, but is done to prevent O from winning while setting up a potential win scenario. The third board simultaneously blocks O from making meaningful advances while setting up a guaranteed win scenario. The fourth board is setting up a potential win scenario in which O will be forced to block, leaving X free to set up a situation similar to the third board. + ### 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 state demonstrates a 0 value, which implies that the game is as fair as possible since it means an equal number of wins for X or O. \ No newline at end of file diff --git a/play_ttt.py b/play_ttt.py index ef5530a..d1b6995 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("Player 2") game = TTTGame() view = TTTView(player0, player1) diff --git a/ttt/player.py b/ttt/player.py index bfbbe15..e5b6ef2 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()) def choose_action(self, state): "Chooses a random move from the moves available."