generated from mwc/lab_tic_tac_toe
Fixed TTTGame.check_winner.
What I changed Added 8 cases to check for to see if someone won: three rows, three columns and two diagonals. Why I changed it TTTGame.check_winner always reported false, so the game only ended when the board was full even if someone should have won. Estimate for remaining time to finish assignment: [Like a few hours assuming my students don't rip a door off its hinges in the bathroom again...]
This commit is contained in:
16
ttt/game.py
16
ttt/game.py
@@ -58,4 +58,20 @@ class TTTGame:
|
||||
|
||||
def check_winner(self, state, symbol):
|
||||
"Checks whether the player with `symbol` has won the game."
|
||||
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
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user