diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-05-15 01:59:10 +0200 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-05-15 03:13:01 +0200 |
commit | e560cb629851cd27191756a62e5aca43150d3bdf (patch) | |
tree | 86611a8e429ffb413850fd3132be49ca881b51db | |
parent | 25c8dc5ad6faa9998d47b476c4f402482d80963c (diff) |
Rework the recycling of the cards
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
-rw-r--r-- | swiftstory/Board.py | 28 | ||||
-rw-r--r-- | swiftstory/Game.py | 4 |
2 files changed, 17 insertions, 15 deletions
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() diff --git a/swiftstory/Game.py b/swiftstory/Game.py index e80b7b2..9dd19c4 100644 --- a/swiftstory/Game.py +++ b/swiftstory/Game.py @@ -69,7 +69,7 @@ class Game: return error('Someone is judge already') self.judge = player - self.board.reveal_black_card() + self.board.reveal_next_black_card() self.state = self.WAITING_COLLECTION @@ -163,7 +163,6 @@ class Game: }) p.has_played = False - self.board.recycle_black_card() self.judge = None for p in self.players: @@ -208,7 +207,6 @@ class Game: player.client = None if self.judge is player: - self.board.recycle_black_card() self.judge = None for p in self.players: |