generated from mwc/lab_tic_tac_toe
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:
21
ttt/game.py
21
ttt/game.py
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user