Browse Source

TeSt num 42

master
Bastion 1 day ago
parent
commit
b949fb4ecf
  1. 72
      bataille.py

72
bataille.py

@ -17,11 +17,11 @@ class Carte:
def __repr__(self):
return str(self.valeur)
def __str__(self):
if self.valeur == 11:
if self.valeur == 11:
return "V" + self.couleur
if self.valeur == 12:
elif self.valeur == 12:
return "D" + self.couleur
if self.valeur == 13:
elif self.valeur == 13:
return "R" + self.couleur
return str(self.valeur) + " de " + self.couleur
@ -86,8 +86,9 @@ class partie_TeSt:
self.j1, self.j2 = jeux.distribue()
self.Round = 1
self.Gain = File()
self.Winner = None
def play_round():
def play_round(self):
self.Round += 1
c1, c2 = self.j1.defiler(), self.j2.defiler()
@ -113,60 +114,27 @@ class partie_TeSt:
if resultat == 1:
while not self.Gain.est_vide():
self.j1.enfiler(self.Gain.defiler())
if self.j2.est_vide():
self.Winner = "J1"
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
c1 = j1.defiler()
c2 = j2.defiler()
gain = File()
gain.enfiler(c1)
gain.enfiler(c2)
resultat = c1.compare(c2)
while resultat == 0 and j1.taille() >= 2 and j2.taille() >= 2:
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:
gain.enfiler(c2)
gain.enfiler(c1)
else:
gain.enfiler(c1)
gain.enfiler(c2)
resultat = c1.compare(c2)
if resultat == 1:
winner = "c'est j1 qui a gagné"
while not gain.est_vide():
j1.enfiler(gain.defiler())
elif resultat == -1:
winner = "c'est j2 qui a gagné"
while not gain.est_vide():
j2.enfiler(gain.defiler())
if self.j1.est_vide():
self.Winner = "J2"
else:
if j1.taille() < 2 and not j2.taille() < 2:
winner = "c'est j2 qui a gagné"
self.Winner = "J2"
elif not j1.taille() < 2 and j2.taille() < 2:
winner = "c'est j2 qui a gagné"
self.Winner = "J1"
else:
winner = "égalité"
break
print(j1, j2)
return winner
self.Winner = "Egalité"
def get_winner(self):
if self.Winner is None:
return "Partie en cours..."
return self.Winner
if __name__ == "__main__":
jeu = Jeux(8)
j1, j2 = jeu.distribue()
print(partie_TeSt(j1, j2))
partie = partie_TeSt(32)
while partie.get_winner() == "Partie en cours...":
partie.play_round()

Loading…
Cancel
Save