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

card

parent 68cf7bde
No related branches found
No related tags found
No related merge requests found
...@@ -95,9 +95,14 @@ class ApQueue(): ...@@ -95,9 +95,14 @@ class ApQueue():
return the string representation of this queue. return the string representation of this queue.
""" """
return ApQueue.ARROW + \ return ApQueue.ARROW + \
"|".join(str(el) for el in self.__content) + \ "|".join(str(el) for el in self.__content[::-1]) + \
ApQueue.ARROW ApQueue.ARROW
def __len__(self) -> int:
"""
return the length of this queue
"""
return len(self.__content)
if __name__ == '__main__': if __name__ == '__main__':
import apl1test import apl1test
......
...@@ -53,7 +53,8 @@ class Card(object): ...@@ -53,7 +53,8 @@ class Card(object):
précondition : value in VALUES and color in COLORS précondition : value in VALUES and color in COLORS
""" """
... self.value=value
self.color=color
def __hash__(self) -> int: def __hash__(self) -> int:
...@@ -69,7 +70,17 @@ class Card(object): ...@@ -69,7 +70,17 @@ class Card(object):
$$$ Card('Ace', 'heart') $$$ Card('Ace', 'heart')
Card("Ace", "heart") Card("Ace", "heart")
""" """
... return f'Card("{self.value}","{self.color}")'
def __str__(self) -> str:
"""
$$$ c=Card('Ace', 'heart')
$$$ repr(c)
'Ace of heart'
"""
return f'{self.value} of {self.color}'
def compare(self, card: Card) -> int: def compare(self, card: Card) -> int:
""" """
...@@ -97,7 +108,13 @@ class Card(object): ...@@ -97,7 +108,13 @@ class Card(object):
$$$ c1.compare(c3) == 0 $$$ c1.compare(c3) == 0
True True
""" """
... if Card.VALUES.index(self.value) < Card.VALUES.index(card.value):
res=-1
elif Card.VALUES.index(self.value) > Card.VALUES.index(card.value):
res=1
else:
res=0
return res
@staticmethod @staticmethod
def deck(n_card: int) -> list[Card]: def deck(n_card: int) -> list[Card]:
...@@ -116,49 +133,54 @@ class Card(object): ...@@ -116,49 +133,54 @@ class Card(object):
$$$ len(set(cartes)) $$$ len(set(cartes))
len(cartes) len(cartes)
""" """
... cartes=[Card(Card.VALUES[i],Card.COLORS[j]) for i in range(len(Card.VALUES)) for j in range(len(Card.COLORS))]
random.shuffle(cartes)
res=[]
for i in range(n_card):
res.append(cartes[i])
return res
def __eq__(self, card: Card) -> bool: def __eq__(self, card: Card) -> bool:
""" """
return True if self equals card return True if self equals card
False otherwise False otherwise
""" """
... return self.compare(card)==0
def __neq__(self, card: Card) -> bool: def __neq__(self, card: Card) -> bool:
""" """
return True if self don't equal card return True if self don't equal card
False otherwise False otherwise
""" """
... return self.compare(card)!=0
def __lt__(self, card: Card) -> bool: def __lt__(self, card: Card) -> bool:
""" """
return True if self is strictly inferior to card return True if self is strictly inferior to card
False otherwise False otherwise
""" """
... return self.compare(card)<0
def __le__(self, card: Card) -> bool: def __le__(self, card: Card) -> bool:
""" """
return True if self is inferior or equal to card return True if self is inferior or equal to card
False otherwise False otherwise
""" """
... return self.compare(card)<=0
def __gt__(self, card: Card) -> bool: def __gt__(self, card: Card) -> bool:
""" """
return True if self is strictly superior to card return True if self is strictly superior to card
False otherwise False otherwise
""" """
... return self.compare(card)>0
def __ge__(self, card: Card) -> bool: def __ge__(self, card: Card) -> bool:
""" """
return True if self is superior or equal to card return True if self is superior or equal to card
False otherwise False otherwise
""" """
... return self.compare(card)>=0
if (__name__ == '__main__'): if (__name__ == '__main__'):
......
...@@ -37,7 +37,15 @@ def distribute(n_card: int) -> tuple[ApQueue, ApQueue]: ...@@ -37,7 +37,15 @@ def distribute(n_card: int) -> tuple[ApQueue, ApQueue]:
$$$ isinstance(carte, Card) $$$ isinstance(carte, Card)
True True
""" """
... m1=ApQueue()
m2=ApQueue()
cartes=deck(2*n_card)
for i in range(n):
m1.enqueue(cartes[i])
m2.enqueue(cartes[2*n-i])
return (m1,m2)
def gather_stack(main: ApQueue, pile: ApStack) -> None: def gather_stack(main: ApQueue, pile: ApStack) -> None:
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment