SHARE
TWEET

Untitled

a guest Nov 19th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class xo:
  2.     N = 1
  3.     doska = [[" "," "," "],[" "," "," "],[" "," "," "]]
  4.     def proverka(self,X,Y):
  5.         if (X == 1 and Y == 1 and (self.doska[0][0] == "X" or self.doska[0][0] == "O")) or (X == 1 and Y == 2 and (self.doska[1][0] == "X" or self.doska[1][0] == "O")) or (X == 1 and Y == 3 and (self.doska[2][0] == "X" or self.doska[2][0] == "O")) or (X == 2 and Y == 1 and (self.doska[0][1] == "X" or self.doska[0][1] == "O")) or (X == 2 and Y == 2 and (self.doska[1][1] == "X" or self.doska[1][1] == "O")) or (X == 2 and Y == 3 and (self.doska[2][1] == "X" or self.doska[2][1] == "O")) or (X == 3 and Y == 1 and (self.doska[2][0] == "X" or self.doska[2][0] == "O")) or (X == 3 and Y == 2 and (self.doska[1][2] == "X" or self.doska[1][2] == "O")) or (X == 3 and Y == 3 and (self.doska[2][2] == "X" or self.doska[2][2] == "O")):
  6.             print("Эта ячейка занята...")
  7.             print("Попробуйте снова")
  8.             print()
  9.             self.N -= 1
  10.             pass
  11.         else:
  12.             pass
  13.  
  14.     def hod(self):
  15.             X = int(input('Введите Х (1-3): '))
  16.             Y = int(input('Введите Y (1-3): '))
  17.             print()
  18.             self.proverka(X,Y)
  19.             if self.N%2 == 0:
  20.                 self.doska[Y-1][X-1]="O"
  21.             else:
  22.                 self.doska[Y-1][X-1]="X"
  23.            
  24.     def view(self):
  25.         print('ВАША ДОСКА:')
  26.         i = 0
  27.         for i in range(3):
  28.             print("|=====|=====|=====|")
  29.             print("| ",self.doska[i][0]," | ",self.doska[i][1]," | ",self.doska[i][2]," |")
  30.             i+=1
  31.         print("|=====|=====|=====|")
  32.         print()
  33.         return ""
  34.    
  35.     def __init__(self,a=[[" "," "," "],[" "," "," "],[" "," "," "]]):
  36.         self.doska=a
  37.        
  38.     def calcendgame(self):
  39.         if (self.doska[0][0] == "X" and self.doska[0][1] == "X" and self.doska[0][2] == "X") or (self.doska[1][0] == "X" and self.doska[1][1] == "X" and self.doska[1][2] == "X") or (self.doska[2][0] == "X" and self.doska[2][1] == "X" and self.doska[2][2] == "X") or (self.doska[0][0] == "X" and self.doska[1][1] == "X" and self.doska[2][2] == "X") or (self.doska[0][0] == "X" and self.doska[1][0] == "X" and self.doska[2][0] == "X") or (self.doska[0][1] == "X" and self.doska[1][1] == "X" and self.doska[2][1] == "X") or (self.doska[0][2] == "X" and self.doska[1][2] == "X" and self.doska[2][2] == "X") or (self.doska[2][0] == "X" and self.doska[1][1] == "X" and self.doska[0][2] == "X"):
  40.             print()
  41.             print('КРЕСТИКИ ВЫИГРАЛИ!')
  42.             self.view()
  43.             return 1
  44.         elif (self.doska[0][0] == "O" and self.doska[0][1] == "O" and self.doska[0][2] == "O") or (self.doska[1][0] == "O" and self.doska[1][1] == "O" and self.doska[1][2] == "O") or (self.doska[2][0] == "O" and self.doska[2][1] == "O" and self.doska[2][2] == "O") or (self.doska[0][0] == "O" and self.doska[1][1] == "O" and self.doska[2][2] == "O") or (self.doska[0][0] == "O" and self.doska[1][0] == "O" and self.doska[2][0] == "O") or (self.doska[0][1] == "O" and self.doska[1][1] == "O" and self.doska[2][1] == "O") or (self.doska[0][2] == "O" and self.doska[1][2] == "O" and self.doska[2][2] == "O") or (self.doska[2][0] == "O" and self.doska[1][1] == "O" and self.doska[0][2] == "O"):
  45.             print()
  46.             print('НОЛИКИ ВЫИГРАЛИ!')
  47.             self.view()
  48.             return 1
  49.         elif (self.doska[0][0] == "X" or self.doska[0][0] == "O") and (self.doska[1][0] == "X" or self.doska[1][0] == "O") and (self.doska[2][0] == "X" or self.doska[2][0] == "O") and (self.doska[0][1] == "X" or self.doska[0][1] == "O") and (self.doska[1][1] == "X" or self.doska[1][1] == "O") and (self.doska[2][1] == "X" or self.doska[2][1] == "O") and (self.doska[2][0] == "X" or self.doska[2][0] == "O") and (self.doska[1][2] == "X" or self.doska[1][2] == "O") and (self.doska[2][2] == "X" or self.doska[2][2] == "O"):
  50.             print()
  51.             print('НИЧЬЯ!')
  52.             self.view()
  53.             return 1
  54.         else:
  55.             return 0
  56.        
  57.     def game(self):
  58.             while (self.calcendgame()==0):
  59.                 self.view()
  60.                 self.hod()
  61.                 self.N += 1
  62.  
  63. a = xo()
  64. print(a.game())
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top