# Type your text here import random import time def affiche(liste) : for u in range(3) : tout = "" for i in range(3) : v = liste[i][2-u] if v == None : v = " " tout += "|"+v+"|" print(tout) print("---------") def jeu() : print("Bonjour dans mon programme du morpion Le joueur 1 est O est le joueur 2 est X") print("") z=0 liste = [[None,None,None],[None,None,None],[None,None,None]] liste2 = [] listetout = [] affiche(liste) tour = 0 boucle = 0 while tour != 9: listecl = [] boucle = 0 if tour%2 == 0 : while boucle == 0 : print("") ligne = int(input("Joueur 1 choisit ta ligne : ")) colone = int(input("Joueur 1 choisit ta colone : ")) print("") listecl = [colone,ligne] if listecl in listetout : print("Cette case est déja prise") else : boucle = 1 listetout.append(listecl) for i in range(100) : print("") liste[colone][ligne] = "O" else : while boucle == 0 : ligne = int(input("Joueur 2 choisit ta ligne : ")) colone = int(input("Joueur 2 choisit ta colone : ")) print("") listecl = [colone,ligne] if listecl in listetout : print("Cette case est déja prise") else : boucle = 1 listetout.append(listecl) for i in range(100) : print("") liste[colone][ligne] = "X" affiche(liste) print("") print("") g = vaincqueur(liste) tour += 1 if g == "j1" : return "Le joueur 1 est le vaincqueur " elif g == "j2" : return "Le joueur 2 est le vaincqueur " if tour == 9 : return "Il y a égalité " else : pass print("") print("Il y a égalité ") def vaincqueur(liste) : j1 = 0 j2 = 0 if liste[0][0] == "O" and liste[0][1] == "O" and liste[0][2] == "O" : j1 = True elif liste[1][0] == "O" and liste[1][1] == "O" and liste[1][2] == "O" : j1 = True elif liste[2][0] == "O" and liste[2][1] == "O" and liste[2][2] == "O" : j1 = True elif liste[0][0] == "O" and liste[1][0] == "O" and liste[2][0] == "O" : j1 = True elif liste[0][1] == "O" and liste[1][1] == "O" and liste[2][1] == "O" : j1 = True elif liste[0][2] == "O" and liste[1][2] == "O" and liste[2][2] == "O" : j1 = True elif liste[0][0] == "O" and liste[1][1] == "O" and liste[2][2] == "O" : j1 = True elif liste[2][0] == "O" and liste[1][1] == "O" and liste[0][2] == "O" : j1 = True elif liste[0][0] == "X" and liste[0][1] == "X" and liste[0][2] == "X" : j2 = True elif liste[1][0] == "X" and liste[1][1] == "X" and liste[1][2] == "X" : j2 = True elif liste[2][0] == "X" and liste[2][1] == "X" and liste[2][2] == "X" : j2 = True elif liste[0][0] == "X" and liste[1][0] == "X" and liste[2][0] == "X" : j2 = True elif liste[0][1] == "X" and liste[1][1] == "X" and liste[2][1] == "X" : j2 = True elif liste[0][2] == "X" and liste[1][2] == "X" and liste[2][2] == "X" : j2 = True elif liste[0][0] == "X" and liste[1][1] == "O" and liste[2][2] == "X" : j2 = True elif liste[2][0] == "X" and liste[1][1] == "X" and liste[0][2] == "X" : j2 = True if j1 == True : return "j1" elif j2 == True : return "j2" else : return None def jeu_IA() : print("Bonjour dans mon programme du morpion ") print("") z=0 liste = [[None,None,None],[None,None,None],[None,None,None]] liste2 = [] listetout = [] affiche(liste) tour = 0 boucle = 0 while tour != 9: listecl = [] boucle = 0 if tour%2 == 0 : while boucle == 0 : print("") ligne = int(input("Choisit ta ligne : ")) colone = int(input("Choisit ta colone : ")) print("") listecl = [colone,ligne] if listecl in listetout : print("Cette case est déja prise") else : boucle = 1 listetout.append(listecl) for i in range(100) : print("") liste[colone][ligne] = "O" else : while boucle == 0 : print("") ligne = random.randint(0,2) colone = random.randint(0,2) listecl = [colone,ligne] if listecl in listetout : pass else : boucle = 1 listetout.append(listecl) for i in range(100) : print("") liste[colone][ligne] = "X" affiche(liste) time.sleep(2) print("") print("") g = vaincqueur(liste) tour += 1 if g == "j1" : return "Tu as Gagné" elif g == "j2" : return "Tu as Perdu " if tour == 9 : return "Il y a égalité " else : pass print("") print("Il y a égalité ")