checkpoint 2

I listed all the possible winning patterns for tic tac toe including
the rows, columns, and diagonals. then the code goes through each pattern to check
and see if they all have the same symbol. whatever the first position is, it
checks to see if the second position is the same and then the third.
If all 3 are the same symbol then we have true and if not then false.
This commit is contained in:
Lauren Dawnkaski
2024-11-30 15:53:01 -05:00
parent 93ff929a44
commit 8aac402bb7

View File

@@ -58,4 +58,8 @@ class TTTGame:
def check_winner(self, state, symbol):
"Checks whether the player with `symbol` has won the game."
pattern_to_win = [[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 pattern in pattern_to_win:
if state["board"][pattern[0]]==symbol and state["board"][pattern[1]]==symbol and state["board"][pattern[2]]==symbol:
return True
return False