generated from mwc/lab_tic_tac_toe
Checkpoint 2: List all the possible cases for winning first.
Then I thought of for loop, and realized that the work will be much longer than I wished while making a note on the paper. Index would be more ideal to check each combination with a shorter code.
This commit is contained in:
parent
2d43238040
commit
740872f7b6
|
@ -58,4 +58,9 @@ class TTTGame:
|
|||
|
||||
def check_winner(self, state, symbol):
|
||||
"Checks whether the player with `symbol` has won the game."
|
||||
winning_combinations=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
|
||||
board=state["board"]
|
||||
combination=[index for index in range(9) if board[index]==symbol]
|
||||
if combination in winning_combinations:
|
||||
return True
|
||||
return False
|
||||
|
|
Loading…
Reference in New Issue