Skip to content
Snippets Groups Projects
Commit ec72e958 authored by Belkacemi Melissa's avatar Belkacemi Melissa
Browse files

gather_stack

parent bd0aa91e
No related branches found
No related tags found
No related merge requests found
...@@ -75,7 +75,7 @@ class Card(object): ...@@ -75,7 +75,7 @@ class Card(object):
def __str__(self) -> str: def __str__(self) -> str:
""" """
$$$ c=Card('Ace', 'heart') $$$ c=Card('Ace', 'heart')
$$$ repr(c) $$$ str(c)
'Ace of heart' 'Ace of heart'
""" """
......
...@@ -39,10 +39,11 @@ def distribute(n_card: int) -> tuple[ApQueue, ApQueue]: ...@@ -39,10 +39,11 @@ def distribute(n_card: int) -> tuple[ApQueue, ApQueue]:
""" """
m1=ApQueue() m1=ApQueue()
m2=ApQueue() m2=ApQueue()
cartes=deck(2*n_card) cartes=Card.deck(2*n_card)
for i in range(n): for i in range(n_card):
m1.enqueue(cartes[i]) m1.enqueue(cartes[i])
m2.enqueue(cartes[2*n-i]) for j in range(n_card,2*n_card):
m2.enqueue(cartes[j])
return (m1,m2) return (m1,m2)
...@@ -56,15 +57,16 @@ def gather_stack(main: ApQueue, pile: ApStack) -> None: ...@@ -56,15 +57,16 @@ def gather_stack(main: ApQueue, pile: ApStack) -> None:
$$$ cartes = Card.deck(4) $$$ cartes = Card.deck(4)
$$$ main = ApQueue() $$$ main = ApQueue()
$$$ pile = ApStack() $$$ pile = ApStack()
$$$ for c in cartes: $$$ for c in cartes: pile.push(c)
... pile.push(c)
$$$ gather_stack( main, pile ) $$$ gather_stack( main, pile )
$$$ len( main ) == 4 $$$ len( main ) == 4
True True
$$$ all( main.dequeue() == cartes[ 3 - i ] for i in range(3)) $$$ all( main.dequeue() == cartes[ 3 - i ] for i in range(3))
True True
""" """
... while not pile.is_empty():
carte=pile.pop()
main.enqueue(carte)
def play_one_round(m1: ApQueue, m2: ApQueue, pile: ApStack) -> None: 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: ...@@ -81,7 +83,11 @@ def play_one_round(m1: ApQueue, m2: ApQueue, pile: ApStack) -> None:
precondition : m1 et m2 ne sont pas vides 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: def play(n_card: int, n_round: int) -> None:
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment