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.
This commit is contained in:
Seoyeon Lee 2024-12-15 00:54:20 -05:00
parent 2d43238040
commit 740872f7b6
1 changed files with 5 additions and 0 deletions

View File

@ -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