Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.06 KB | None | 0 0
  1. def winnercheck(test):
  2.     for line in test:
  3.         if line.count("X") == 3:
  4.             return "Joueur 1"
  5.         elif line.count("O") == 3:
  6.             return "Joueur 2"
  7.     for i in range(3):
  8.         if test[0][i] == "X" and test[1][i] == "X" and test[2][i] == "X":
  9.             return "Joueur 1"
  10.         elif test[0][i] == "O" and test[1][i] == "O" and test[2][i] == "O":
  11.             return "Joueur 2"
  12.     if test[0][0] == "X" and test[1][1] == "X" and test[2][2] == "X" or test[0][2] == "X" and test[1][1] == "X" and test[2][0] == "X":
  13.         return "Joueur 1"
  14.     elif test[0][0] == "O" and test[1][1] == "O" and test[2][2] == "O" or test[0][2] == "O" and test[1][1] == "O" and test[2][0] == "O":
  15.         return "Joueur 2"
  16.  
  17.     return False
  18.  
  19. grille = [[".", ".", "."],
  20.           [".", ".", "."],
  21.           [".", ".", "."]]
  22.  
  23. tour = 1
  24. gagnant = False
  25. player = -1
  26.  
  27. while not gagnant:
  28.     if tour == 10:
  29.         gagnant = "Egalite"
  30.         break
  31.     if player == -1:  # joueur 1
  32.         print("...Joueur 1...")
  33.         print(f"{grille[0][0]} {grille[0][1]} {grille[0][2]}\n{grille[1][0]} {grille[1][1]} {grille[1][2]}\n{grille[2][0]} {grille[2][1]} {grille[2][2]}\n")
  34.         ligne = int(input("Ligne: ")) - 1
  35.         colonne = int(input("Colonne: ")) - 1
  36.         if grille[ligne][colonne] == ".":
  37.             grille[ligne][colonne] = "X"
  38.             gagnant = winnercheck(grille)
  39.             tour += 1
  40.             player *= -1
  41.         else:
  42.             print("Entrez une case non choisie.")
  43.     else:  # joueur 2
  44.         print("...Joueur 2...")
  45.         print(f"{grille[0][0]} {grille[0][1]} {grille[0][2]}\n{grille[1][0]} {grille[1][1]} {grille[1][2]}\n{grille[2][0]} {grille[2][1]} {grille[2][2]}\n")
  46.         ligne = int(input("Ligne: ")) - 1
  47.         colonne = int(input("Colonne: ")) - 1
  48.         if grille[ligne][colonne] == ".":
  49.             grille[ligne][colonne] = "O"
  50.             gagnant = winnercheck(grille)
  51.             tour += 1
  52.             player *= -1
  53.         else:
  54.             print("Entrez une case non choisie.")
  55.  
  56. print(f"Gagnant: {gagnant}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement