From b84640e4b393ce769ca30a2d4b356f87452ddb98 Mon Sep 17 00:00:00 2001 From: Justin Toombs Date: Mon, 12 Feb 2024 21:50:12 -0500 Subject: [PATCH] This submit dealt with the problems of not determining a winner and always ending with a tie regardless of the outcome. What I changed I looked to find all of the possible win scenarios, which took some time to determine. I then utilized several loops to ensure a winner is declared when three in a row is earned. Why I changed it While perhaps not done in the most proficient way, this helped to map out each of the win scenarios while still understanding it at the surface level. Estimate for remaining time to finish assignment: [2-4 hours depending on peer assistance] --- notes.md | 2 +- ttt/game.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/notes.md b/notes.md index 049b055..e5ac000 100644 --- a/notes.md +++ b/notes.md @@ -14,7 +14,7 @@ The board is shown using TTTView with the methods for print_board() and get_acti ### Choosing which action to play on a turn A player can choose which action to play on a turn from within the TTTHumanPlayer with the method for choose_action(). -## Checkpoint 2 Notes +## Checkpoint 3 Notes ### TTT Strategy diff --git a/ttt/game.py b/ttt/game.py index 2f0e302..9678d14 100644 --- a/ttt/game.py +++ b/ttt/game.py @@ -58,4 +58,15 @@ class TTTGame: def check_winner(self, state, symbol): "Checks whether the player with `symbol` has won the game." + currentState = state["board"] + for i in range (0,7,3): + if currentState[i] == symbol and currentState [i+1] == symbol and currentState [i+2] == symbol: + return True + 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: + return True + if currentState[2] == symbol and currentState [4] == symbol and currentState [6] == symbol: + return True return False