diff --git a/notes.md b/notes.md index 02f68b3..d60fba1 100644 --- a/notes.md +++ b/notes.md @@ -30,6 +30,7 @@ and it's your turn, which action would you take? Why? ---+---+--- ---+---+--- ---+---+--- ---+---+--- | | | | O | | | | + ### Initial game state You can get the inital game state using game.get_initial_state(). diff --git a/ttt/game.py b/ttt/game.py index 2f0e302..f99f3c1 100644 --- a/ttt/game.py +++ b/ttt/game.py @@ -58,4 +58,25 @@ 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, 3, 6], + [1, 4 ,7], + [2, 5 ,8], + [0, 4 ,8], + [2, 4 ,6] + ] + 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 combo eg[1,2,3] are + filled with a symbol""" + for index in combo: + if state["board"][index] != symbol: + return False + return True \ No newline at end of file