Files
card/card_game/deck.py
2026-05-24 08:10:22 +08:00

27 lines
589 B
Python

"""Deck class: build, shuffle, draw."""
import random
from card_game.card import Card
class Deck:
def __init__(self):
self.cards = []
self.draw_pile = []
def build(self, card_id_list):
self.cards = [Card(cid) for cid in card_id_list]
self.draw_pile = list(self.cards)
random.shuffle(self.draw_pile)
def draw(self):
if not self.draw_pile:
return None
return self.draw_pile.pop()
def is_empty(self):
return len(self.draw_pile) == 0
def remaining(self):
return len(self.draw_pile)