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