diff --git a/ttt/game.py b/ttt/game.py index 2f0e302..37536f1 100644 --- a/ttt/game.py +++ b/ttt/game.py @@ -58,4 +58,8 @@ class TTTGame: def check_winner(self, state, symbol): "Checks whether the player with `symbol` has won the game." + pattern_to_win = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]] + for pattern in pattern_to_win: + if state["board"][pattern[0]]==symbol and state["board"][pattern[1]]==symbol and state["board"][pattern[2]]==symbol: + return True return False