SHARE
TWEET

Tic Tac Toe Check Winner

a guest May 22nd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def check_horizontal(list_of_list):
  2.     for i in range(len(list_of_list)):
  3.         if(list_of_list[i].count(1) == len(list_of_list)):
  4.             return("Player 1 is the winner - Horizontal")
  5.         elif(list_of_list[i].count(2) == len(list_of_list)):
  6.             return("Player 2 is the winner - Horzontal")
  7.        
  8. def check_vertical(list_of_list):
  9.     for i in range(len(list_of_list)):
  10.         store_vals = []
  11.         for j in range(len(list_of_list)):
  12.             store_vals.append(list_of_list[j][i])
  13.             if(len(store_vals) == len(list_of_list)):
  14.                 if(store_vals.count(1) == len(list_of_list)):
  15.                     return("Player 1 is the winner - Vertical")
  16.                 elif(store_vals.count(2) == len(list_of_list)):
  17.                     return("Player 2 is the winner - Vertical")
  18.                
  19. def check_diagnoal(list_of_list):
  20.     diag1 = []
  21.     diag2 = []
  22.     for i in range(len(list_of_list)):
  23.         diag1.append(list_of_list[2-i][i])
  24.         diag2.append(list_of_list[i][i])
  25.        
  26.         if(len(diag1) == len(list_of_list)):
  27.             if(diag1.count(1) == len(list_of_list) or diag2.count(1) == len(list_of_list)):
  28.                 return("Player 1 is the winner - diag")
  29.             if(diag1.count(2) == len(list_of_list) or diag2.count(2) == len(list_of_list)):
  30.                 return("Player 2 is the winner - diag")
  31.  
  32. def check_win(list_of_list):
  33.     print(check_horizontal(list_of_list))
  34.     print(check_vertical(list_of_list))
  35.     print(check_diagnoal(list_of_list))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top