diff --git a/ttt/game.py b/ttt/game.py index 2f0e302..68983af 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." + b = state["board"] + for r in range(3): + if b[3*r] == symbol and b[3*r+1] == symbol and b[3*r+2] == symbol: + return True + for c in range(3): + if b[c] == symbol and b[c+3] == symbol and b[c+6] == symbol: + return True + if b[0] == symbol and b[4] == symbol and b[8] == symbol: + return True + if b[2] == symbol and b[4] == symbol and b[6] == symbol: + return True return False