From 13743e56d3c6de2e659b5c701e0fe30d2a153533 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 12 Dec 2024 11:31:44 -0500 Subject: [PATCH] Added code for check_winning_combo method and for functionality for check_winner method. Checkpoint 2: Th strategy we used was to list out all of the possible winning combinations and check for each one. --- ttt/game.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ttt/game.py b/ttt/game.py index 2f0e302..f198345 100644 --- a/ttt/game.py +++ b/ttt/game.py @@ -58,4 +58,24 @@ class TTTGame: def check_winner(self, state, symbol): "Checks whether the player with `symbol` has won the game." + combos = [ + [0, 1, 2], + [3, 4, 5], + [6, 7, 8], + [0, 4, 8], + [2, 4, 6], + [0, 3, 6], + [1, 4, 7], + [2, 5, 8] + ] + for combo in combos: + if self.check_winning_combo(state, symbol, combo): + return True return False + + def check_winning_combo(self, state, symbol, combo): + """Checks whether all three spaces in a winning combo are filled with player's symbol.""" + for index in combo: + if state["board"][index] != symbol: + return False + return True