overactive

gra_o_x

Jun 7th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. '''kółko i krzyżyk'''
  2. def theGame():
  3. #coord = {1:'l', 2:'', 3:'', 4:'', 5:'', 6:'', 7:'', 8:'', 9:''}
  4. coord = ['', '', '', '', '', '', '', '', '']
  5. done = False
  6.  
  7. #(('0 0', '1 0', '2 0'), ('0 1' , '1 1' , '2 1'), ('0 2', '1 2', '2 2'), ('0 0', '0 1', '0 2'), ('1 0', '1 1', '1 2'), ('2 0', '2 1', '2 2'), ('0 2', '2 2', '2 0'), ('0 0', '1 1', '2 2'))
  8.  
  9. def printGame():
  10. print('{:4}{:^3}{}{:^3}{}{:^3}{}'.format('',0,'|',1,'|',2,'|'))
  11. print('{:>2d}{}{:^3}{}{:^3}{}{:^3}{}'.format(0,' |',coord[0],'|',coord[1],'|',coord[2],'|'))
  12. print('{:>2d}{}{:^3}{}{:^3}{}{:^3}{}'.format(1,' |',coord[3],'|',coord[4],'|',coord[5],'|'))
  13. print('{:>2d}{}{:^3}{}{:^3}{}{:^3}{}'.format(2,' |',coord[6],'|',coord[7],'|',coord[8],'|'))
  14.  
  15. def inputCoords():
  16. s = input()
  17. if s == '0 0': s = 0
  18. if s == '1 0': s = 1
  19. if s == '2 0': s = 2
  20. if s == '0 1': s = 3
  21. if s == '1 1': s = 4
  22. if s == '2 1': s = 5
  23. if s == '0 2': s = 6
  24. if s == '1 2': s = 7
  25. if s == '2 2': s = 8
  26. return s
  27.  
  28. def moveX():
  29. print('\nX move:')
  30. x = inputCoords()
  31.  
  32. if coord[x] == 'X' or coord[x] == 'O':
  33. print('\nAlready taken. Choose again.')
  34. moveX()
  35. else:
  36. coord[x] = 'X'
  37.  
  38. def moveO():
  39. print('\nO move:')
  40. o = inputCoords()
  41.  
  42. if coord[o] == 'X' or coord[o] == 'O':
  43. print('\nAlready taken. Choose again.')
  44. moveO()
  45. else:
  46. coord[o] = 'O'
  47.  
  48.  
  49.  
  50. def gameStatus():
  51. count = 0
  52. winCoord = ((0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6), (1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6))
  53.  
  54. for i in winCoord:
  55. if coord[i[0]] == 'X':
  56. if coord[i[1]] == 'X':
  57. if coord[i[2]] == 'X':
  58. print('X Wins!\n')
  59. done = True
  60. return done
  61.  
  62. if coord[i[0]] == 'O':
  63. if coord[i[1]] == 'O':
  64. if coord[i[2]] == 'O':
  65. print('O Wins!\n')
  66. done = True
  67. return done
  68.  
  69. if coord.count('X')+coord.count('O') == 9:
  70. done = True
  71. return done
  72.  
  73.  
  74.  
  75. while not done :
  76.  
  77. printGame()
  78.  
  79. done = gameStatus()
  80. if done == True:
  81. break
  82.  
  83. moveX()
  84. printGame()
  85.  
  86. done = gameStatus()
  87. if done == True:
  88. break
  89.  
  90. moveO()
  91. theGame()
Advertisement
Add Comment
Please, Sign In to add comment