Jimtuv

Tic Tac Toe test

Feb 18th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. def tictactoe(moves):
  2.    
  3.    
  4.     for i in range(3):      
  5.         if moves[i][0] == 'X' and moves[i][1] == 'X' and moves[i][2] == 'X':
  6.             return "'X' wins (horizontal)."
  7.         if moves[0][i] == 'X' and moves[1][i] == 'X' and moves[2][i] == 'X':
  8.             return "'X' wins (vertical)."
  9.         if moves[i][0] == 'O' and moves[i][1] == 'O' and moves[i][2] == 'O':
  10.             return "'Y' wins (horizontal)."
  11.         if moves[0][i] == 'O' and moves[1][i] == 'O' and moves[2][i] == 'O':
  12.             return "'O' wins (vertical)."
  13.            
  14.     if moves[0][0] == 'X' and moves[1][1] == 'X' and moves[2][2] == 'X':
  15.         return "'X' wins (diagonal)."
  16.     if moves[0][2] == 'X' and moves[1][1] == 'X' and moves[2][0] == 'X':
  17.         return "'X' wins (diagonal)."
  18.        
  19.     if moves[0][0] == 'O' and moves[1][1] == 'O' and moves[2][2] == 'O':
  20.         return "'O' wins (diagonal)."
  21.     if moves[0][2] == 'O' and moves[1][1] == 'O' and moves[2][0] == 'O':
  22.         return "'O' wins (diagonal)."
  23.     isempty = 0
  24.    
  25.     for row in range(3):
  26.         for item in range(3):
  27.             if moves[row][item] == ' ':
  28.                 isempty = isempty + 1
  29.      
  30.     print isempty          
  31.     if isempty == 0:
  32.         return 'Draw.'
  33.                    
  34.     return  ''
Advertisement
Add Comment
Please, Sign In to add comment