checkpoint 2:I scanned the board to find if there were three of the same symbols in a row, column, or diagonal.

This commit is contained in:
jbayati
2025-11-17 09:31:28 -05:00
parent eb65c5e692
commit 723a00b12f

View File

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