diff options
Diffstat (limited to 'swiftstory')
-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: |