I changed the check_winner method in game.py

(Checkpoint 2)
What I changed
I changed the method so that it would accurately determine if the player with the symbol passed through the
parameter won. It does this by checking each possible way to win tic tac toe.

Why I changed it
I made the change so that the game could accurately determine which player won the game.

Estimate for remaining time to finish assignment: [1 to 2 hours]
This commit is contained in:
Thomas Naber
2024-02-25 20:15:23 -05:00
parent 67a041b903
commit 0dbc59d637
2 changed files with 25 additions and 2 deletions

View File

@@ -58,4 +58,23 @@ class TTTGame:
def check_winner(self, state, symbol):
"Checks whether the player with `symbol` has won the game."
return False
if state["board"][0]==symbol and state["board"][1]==symbol and state["board"][2]==symbol:
return True
elif state["board"][3]==symbol and state["board"][4]==symbol and state["board"][5]==symbol:
return True
elif state["board"][6]==symbol and state["board"][7]==symbol and state["board"][8]==symbol:
return True
elif state["board"][0]==symbol and state["board"][3]==symbol and state["board"][6]==symbol:
return True
elif state["board"][1]==symbol and state["board"][4]==symbol and state["board"][7]==symbol:
return True
elif state["board"][2]==symbol and state["board"][5]==symbol and state["board"][8]==symbol:
return True
elif state["board"][0]==symbol and state["board"][4]==symbol and state["board"][8]==symbol:
return True
elif state["board"][2]==symbol and state["board"][4]==symbol and state["board"][6]==symbol:
return True
else:
return False