summaryrefslogtreecommitdiff
path: root/swiftstory/board.py
diff options
context:
space:
mode:
authorOlivier Gayot <olivier.gayot@sigexec.com>2021-12-23 15:27:43 +0100
committerOlivier Gayot <olivier.gayot@sigexec.com>2021-12-23 23:15:21 +0100
commit82cd09e010783b81ec58145c7682f4b8da49ac85 (patch)
tree83b3e61aaa4befcd340a01b2fb147a2306bdb29e /swiftstory/board.py
parent1be5c49ae402b768f9206724abdd503c18933ae1 (diff)
Use lowercase module names
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'swiftstory/board.py')
-rw-r--r--swiftstory/board.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/swiftstory/board.py b/swiftstory/board.py
new file mode 100644
index 0000000..c9b2aee
--- /dev/null
+++ b/swiftstory/board.py
@@ -0,0 +1,55 @@
+import random
+
+
+class Board:
+ ''' This class automatically handles the reshuffling of different deck/heap
+ of cards '''
+
+ def __init__(self):
+ # List of tuples:
+ # (card_id, card_desc)
+ self.white_pick = list()
+ self.black_pick = list()
+ self.white_recycled = list()
+ self.black_recycled = list()
+
+ self.current_black_card = None
+
+ # List of tuples:
+ # ((card_id, card_desc), player)
+ self.played_cards = list()
+
+ 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
+
+ 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_pick, self.black_recycled = self.black_recycled, list()
+
+ self.current_black_card = self.black_pick.pop()
+
+ def pick_white_card(self):
+ if not 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_pick, self.white_recycled = self.white_recycled, list()
+
+ return self.white_pick.pop()
+
+ def play_card(self, player, card):
+ self.played_cards.append((card, player))
+
+ def shuffle_played_cards(self):
+ random.shuffle(self.played_cards)
+
+ def recycle_played_cards(self):
+ self.white_recycled += [i[0] for i in self.played_cards]
+
+ self.played_cards = []