Advertisement
xdrasz

tictactoe w/ winner

Jun 9th, 2022
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.18 KB | None | 0 0
  1. x1=1
  2. x2=2
  3. x3=3
  4. x4=4
  5. x5=5
  6. x6=6
  7. x7=7
  8. x8=8
  9. x9=9
  10. x="X"
  11. o="O"
  12. a=0
  13. oturn="O's turn"
  14. xturn="X's turn"
  15. print(" press any letter to end the program")
  16. print(" ")
  17. print(" ")
  18. print(" ")
  19. print(" press a number from the grid to play")
  20. print(" ")
  21. print(" ")
  22. print(" ")
  23. while a < 9:
  24.     print(x1,"|",x2,"|",x3,"    ",oturn)
  25.     print("---------")
  26.     print(x4,"|",x5,"|",x6)
  27.     print("---------")
  28.     print(x7,"|",x8,"|",x9)
  29.     y = int(input())
  30.     if y == x1:x1=o
  31.     if y==x2:x2=o
  32.     if y==x3:x3=o
  33.     if y==x4:x4=o
  34.     if y==x5:x5=o
  35.     if y==x6:x6=o
  36.     if y==x7:x7=o
  37.     if y==x8:x8=o
  38.     if y==x9:x9=o
  39.     if x1==x2 and x2 ==x3 :
  40.             print(x1,"|",x2,"|",x3)
  41.             print("---------")
  42.             print(x4,"|",x5,"|",x6)
  43.             print("---------")
  44.             print(x7,"|",x8,"|",x9)
  45.             print("gg player",x3)
  46.             a=9
  47.     elif x4==x5 and x5==x6 :
  48.             print(x1,"|",x2,"|",x3)
  49.             print("---------")
  50.             print(x4,"|",x5,"|",x6)
  51.             print("---------")
  52.             print(x7,"|",x8,"|",x9)
  53.             print("gg player",x6)
  54.             a=9
  55.     elif x7==x8 and x8 ==x9 :
  56.             print(x1,"|",x2,"|",x3,"   ",xturn)
  57.             print("---------")
  58.             print(x4,"|",x5,"|",x6)
  59.             print("---------")
  60.             print(x7,"|",x8,"|",x9)
  61.             print("gg player",x9)
  62.             a=9
  63.     elif x1==x4 and x4 ==x7 :
  64.             print(x1,"|",x2,"|",x3)
  65.             print("---------")
  66.             print(x4,"|",x5,"|",x6)
  67.             print("---------")
  68.             print(x7,"|",x8,"|",x9)
  69.             print("gg player",x7)
  70.             a=9
  71.     elif x2==x5 and x5 ==x8 :
  72.             print(x1,"|",x2,"|",x3)
  73.             print("---------")
  74.             print(x4,"|",x5,"|",x6)
  75.             print("---------")
  76.             print(x7,"|",x8,"|",x9)
  77.             print("gg player",x8)
  78.             a=9
  79.     elif x3==x6 and x6==x9 :
  80.             print(x1,"|",x2,"|",x3)
  81.             print("---------")
  82.             print(x4,"|",x5,"|",x6)
  83.             print("---------")
  84.             print(x7,"|",x8,"|",x9)
  85.             print("gg player",x9)
  86.             a=9
  87.     elif x3==x5 and x5 ==x7 :
  88.             print(x1,"|",x2,"|",x3)
  89.             print("---------")
  90.             print(x4,"|",x5,"|",x6)
  91.             print("---------")
  92.             print(x7,"|",x8,"|",x9)
  93.             print("gg player",x7)
  94.             a=9
  95.     elif x1==x5 and x5 ==x9 :
  96.             print(x1,"|",x2,"|",x3)
  97.             print("---------")
  98.             print(x4,"|",x5,"|",x6)
  99.             print("---------")
  100.             print(x7,"|",x8,"|",x9)
  101.             print("gg player",x9)
  102.             a=9
  103.     else :
  104.         a=a+1
  105.         if a<9:
  106.             print(x1,"|",x2,"|",x3,"   ",xturn)
  107.             print("---------")
  108.             print(x4,"|",x5,"|",x6)
  109.             print("---------")
  110.             print(x7,"|",x8,"|",x9)
  111.             c = int(input())
  112.         if c == x1:x1=x
  113.         if c==x2:x2=x
  114.         if c==x3:x3=x
  115.         if c==x4:x4=x
  116.         if c==x5:x5=x
  117.         if c==x6:x6=x
  118.         if c==x7:x7=x
  119.         if c==x8:x8=x
  120.         if c==x9:x9=x
  121.         if x1==x2 and x2 ==x3 :
  122.             print(x1,"|",x2,"|",x3)
  123.             print("---------")
  124.             print(x4,"|",x5,"|",x6)
  125.             print("---------")
  126.             print(x7,"|",x8,"|",x9)
  127.             print("gg player",x3)
  128.             a=9
  129.         elif x4==x5 and x5==x6 :
  130.             print(x1,"|",x2,"|",x3)
  131.             print("---------")
  132.             print(x4,"|",x5,"|",x6)
  133.             print("---------")
  134.             print(x7,"|",x8,"|",x9)
  135.             print("gg player",x6)
  136.             a=9
  137.         elif x7==x8 and x8 ==x9 :
  138.             print(x1,"|",x2,"|",x3)
  139.             print("---------")
  140.             print(x4,"|",x5,"|",x6)
  141.             print("---------")
  142.             print(x7,"|",x8,"|",x9)
  143.             print("gg player",x9)
  144.             a=9
  145.         elif x1==x4 and x4 ==x7 :
  146.             print(x1,"|",x2,"|",x3)
  147.             print("---------")
  148.             print(x4,"|",x5,"|",x6)
  149.             print("---------")
  150.             print(x7,"|",x8,"|",x9)
  151.             print("gg player",x7)
  152.             a=9
  153.         elif x2==x5 and x5 ==x8 :
  154.             print(x1,"|",x2,"|",x3)
  155.             print("---------")
  156.             print(x4,"|",x5,"|",x6)
  157.             print("---------")
  158.             print(x7,"|",x8,"|",x9)
  159.             print("gg player",x8)
  160.             a=9
  161.         elif x3==x6 and x6==x9 :
  162.             print(x1,"|",x2,"|",x3)
  163.             print("---------")
  164.             print(x4,"|",x5,"|",x6)
  165.             print("---------")
  166.             print(x7,"|",x8,"|",x9)
  167.             print("gg player",x9)
  168.             a=9
  169.         elif x3==x5 and x5 ==x7 :
  170.             print(x1,"|",x2,"|",x3)
  171.             print("---------")
  172.             print(x4,"|",x5,"|",x6)
  173.             print("---------")
  174.             print(x7,"|",x8,"|",x9)
  175.             print("gg player",x7)
  176.             a=9
  177.         elif x1==x5 and x5 ==x9 :
  178.             print(x1,"|",x2,"|",x3)
  179.             print("---------")
  180.             print(x4,"|",x5,"|",x6)
  181.             print("---------")
  182.             print(x7,"|",x8,"|",x9)
  183.             print("gg player",x9)
  184.             a=9
  185.         else :
  186.             a=a+1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement