Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def winnercheck(test):
- for line in test:
- if line.count("X") == 3:
- return "Joueur 1"
- elif line.count("O") == 3:
- return "Joueur 2"
- for i in range(3):
- if test[0][i] == "X" and test[1][i] == "X" and test[2][i] == "X":
- return "Joueur 1"
- elif test[0][i] == "O" and test[1][i] == "O" and test[2][i] == "O":
- return "Joueur 2"
- 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":
- return "Joueur 1"
- 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":
- return "Joueur 2"
- return False
- grille = [[".", ".", "."],
- [".", ".", "."],
- [".", ".", "."]]
- tour = 1
- gagnant = False
- player = -1
- while not gagnant:
- if tour == 10:
- gagnant = "Egalite"
- break
- if player == -1: # joueur 1
- print("...Joueur 1...")
- 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")
- ligne = int(input("Ligne: ")) - 1
- colonne = int(input("Colonne: ")) - 1
- if grille[ligne][colonne] == ".":
- grille[ligne][colonne] = "X"
- gagnant = winnercheck(grille)
- tour += 1
- player *= -1
- else:
- print("Entrez une case non choisie.")
- else: # joueur 2
- print("...Joueur 2...")
- 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")
- ligne = int(input("Ligne: ")) - 1
- colonne = int(input("Colonne: ")) - 1
- if grille[ligne][colonne] == ".":
- grille[ligne][colonne] = "O"
- gagnant = winnercheck(grille)
- tour += 1
- player *= -1
- else:
- print("Entrez une case non choisie.")
- print(f"Gagnant: {gagnant}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement