I just used the coordiantes of the grid to check all possible winning combinations.

This commit is contained in:
cdonahue
2025-11-17 09:32:53 -05:00
parent b58d15aa4a
commit 08b52bb799
3 changed files with 15 additions and 2 deletions

View File

@@ -58,4 +58,14 @@ class TTTGame:
def check_winner(self, state, symbol):
"Checks whether the player with `symbol` has won the game."
board = state["board"]
# All winning triplets (rows, columns, diagonals)
winning_combinations = [
(0, 1, 2), (3, 4, 5), (6, 7, 8), # rows
(0, 3, 6), (1, 4, 7), (2, 5, 8), # columns
(0, 4, 8), (2, 4, 6), # diagonals
]
for i, j, k in winning_combinations:
if board[i] == board[j] == board[k] == symbol:
return True
return False