Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. import numpy as np
  2.  
  3. # %%
  4. n1 = np.array([0,1,1])
  5. n2 = np.array([0,1,0])
  6. n3 = np.array([1,0,1])
  7. n_diag_descending = np.diagonal([n1,n2,n3])
  8. n_diag_ascending = np.diagonal(np.fliplr([n1,n2,n3]))
  9.  
  10. # %% Vertical sum
  11. vs = np.sum([n1,n2,n3], axis=0)
  12.  
  13. # %% Horizontal sum
  14. hs = np.sum([n1,n2,n3], axis=1)
  15.  
  16. # %% Diagonal sum descending
  17. dsd = np.sum([n_diag_descending])
  18.  
  19. # %% Diagonal sum ascending
  20. dsa = np.sum([n_diag_ascending])
  21.  
  22. # %%
  23. def winner(*args):
  24.     vals = np.concatenate((args))
  25.     print(vals)
  26.  
  27.     if 3 in vals:
  28.         print('Player 1 win')
  29.     elif 0 in vals:
  30.         print('Player 0 win')
  31.     else:
  32.         print('No one won this round')
  33.    
  34. winner(hs, vs, [dsd], [dsa])
  35.  
  36. # %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement