generated from mwc/lab_tic_tac_toe
checkpoint 2:I scanned the board to find if there were three of the same symbols in a row, column, or diagonal.
This commit is contained in:
11
ttt/game.py
11
ttt/game.py
@@ -58,4 +58,15 @@ class TTTGame:
|
||||
|
||||
def check_winner(self, state, symbol):
|
||||
"Checks whether the player with `symbol` has won the game."
|
||||
b = state["board"]
|
||||
for r in range(3):
|
||||
if b[3*r] == symbol and b[3*r+1] == symbol and b[3*r+2] == symbol:
|
||||
return True
|
||||
for c in range(3):
|
||||
if b[c] == symbol and b[c+3] == symbol and b[c+6] == 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
|
||||
|
||||
Reference in New Issue
Block a user