|
@ -8,10 +8,10 @@ class Carte: |
|
|
self.couleur = couleur |
|
|
self.couleur = couleur |
|
|
def compare(self, other): |
|
|
def compare(self, other): |
|
|
if self.valeur > other.valeur: |
|
|
if self.valeur > other.valeur: |
|
|
return 1 |
|
|
return 0 |
|
|
elif self.valeur < other.valeur: |
|
|
elif self.valeur < other.valeur: |
|
|
return -1 |
|
|
return 1 |
|
|
return 0 |
|
|
return 2 |
|
|
|
|
|
|
|
|
class Jeux: |
|
|
class Jeux: |
|
|
def __init__ (self, nbr_cartes): |
|
|
def __init__ (self, nbr_cartes): |
|
@ -40,8 +40,28 @@ numeros = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] |
|
|
jeu = Jeux(52) |
|
|
jeu = Jeux(52) |
|
|
|
|
|
|
|
|
players = [File_chaine(), File_chaine()] |
|
|
players = [File_chaine(), File_chaine()] |
|
|
|
|
|
next_game = [[], []] |
|
|
|
|
|
|
|
|
jeu.distribue() |
|
|
jeu.distribue() |
|
|
|
|
|
|
|
|
while not (players[0].est_vide() or players[1].est_vide()): |
|
|
while not (players[0].est_vide() and len(next_game[0])!=0 or players[1].est_vide() and len(next_game[1])!=0): |
|
|
players[0].compare(players[1]) |
|
|
cartes_tour = [] |
|
|
|
|
|
cartes_tour.extend([players[0].defiler(), players[1].defiler()]) |
|
|
|
|
|
winner = cartes_tour[-2].compare(cartes_tour[-1]) |
|
|
|
|
|
if winner == 2: |
|
|
|
|
|
pass |
|
|
|
|
|
else: |
|
|
|
|
|
next_game[winner].extend(cartes_tour) |
|
|
|
|
|
for player_id in range(2): |
|
|
|
|
|
if players[player_id].est_vide() and len(next_game[player_id])==0: |
|
|
|
|
|
shuffle(next_game[player_id]) |
|
|
|
|
|
for i in next_game[player_id]: |
|
|
|
|
|
players[player_id].enfiler(i) |
|
|
|
|
|
next_game[player_id] = [] |
|
|
|
|
|
|
|
|
|
|
|
if players[0].est_vide(): |
|
|
|
|
|
print("Le joueur 1 a perdu", players[0].taille(), players[1].taille()) |
|
|
|
|
|
elif players[1].est_vide(): |
|
|
|
|
|
print("Le joueur 2 a perdu") |
|
|
|
|
|
|
|
|
|
|
|
|