Last active
November 22, 2022 21:12
-
-
Save Et7f3/b3177cb5e176b3640fe330caef6bbfae to your computer and use it in GitHub Desktop.
morpion python
This file contains 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