本文整理汇总了Python中models.Game.deck方法的典型用法代码示例。如果您正苦于以下问题:Python Game.deck方法的具体用法?Python Game.deck怎么用?Python Game.deck使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.deck方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import deck [as 别名]
def create_game(game_type, room_id):
if request.method == 'GET':
dealer = Player()
session.add(dealer)
game = Game(game_type)
session.add(game)
deck = Hand()
session.add(deck)
game.deck = deck
if game_type == 'Blackjack':
i = 1
while i <= 5:
seat = Seat(i)
game.seats.append(seat)
session.commit()
i += 1
game.time = datetime.datetime.now()
game.dealer = dealer
dealer_hand = Hand()
dealer.hands.append(dealer_hand)
game.players.append(current_user)
session.commit()
if room_id != 0:
room = session.query(GameRoom).filter(GameRoom.id == room_id).all()[0]
room.current_game = game
return redirect(url_for('game_room', room_id=room_id))
else:
room = GameRoom()
room.current_game = game
session.commit()
return redirect(url_for('game_room', room_id=room.id))
示例2: test_make_deck_shuffle_hit
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import deck [as 别名]
def test_make_deck_shuffle_hit(self):
# setup
player = Player('cory', 'password')
game = Game('Blackjack')
game.players.append(player)
h = Hand()
h2 = Hand()
game.hands.append(h)
player.hands.append(h2)
cards = piece_maker(suits, card_values, 1)
h.cards.extend(cards)
cards_app.session.commit()
# end of setup
# deck is made in setUp() with piece_maker() ha
game.deck = h
game.hands.append(h2)
deck = game.deck
hand2 = h2
cards_app.session.flush()
assert deck.cards != shuffle(deck)
hand_before_hit = len(hand2.cards)
deck_before_hit = len(deck.cards)
hit(hand2, 1)
cards_app.session.commit()
# do we still have 52 cards after hitting?
assert len(set(deck.cards)) + len(set(hand2.cards)) == 52
assert len(deck.cards) == deck_before_hit-1
assert len(hand2.cards) == hand_before_hit+1
示例3: test_blackjack_payout
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import deck [as 别名]
def test_blackjack_payout(self):
player = Player('cory','password')
game = Game('Blackjack')
hand = Hand()
game.players = []
player.bank = 100
player.hands = [hand]
hand.bet = 0
game.deck = Hand()
game.dealer = Player('cory','password')
game.dealer.hands.append(Hand())
game.hands.append(game.dealer.hands[0])
player.hands.append(hand)
game.hands.append(hand)
game.deck.cards = piece_maker(suits, card_values, 1)
game.players.append(player)
cards_app.session.flush()
# testing player AND dealer get blackjack
hand.cards = [Card(sequence=1), Card(sequence=10)]
game.dealer.hands[0].cards = [Card(sequence=1), Card(sequence=10)]
bet(hand, 50)
count_blackjack(hand)
blackjack_dealer(game)
assert player.bank == 100
# Player gets 15 and dealer gets 15, dealer hits and breaks because deck is unshuffled and king on top
player.bank = 100
hand.cards = [Card(sequence=10), Card(sequence=5)]
game.dealer.hands[0].cards = [Card(sequence=10), Card(sequence=5)]
bet(hand, 50)
hand.is_expired = False
count_blackjack(hand)
blackjack_dealer(game)
assert player.bank == 150
# player gets blackjack, dealer doesn't
hand.is_expired = False
hand.bet = 0
player.bank = 100
hand.cards = [Card(sequence=10), Card(sequence=1)]
game.dealer.hands[0].cards = [Card(sequence=10), Card(sequence=10)]
bet(hand, 50)
count_blackjack(hand)
blackjack_dealer(game)
assert player.bank == 175
# player broke, loses bet
hand.is_expired = False
hand.bet = 0
player.bank = 100
hand.cards = [Card(sequence=10), Card(sequence=10), Card(sequence=10)]
game.dealer.hands[0].cards = [Card(sequence=10), Card(sequence=10)]
bet(hand, 50)
count_blackjack(hand)
blackjack_dealer(game)
blackjack_payout(game)
assert player.bank == 50
示例4: new_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import deck [as 别名]
def new_game():
game = Game()
game.deck = ""
game.started = False
game.start_time = datetime.datetime.today() + datetime.timedelta(hours=1)#a timeout at some point?
game.save()
game_id = game.pk
#This actually belongs somewhere else, needs to be recreated with every server reboot.
gameEvent = threading.Event()
game_events[game_id] = gameEvent
gameLock = threading.Condition()
game_locks[game_id] = gameLock
print "creating a new game.", game.pk
return game
示例5: test_split
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import deck [as 别名]
def test_split(self):
cards = [Card(sequence=1), Card(sequence=1)]
hand = Hand()
player = Player('cory','password')
game = Game('Blackjack')
deck = Hand()
game.deck = deck
game.deck.cards = piece_maker(suits, card_values, 1)
game.deck.cards = shuffle(game.deck)
player.hands.append(hand)
player.cards.extend(cards)
game.hands.append(hand)
hand.cards.extend(cards)
split(hand)
hands = player.hands
assert len(hands) == 2
assert len(hands[0].cards) == 2 and len(hands[1].cards) == 2
assert hands[0].cards[0].sequence == hands[1].cards[0].sequence
示例6: test_blackjack_dealer
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import deck [as 别名]
def test_blackjack_dealer(self):
player = Player('cory','password')
game = Game('Blackjack')
hand = Hand()
game.players = []
player.bank = 100
game.deck = Hand()
game.dealer = Player('cory','password')
game.dealer.hands.append(Hand())
game.hands.append(game.dealer.hands[0])
player.hands.append(hand)
game.hands.append(hand)
game.deck.cards = piece_maker(suits, card_values, 1)
game.players.append(player)
cards_app.session.flush()
player.hands[0].cards = [Card(sequence=10), Card(sequence=8)]
game.dealer.hands[0].cards = [Card(sequence=6), Card(sequence=1)]
bet(player.hands[0], 50)
count_blackjack(player.hands[0])
blackjack_dealer(game)
blackjack_payout(game)
# blackjack dealer should break after hitting on he soft 17
assert player.bank == 150