generated from mwc/lab_tic_tac_toe
completed checkpoint 2
What I changed I added the logic to check if someone won the game. Why I changed it The goal was to make it so the code could tell if a there was a winner at each point in the game. I figured the easiest way I could implement this accessing the list then using if statements. Estimate for remaining time to finish assignment: 1 hour
This commit is contained in:
parent
bf04a4ba8a
commit
ca1c558686
17
ttt/game.py
17
ttt/game.py
|
@ -58,4 +58,21 @@ class TTTGame:
|
|||
|
||||
def check_winner(self, state, symbol):
|
||||
"Checks whether the player with `symbol` has won the game."
|
||||
b=state['board']
|
||||
if b[0]==symbol and b[3]==symbol and b[6]==symbol:
|
||||
return True
|
||||
if b[1]==symbol and b[4]==symbol and b[7]==symbol:
|
||||
return True
|
||||
if b[2]==symbol and b[5]==symbol and b[8]==symbol:
|
||||
return True
|
||||
if b[0]==symbol and b[1]==symbol and b[2]==symbol:
|
||||
return True
|
||||
if b[3]==symbol and b[4]==symbol and b[5]==symbol:
|
||||
return True
|
||||
if b[6]==symbol and b[7]==symbol and b[8]==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
|
||||
|
|
Loading…
Reference in New Issue