Last active
August 23, 2025 02:00
-
-
Save Et7f3/b3177cb5e176b3640fe330caef6bbfae to your computer and use it in GitHub Desktop.
morpion python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def check(m): | |
| #on verifie les colonnes | |
| for i in range(0,3): | |
| if(m[i][0]==m[i][1]==m[i][2]!=" "): | |
| print('GG le joueur:',m[i][0]) | |
| return 0 | |
| #on verifie les lignes | |
| for i in range(0,3): | |
| if(m[0][i]==m[1][i]==m[2][i]!=" "): | |
| print('GG le joueur:',m[0][i]) | |
| return 0 | |
| #on verifie les diagonales | |
| if(m[0][0]==m[1][1]==m[2][2]!=" "): | |
| print('GG le joueur:',m[1][1]) | |
| return 0 | |
| if(m[0][2]==m[1][1]==m[2][0]!=" "): | |
| printprint('GG le joueur:',m[1][1]) | |
| return 0 | |
| #on verifie qu'il reste des cases a remplir | |
| for i in range(0,3): | |
| for j in range(0,3): | |
| if(m[i][j]==" "): | |
| return 1 | |
| print("fin du jeu aucun gagnant") | |
| return 0 | |
| def draw(m): | |
| print("-------------") | |
| for i in range(0,3): | |
| print("|",m[i][0],"|",m[i][1],"|",m[i][2],"|") | |
| print("-------------") | |
| return 1 | |
| if __name__== "__main__": | |
| nihil=" " | |
| m =[[nihil,nihil,nihil],[nihil,nihil,nihil],[nihil,nihil,nihil]] | |
| draw(m) | |
| j='x' | |
| while(check(m)): | |
| case=int(input("Entrer un numéro de case entre 1 et 9:"))-1 | |
| if(not(-1<case<9)): | |
| continue | |
| x=case%3 | |
| y=int((case-x)/3) | |
| if(m[y][x]==' '): | |
| m[y][x]=j | |
| j='0' if j=='x' else 'x' | |
| draw(m) | |
| #print(x,y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jeu de Morpion (Tic Tac Toe) à deux joueurs
def afficher_plateau(plateau):
for ligne in plateau:
print(" | ".join(ligne))
print("-" * 5)
def verifier_gagnant(plateau, joueur):
# Vérifie lignes
for ligne in plateau:
if all(case == joueur for case in ligne):
return True
# Vérifie colonnes
for col in range(3):
if all(plateau[ligne][col] == joueur for ligne in range(3)):
return True
# Vérifie diagonales
if all(plateau[i][i] == joueur for i in range(3)) or all(plateau[i][2-i] == joueur for i in range(3)):
return True
return False
def morpion():
plateau = [[" " for _ in range(3)] for _ in range(3)]
joueurs = ["X", "O"]
tour = 0
morpion()