Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- ######import random#####
- import sys
- sys.path.append("C:\Program Files (x86)\IronPython 2.7\Lib")
- import random
- OUT = random.random()
- ######import random#####
- #case du jeu
- case = ['0', '1', '2', '3', '4', '5', '6', '7', '8']
- def affiche():
- print(case[0], '|', case[1], '|', case[2])
- print('----------')
- print(case[3], "|", case[4], "|", case[5])
- print('----------')
- print(case[6], "|", case[7], "|", case[8])
- def testLigne(char, position1, position2, position3):
- if case[position1] == char and case[position2] == char and case[
- position3] == char:
- return True
- def testGanant(char):
- #test vertical
- if testLigne(char, 0, 1, 2):
- return True
- if testLigne(char, 3, 4, 5):
- return True
- if testLigne(char, 6, 7, 8):
- return True
- #test horizontale
- if testLigne(char, 0, 3, 6):
- return True
- if testLigne(char, 1, 4, 7):
- return True
- if testLigne(char, 2, 5, 8):
- return True
- #test diagonales
- if testLigne(char, 0, 4, 8):
- return True
- if testLigne(char, 2, 4, 6):
- return True
- affiche()
- while True:
- case_choisie = int(input("Choisissez une case : "))
- if case[case_choisie] != 'x' and case[case_choisie] != 'o':
- case[case_choisie] = 'x'
- #Test Si X à gagner
- if testGanant('x') == True:
- print("---X A GAGNER---")
- affiche()
- break
- case_trouver = True
- while case_trouver: #l'ordinateur joue
- random.seed() #Donne un generateur aléatoire
- opponent = random.randint(0, 8)
- if case[opponent] != 'x' and case[opponent] != 'x':
- case[opponent] = 'o'
- case_trouver = False
- if testGanant('o') == True:
- print("---O A GAGNER---")
- affiche()
- break
- else:
- print('Cette case est déjà prise')
- affiche()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement