From e560cb629851cd27191756a62e5aca43150d3bdf Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 15 May 2020 01:59:10 +0200 Subject: Rework the recycling of the cards Signed-off-by: Olivier Gayot --- swiftstory/Board.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'swiftstory/Board.py') diff --git a/swiftstory/Board.py b/swiftstory/Board.py index 40d3ab7..5176e55 100644 --- a/swiftstory/Board.py +++ b/swiftstory/Board.py @@ -2,6 +2,9 @@ import random class Board: + ''' This class automatically handles the reshuffling of different deck/heap + of cards ''' + def __init__(self, white_cards, black_cards): self.white_pick = white_cards self.black_pick = black_cards @@ -17,26 +20,27 @@ class Board: random.shuffle(self.white_pick) random.shuffle(self.black_pick) - def reveal_black_card(self): - if not self.black_pick: - self.black_pick = self.black_recycle + def reveal_next_black_card(self): + if self.current_black_card is not None: + self.black_recycled.append(self.current_black_card) + self.current_black_card = None - random.shuffle(self.black_pick) + if not self.black_pick: + # If we have no more cards in the deck, we need to reform one using + # the cards that have been recycled. + random.shuffle(self.black_recycled) - self.black_recycled = [] + self.black_pick, self.black_recycled = self.black_recycled, list() self.current_black_card = self.black_pick.pop() - def recycle_black_card(self): - self.black_recycled.append(self.current_black_card) - def pick_white_card(self): if not self.white_pick: - self.white_pick = self.white_recycled - - random.shuffle(self.white_pick) + # If we have no more cards in the deck, we need to reform one using + # the cards that have been recycled. + random.shuffle(self.white_recycled) - self.white_recycled = [] + self.white_pick, self.white_recycled = self.white_recycled, list() return self.white_pick.pop() -- cgit v1.2.3