class Player(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(255), index=True, unique=True) email = db.Column(db.String(255), index=True, unique=True) password_hash = db.Column(db.String(255)) chips = db.Column(db.Integer) games = db.relationship('Game', backref='player', lazy='dynamic') def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password)
class Card(db.Model): id = db.Column(db.Integer, primary_key=True) deck_id = db.Column(db.Integer, enable_typechecks=False,db.ForeignKey('cardset.id')) rank = db.Column(db.Enum(CardRanks)) suit = db.Column(db.Enum(CardSuit)) def __init__(self, rank, suit): self.rank = rank self.suit = suit def __str__(self): if not (self.rank == CardRanks.Ace or self.rank == CardRanks.Jack or self.rank == CardRanks.Queen or self.rank == CardRanks.King): cardvalue = self.rank.value else: cardvalue = self.rank.name return str(cardvalue) + ' ' + self.suit.name def __repr__(self): return self.rank.name + ' ' + self.suit.name def as_json(self): return {'Card': self.__str__()}
class Game(db.Model): id = db.Column(db.Integer, primary_key=True) player_id = db.Column(db.Integer, db.ForeignKey('player.id')) deck_id = db.Column(db.Integer) deck = db.relationship('CardSet', enable_typechecks=False, foreign_keys=[deck_id], primaryjoin='Game.deck_id==CardSet.id') player_hand_id = db.Column(db.Integer) player_hand = db.relationship( 'CardSet', enable_typechecks=False, foreign_keys=[player_hand_id], primaryjoin='Game.player_hand_id==CardSet.id') #dealer_hand_id = db.Column(db.Integer, db.ForeignKey('d.id')) bet_pool = db.Column(db.Integer) current_bet = db.Column(db.Integer)
class CardSet(db.Model): id = db.Column(db.Integer, primary_key=True) cards = db.relationship('Card', enable_typechecks=False, lazy='dynamic')