Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. ######import random#####
  5. import sys
  6. sys.path.append("C:\Program Files (x86)\IronPython 2.7\Lib")
  7.  
  8. import random
  9.  
  10. OUT = random.random()
  11. ######import random#####
  12.  
  13. #case du jeu
  14.  
  15. case = ['0', '1', '2', '3', '4', '5', '6', '7', '8']
  16.  
  17.  
  18. def affiche():
  19. print(case[0], '|', case[1], '|', case[2])
  20. print('----------')
  21. print(case[3], "|", case[4], "|", case[5])
  22. print('----------')
  23. print(case[6], "|", case[7], "|", case[8])
  24.  
  25.  
  26. def testLigne(char, position1, position2, position3):
  27. if case[position1] == char and case[position2] == char and case[
  28. position3] == char:
  29. return True
  30.  
  31.  
  32. def testGanant(char):
  33.  
  34. #test vertical
  35. if testLigne(char, 0, 1, 2):
  36. return True
  37. if testLigne(char, 3, 4, 5):
  38. return True
  39. if testLigne(char, 6, 7, 8):
  40. return True
  41.  
  42. #test horizontale
  43. if testLigne(char, 0, 3, 6):
  44. return True
  45. if testLigne(char, 1, 4, 7):
  46. return True
  47. if testLigne(char, 2, 5, 8):
  48. return True
  49.  
  50. #test diagonales
  51. if testLigne(char, 0, 4, 8):
  52. return True
  53. if testLigne(char, 2, 4, 6):
  54. return True
  55.  
  56.  
  57. affiche()
  58.  
  59. while True:
  60.  
  61. case_choisie = int(input("Choisissez une case : "))
  62.  
  63. if case[case_choisie] != 'x' and case[case_choisie] != 'o':
  64. case[case_choisie] = 'x'
  65.  
  66. #Test Si X à gagner
  67. if testGanant('x') == True:
  68. print("---X A GAGNER---")
  69. affiche()
  70. break
  71.  
  72. case_trouver = True
  73.  
  74. while case_trouver: #l'ordinateur joue
  75. random.seed() #Donne un generateur aléatoire
  76. opponent = random.randint(0, 8)
  77.  
  78. if case[opponent] != 'x' and case[opponent] != 'x':
  79. case[opponent] = 'o'
  80. case_trouver = False
  81.  
  82. if testGanant('o') == True:
  83. print("---O A GAGNER---")
  84. affiche()
  85. break
  86.  
  87. else:
  88. print('Cette case est déjà prise')
  89. affiche()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement