diff --git a/TP8/bataille-carte/card.py b/TP8/bataille-carte/card.py index 0a500fa1535e8125666af0b08f020170bd233b3a..bd240e541caa23baad76b53e88519cc568815cbf 100755 --- a/TP8/bataille-carte/card.py +++ b/TP8/bataille-carte/card.py @@ -75,7 +75,7 @@ class Card(object): def __str__(self) -> str: """ $$$ c=Card('Ace', 'heart') - $$$ repr(c) + $$$ str(c) 'Ace of heart' """ diff --git a/TP8/bataille-carte/war.py b/TP8/bataille-carte/war.py index 4c58b9c299827bb7a1c3c1ddddd874e525f51a0a..b90cdbfc44fb9c5ddb4afda3d1732f45e0e51ae3 100755 --- a/TP8/bataille-carte/war.py +++ b/TP8/bataille-carte/war.py @@ -39,10 +39,11 @@ def distribute(n_card: int) -> tuple[ApQueue, ApQueue]: """ m1=ApQueue() m2=ApQueue() - cartes=deck(2*n_card) - for i in range(n): - m1.enqueue(cartes[i]) - m2.enqueue(cartes[2*n-i]) + cartes=Card.deck(2*n_card) + for i in range(n_card): + m1.enqueue(cartes[i]) + for j in range(n_card,2*n_card): + m2.enqueue(cartes[j]) return (m1,m2) @@ -56,15 +57,16 @@ def gather_stack(main: ApQueue, pile: ApStack) -> None: $$$ cartes = Card.deck(4) $$$ main = ApQueue() $$$ pile = ApStack() - $$$ for c in cartes: - ... pile.push(c) + $$$ for c in cartes: pile.push(c) $$$ gather_stack( main, pile ) $$$ len( main ) == 4 True $$$ all( main.dequeue() == cartes[ 3 - i ] for i in range(3)) True """ - ... + while not pile.is_empty(): + carte=pile.pop() + main.enqueue(carte) def play_one_round(m1: ApQueue, m2: ApQueue, pile: ApStack) -> None: """ @@ -81,7 +83,11 @@ def play_one_round(m1: ApQueue, m2: ApQueue, pile: ApStack) -> None: precondition : m1 et m2 ne sont pas vides """ - ... + c1=m1.dequeue() + c2=m2.dequeue() + print(f'joueur 1 joue {str(c1)} et joueur 2 {ste(c2)}') + if c1>c2: + def play(n_card: int, n_round: int) -> None: """