diff --git a/bataille.py b/bataille.py index 3f1551b..794742d 100644 --- a/bataille.py +++ b/bataille.py @@ -21,9 +21,9 @@ class Carte: class Jeux: - def __init__(self, nbmax = 52): + def __init__(self, nbmax): i = 0 - valeurs = [1, 8, 9, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7] + valeurs = [1, 7, 8, 9, 10, 11, 12, 13, 2, 3, 4, 5, 6] couleurs = ["coeur", "pique", "carreau", "trefle"] jeu = [] for val in valeurs: @@ -74,11 +74,43 @@ def partie(jeu1, jeu2): jeu2.enfiler(gain.defiler()) """ - - -def partie_TeSt(j1, j2): - winner = "UwU" - Round = 1 +class partie_TeSt: + def __init__(self, nb_carte = 52): + jeux = Jeux(nb_carte) + self.j1, self.j2 = jeux.distribue() + self.Round = 1 + self.Gain = File() + + def play_round(): + self.Round += 1 + + c1, c2 = self.j1.defiler(), self.j2.defiler() + self.Gain.enfiler(c1) + self.Gain.enfiler(c2) + + resultat = c1.compare(c2) + + while resultat == 0 and self.j1.taille() >= 2 and self.j2.taille() >= 2: + + if random.randint(1, 2) == 1: + self.Gain.enfiler(self.j1.defiler()) + self.Gain.enfiler(self.j2.defiler()) + else: + self.Gain.enfiler(self.j2.defiler()) + self.Gain.enfiler(self.j1.defiler()) + + c1, c2 = self.j1.defiler(), self.j2.defiler() + self.Gain.enfiler(c1) + self.Gain.enfiler(c2) + + resultat = c1.compare(c2) + if resultat == 1: + while not self.Gain.est_vide(): + self.j1.enfiler(self.Gain.defiler()) + elif resultat == -1: + while not self.Gain.est_vide(): + self.j2.enfiler(self.Gain.defiler()) + while not (j1.est_vide() or j2.est_vide() or winner == "égalité"): print(Round) Round += 1 @@ -92,8 +124,12 @@ def partie_TeSt(j1, j2): gain.enfiler(c2) resultat = c1.compare(c2) while resultat == 0 and j1.taille() >= 2 and j2.taille() >= 2: - gain.enfiler(j1.defiler()) - gain.enfiler(j2.defiler()) + if random.randint(1, 2) == 1: + gain.enfiler(j1.defiler()) + gain.enfiler(j2.defiler()) + else: + gain.enfiler(j2.defiler()) + gain.enfiler(j1.defiler()) c1 = j1.defiler() c2 = j2.defiler() if random.randint(1, 2) == 1: