1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
# ------------------------------ variable globales --------------------------------
joueur1 = input("indiquer le nom du joueur 1 : ")
joueur2 = input("indiquer le nom du joueur 2 : ")
print(" ")
print("vous avez 21 pions max par personne")
print(" ")
print("le joueur 1 est : ", joueur1)
print("le joueur 2 est : ", joueur2)
pion1 = 'R'
pion2 = 'J'
# --------------------------------- constante ---------------------
COLONNE = 7
LIGNE = 6
tableau = [['.','.','.','.','.','.','.'],['.','.','.','.','.','.','.'],['.','.','.','.','.','.','.'],['.','.','.','.','.','.','.'],['.','.','.','.','.','.','.'],['.','.','.','.','.','.','.']]
# -------------------------------- fonction ----------------------------
def afficheTableau():
for l in range (LIGNE):
for c in range (COLONNE):
print(tableau[l][c], end = " ")
print()
def verificationligne():
# vérification ligne
for l in range (LIGNE):
cpt=0
for c in range (COLONNE-1):
if (tableau[l][c] == tableau[l][c+1]) and tableau[l][c] !='.':
cpt = cpt +1
if cpt ==3:
print("c'est gagn̮̩")
break
else:
cpt = 0
# Vérification colonne
def verificationcolonne():
for c in range (COLONNE):
cpt=0
for l in range (LIGNE-1):
if (tableau[l][c] == tableau[l+1][c]) and tableau[l][c] !='.':
cpt = cpt +1
if cpt ==3:
print("c'est gagn̮̩")
break
else:
cpt = 0
def verificationdiagonale():
# Vérification en diagonale de la gauche haut ÃÂ* bas droite
for l in range (LIGNE-3):
cpt=0
for c in range (COLONNE-l):
if (tableau[l][c] == tableau[l+c][c]) and tableau[l][c] !='.':
cpt = cpt+1
if cpt == 3:
print("c'est gagnée")
break
else:
cpt = 0
for c in range (COLONNE-3):
cpt=0
for l in range (LIGNE-c):
if (tableau[l][c] == tableau[l][l+c]) and tableau[l][c] !='.':
cpt = cpt+1
if cpt == 3:
print("c'est gagnée")
break
else:
cpt = 0
def ajoutePion(colonne, pion):
for i in range (LIGNE-1, -1, -1):
if tableau[i][colonne]==".":
tableau[i][colonne] = pion
print("placee ligne",i)
break
#-------------------------------------- jeu --------------------------
for i in range (21):
afficheTableau()
print(" ")
print(joueur1,"a ton tour")
print(" ")
co = int(input("entrer une colonne "))
ajoutePion(co, 'R')
verificationligne()
verificationcolonne()
verificationdiagonale()
afficheTableau()
print(" ")
print(joueur2,"a ton tour")
print(" ")
co = int(input("entrer une colonne "))
ajoutePion(co, 'J')
verificationligne()
verificationcolonne()
verificationdiagonale()
print("______________________") |
Partager