Advertisement
tanmoklepasha

tic-tac-toe_prevencia

Jun 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. a = {'1':'1','2':'2','3':'3','4':'4','5':'5',
  2.     '6':'6','7':'7','8':'8','9':'9'}
  3.  
  4. mogeba = (('1','2','3'),('2','5','8'),
  5.           ('4','5','6'),('7','8','9'),
  6.           ('1','4','7'),('3','6','9'),
  7.           ('1','5','9'),('3','5','7'))
  8.  
  9.  
  10.  
  11. def cxrili():
  12.     print('-------------')
  13.     print('|',a['1'],'|',a['2'],'|',a['3'],'|')
  14.     print('-------------')
  15.     print('|',a['4'],'|',a['5'],'|',a['6'],'|')
  16.     print('-------------')
  17.     print('|',a['7'],'|',a['8'],'|',a['9'],'|')
  18.     print('-------------')
  19.  
  20. def in_x(a):
  21.     x = input('x-is svlaa :')
  22.     a[x] = 'x'
  23.  
  24. def in_o(a):
  25.     x = input('o-is svlaa :')
  26.     a[x]= 'o'
  27.  
  28. def win():
  29.     for i in mogeba:
  30.         count_x = 0
  31.         count_o = 0
  32.         for j in i:
  33.             if 'x' == a[j]:
  34.                 count_x+=1
  35.                 if count_x == 3:
  36.                     return 'win x'
  37.             elif 'o' == a[j]:
  38.                 count_o+=1
  39.                 if count_o == 3:
  40.                     return 'win o'
  41.     return ""
  42.  
  43.  
  44. i = 1
  45. while i <=5:
  46.     cxrili()
  47.     in_x(a)
  48.     win_x = win()
  49.     if win_x :
  50.         print(win_x)
  51.         break
  52.  
  53.     if i==5:
  54.         cxrili()
  55.         print('nichiaaa')
  56.         break
  57.  
  58.     cxrili()
  59.     in_o(a)
  60.     win_o = win()
  61.     if win_o :
  62.         print(win_o)
  63.         break
  64.  
  65.  
  66.     i+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement