From 740872f7b6de59cbf6a75419e5623d636d4a7271 Mon Sep 17 00:00:00 2001 From: Seoyeon Lee Date: Sun, 15 Dec 2024 00:54:20 -0500 Subject: [PATCH] Checkpoint 2: List all the possible cases for winning first. Then I thought of for loop, and realized that the work will be much longer than I wished while making a note on the paper. Index would be more ideal to check each combination with a shorter code. --- ttt/game.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ttt/game.py b/ttt/game.py index 2f0e302..0d7149a 100644 --- a/ttt/game.py +++ b/ttt/game.py @@ -58,4 +58,9 @@ class TTTGame: def check_winner(self, state, symbol): "Checks whether the player with `symbol` has won the game." + winning_combinations=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]] + board=state["board"] + combination=[index for index in range(9) if board[index]==symbol] + if combination in winning_combinations: + return True return False