Created
September 14, 2021 12:31
-
-
Save safhac/66636d6b44eb9549a386bc0a2726ce47 to your computer and use it in GitHub Desktop.
my ttt solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def is_solved(board): | |
grid = np.array(board) | |
row0 = grid[0] | |
row1 = grid[1] | |
row2 = grid[2] | |
col0 = grid[:, 0] | |
col1 = grid[:, 1] | |
col2 = grid[:, 2] | |
diag0 = np.einsum('ii->i', grid) | |
diag1 = np.einsum('ii->i', np.flip(grid)) | |
possibilities = [row0, row1, row2, col0, col1, col2, diag0, diag1] | |
for vect in possibilities: | |
if np.all(vect == vect[0]): | |
return vect[0] if vect[0] else -1 | |
return 0 if np.all(grid) else -1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment