本文整理汇总了Python中Deck.Deck.deal方法的典型用法代码示例。如果您正苦于以下问题:Python Deck.deal方法的具体用法?Python Deck.deal怎么用?Python Deck.deal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Deck.Deck
的用法示例。
在下文中一共展示了Deck.deal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: battle
# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import deal [as 别名]
def battle():
print('\n#<====== Playing a Game of War ======>#\n')
## Creating p1Score, p2Score, ties variables.
p1Score = 0
p2Score = 0
ties = 0
## Creating two hands to hold cards (that are dealt for each player)
h1 = []
h2 = []
## Creating a new deck for the cards
d = Deck()
## Shuffling the new deck
d.shuffle()
## Using a loop to deal cards to the two players.
for i in range(len(d.cards)):
if i % 2 == 0:
h1.append(d.deal())
elif i % 2 == 1:
h2.append(d.deal())
i += 1
## printing each player's hands
print('\n#<====== Player 1\'s Hand: ======>#\n')
for card in h1:
print(card)
print('\n#<====== Player 2\'s Hand: ======>#\n')
for card in h2:
print(card)
print('\n#<====== Now its time for WAR!!! ======>#\n')
示例2: run
# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import deal [as 别名]
def run():
playing = True
won_round = True
round = 1
# Creating bot opponents
cpu_players = []
for i in range(num_players):
cpu = ComputerPlayer("CPU" + str(i+1), PLAYING_STYLES[0]) #Playing style
hand = Hand()
cpu.set_hand(hand)
cpu_players.append(cpu)
player = Player("User", is_big_blind = True)
deck = Deck()
deck.create_deck()
hand = Hand()
table = Table()
#start game loop
while (player.can_play() and playing):
print "Round: %d" % round
deck.shuffle()
player.set_hand(hand)
if PLAY_WITH_BLINDS:
table.set_player_blinds(player, cpu_players)
for p in ([player] + cpu_players):
if p.is_big_blind():
blind = p.pay_blind(table.get_big_blind_size())
table.add_bet(blind)
print "*%s is big blind*" % str(p)
elif p.is_small_blind():
blind = p.pay_blind(table.get_small_blind_size())
table.add_bet(blind)
print "*%s is small blind*" % str(p)
print ""
deck.deal(2, player.get_hand())
for cpu in cpu_players:
deck.deal(2, cpu.get_hand())
if (DEBUG_MODE):
print "%s\'s HAND: %s" % (str(cpu), str(cpu.get_hand()))##### FOR DEBUGGING
non_folded_cpu = cpu_players[:]
# Hold'em rules: discard, "burn" 2 cards before the display of the flop
for i in range(5):
if i < 2:
table.burn(deck.draw())
else:
table.push(deck.draw())
turn = 1
#condition to allow bets to continue
betting = True
while turn < 4 and non_folded_cpu != []:
print "%s:\n%s \n" % ("Flop" if turn ==1 else ("Turn" if turn ==2 else "River"), str(table))
print "Current Hand: %s" % str(player.get_hand())
print "Chip amount: %d" % player.get_value()
current_bet = 0
###START BETTING LOOP#####
while(betting or not [cpu.is_checked() for cpu in non_folded_cpu]):
ready_to_exit = True #boolean to control wheter we leave bet loop
user_input = parse_input("Bet, Check, or Fold? (Enter B/C/F):")
if user_input == "B":
current_bet = player.bet()
table.add_bet(current_bet)
#ADD SO I CAN CHECK IF THE BET IS HIGHER THAN MY LAST
elif user_input == "C":
pass
elif user_input == "F":
betting = False
won_round = False
#for loop to decide cpu action
for cpu in non_folded_cpu:
print "%s is deciding..." % str(cpu)
sleep(1)
cpu_bet = cpu.bet(current_bet)
if cpu_bet == -1:
print "%s folds." % str(cpu)
non_folded_cpu.remove(cpu)
elif cpu.is_checked() and current_bet == 0:
print "%s checks." % str(cpu)
#there was a raise
elif cpu_bet > current_bet:
print "%s raises to %d." % (str(cpu), cpu_bet)
table.add_bet(cpu_bet)
current_bet = cpu_bet
elif cpu_bet == current_bet:
print "%s matches the bet." % str(cpu)
table.add_bet(cpu_bet)
else:
raise RuntimeError("Problem Occured, exiting")
exit(0)
print "\nCurrent Pot: %d" % table.get_value()
#end for
if non_folded_cpu == []:
break
#####ADD CONDITION TO EXIT OUT OF BETTING LOOP
for cpu in non_folded_cpu:
if cpu.get_last_bet() < current_bet:
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import deal [as 别名]
class Probability:
def __init__(self, rounds=1000, *choices):
# Variable declarations for counting
self.flush = 0
self.fullHouse = 0
self.threeOfAKind = 0
self.fourOfAKind = 0
self.onePair = 0
self.twoPairs = 0
self.rounds = rounds
self.choices = choices
# Check for empty values
if len(self.choices) == 0:
sys.exit("Empty poker type not allowed")
# Run game 10000 times
for i in range(self.rounds):
# Instantiate card and decks
self.deck = Deck()
self.deck.shuffle()
# Play 10 rounds
for j in range(10):
self.poker = PokerHand()
# Pick up 5 cards
for k in range(5):
self.poker.add(self.deck.deal())
# Check if cards are cetain types of pokers
if self.poker.isFlush():
self.flush += 1
elif self.poker.hasFullHouse():
self.fullHouse += 1
elif self.poker.hasThreeOfAKind():
self.threeOfAKind += 1
elif self.poker.hasFourOfAKind():
self.fourOfAKind += 1
elif self.poker.hasOnePair():
self.onePair += 1
elif self.poker.hasTwoPairs():
self.twoPairs += 1
def show(self):
# Results
self.head = "%s hands dealt\n%s\n"
self.head = self.head % (self.rounds, (len(self.head) - 1) * "=")
print(self.head)
for choice in self.choices:
choice = choice.lower().replace(" ", "")
if choice == "f" or choice == "flush":
print("Flush occurred %s times" % self.flush)
print("Estimated P(Flush) is: %.3f\n" % ((self.flush * 100)/self.rounds))
elif choice == "fh" or choice == "fullhouse":
print("Full House occurred %s times" % self.fullHouse)
print("Estimated P(Full House) is: %.3f\n" % ((self.fullHouse * 100)/self.rounds))
elif choice == "toak" or choice == "threeofakind":
print("Three of a kind %s times" % self.threeOfAKind)
print("Estimated P(Three of a kind) is: %.3f\n" % ((self.threeOfAKind * 100)/self.rounds))
elif choice == "foak" or choice == "fourofakind":
print("Four of a kind %s times" % self.fourOfAKind)
print("Estimated P(Four of a kind) is: %.3f\n" % ((self.fourOfAKind * 100)/self.rounds))
elif choice == "op" or choice == "onepair":
print("One Pair %s times" % self.onePair)
print("Estimated P(One Pair) is: %.3f\n" % ((self.onePair * 100)/self.rounds))
elif choice == "tp" or choice == "twopairs":
print("Two Pairs %s times" % self.twoPairs)
print("Estimated P(Two Pairs) is: %.3f\n" % ((self.twoPairs * 100)/self.rounds))
def plot(self):
pokerlists = []
header = []
for choice in self.choices:
choice = choice.lower().replace(" ", "")
if choice == "f" or choice == "flush":
pokerlists.append(self.flush)
header.append("Flush")
elif choice == "fh" or choice == "fullhouse":
pokerlists.append(self.fullHouse)
header.append("Full House")
elif choice == "toak" or choice == "threeofakind":
pokerlists.append(self.threeOfAKind)
#.........这里部分代码省略.........
示例4: Blackjack
# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import deal [as 别名]
class Blackjack(object):
def __init__(self, player = Player("")):
self.player = player;
self.deck = Deck()
self.deck.create_default_deck()
self.deck.shuffle()
def print_player_name(self):
print self.player.get_name()
def print_hand(self, player = Player("")):
print player.get_name()+"'s cards:"
for c in player.get_hand():
print c.get_name()
def bust(self, player = Player("")):
sum = 0
for c in player.get_hand():
sum += c.get_value()
if(sum>21):
return True
return False
def count_cards(self, cards):
sum = 0
ace = 0
for c in cards:
if c.get_val==11 :
ace += 1
else:
sum += c.get_val()
if ace>0: ## Aces have varying values
for i in range(ace):
if sum+11 > 21:
sum+=1
else:
sum+=11
return sum
def hit(self, player = Player("")):
self.deck.deal(1, player)
def should_hit(self, ai_card_val):
return ai_card_val < 17
def dist_winnings(self, player = Player("")):
print "Congratulations to "+player.get_name()+" for winning this round!";
def dist_winnings_equally(self, ai = Player("")):
print "Tie! Winnings will be distributed equally"
def play(self):
ai = Player ("AI")
self.deck.deal(2, self.player)
self.deck.deal(2, ai)
player_card_val = self.count_cards(self.player.get_hand())
ai_card_val = self.count_cards(ai.get_hand())
self.print_hand(self.player)
while "yes" in raw_input("Do you want to hit?: ").lower():
self.hit(self.player)
player_card_val = self.count_cards(self.player.get_hand())
if (player_card_val>21):
print self.player.get_name()+" busted!"
self.dist_winnings(ai)
self.deck.add(self.player.return_hand())
self.deck.add(ai.return_hand())
return
self.print_hand(self.player)
while self.should_hit(ai_card_val):
self.hit(ai)
ai_card_val = self.count_cards(ai.get_hand())
if(ai_card_val >21):
print ai.get_name()+" busted!"
self.dist_winnings(self.player)
self.deck.add(self.player.return_hand())
self.deck.add(ai.return_hand())
return
self.print_hand(ai)
if player_card_val > ai_card_val :
self.dist_winnings(self.player)
elif ai_card_val > player_card_val:
self.dist_winnings(ai)
else:
self.dist_winnings_equally(ai)
self.deck.add(self.player.return_hand())
self.deck.add(ai.return_hand())
return
示例5: Table
# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import deal [as 别名]
class Table(object):
'''This is essentially the House. It runs the game.'''
def __init__(self):
# self.players is going to be a dict with ints as keys denoting the seats each player has.
self.players = {}
self.button_seat = -1
# Here's how the rake works: $1 for every $10 in pot that is CALLED. Take first from main pot, then side pots in order until limit is reached ($5 here).
self.rake_rules = {
'limit': 5,
'amt': 1,
'in': 10,
}
self.box = 0
self.tips = 0
self.units = [2, 2, 4, 4]
self.limits = [10, 10, 20, 20]
self.action = None
def initialize_hand(self):
self.move_button()
self.pots = [Pot(self.players.keys())]
self.rake = [0]
self.action = self.button_seat
self.deck = Deck()
self.deck.shuffle()
for position, player in self.players.iteritems():
player.discard_hole_cards()
self.board = []
def take_blinds(self):
self.take_bet(1)
self.incr_action()
self.take_bet(2)
def burn_one_card(self):
return self.deck.deal()
def deal_one_hole_card_to_all_players(self):
# I'm not 100% happy with this, but it works.
while True:
self.incr_action()
self.players[self.action].hole_cards.append(self.deck.deal())
if self.action == self.button_seat:
break
def deal_one_community_card(self):
self.board.append(self.deck.deal())
def flop(self):
self.burn_one_card()
for i in xrange(3):
self.deal_one_community_card()
def turn(self):
self.burn_one_card()
self.deal_one_community_card()
def river(self):
self.turn()
def pots_need_action(self, position):
for pot in self.pots:
if pot.action_needed(position):
return True
return False
def run_betting_round(self):
last_to_act = None
pots_ended = False
while self.action != last_to_act:
if self.pots_need_action(self.action):
error = None
decision = self.players[self.action].decide(error)
if decision == Decision.FOLD:
for pot in self.pots:
pot.make_ineligible_to_win(self.action)
elif decision == Decision.CHECK:
pass # I may accommodate this under CALL
elif decision == Decision.CALL:
# Remember that if you skim for a side pot, you have to effectively fold the current action out of any new side pot you make
# Um is that true? Or does Pot skim method do that for me?
self.take_bet(self.current_call_amt())
elif decision == Decision.RAISE:
pass
last_to_act = self.action
potential_winner = self.look_for_winner()
if potential_winner is not None:
for pot in self.pots:
pot.end_round()
return potential_winner
if not self.incr_action(): # Side effect of moving action
for pot in self.pots:
pot.end_round()
pots_ended = True
break # Betting is done
if not pots_ended:
for pot in self.pots:
pot.end_round()
self.take_rake()
#.........这里部分代码省略.........
示例6: print
# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import deal [as 别名]
print('\n#<====== Shuffling Deck ======>#\n')
d.shuffle()
print('The shuffle method will return the deck as:\n')
print(d, '\n')
## Testing the sort method.
print('\n#<====== Sorting Deck ======>#\n')
d.sort()
print('The sort method will return the deck as:\n')
print(d, '\n')
## Testing the Deal method.
print('\n#<====== Dealing Deck ======>#\n')
print('Card #1 is', d.deal())
print('Card #2 is', d.deal())
print('\nThe number of cards left in the deck:', len(d.cards))
print()
def battle():
print('\n#<====== Playing a Game of War ======>#\n')
## Creating p1Score, p2Score, ties variables.
p1Score = 0
p2Score = 0
ties = 0
## Creating two hands to hold cards (that are dealt for each player)
h1 = []
h2 = []
## Creating a new deck for the cards
d = Deck()
示例7: __init__
# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import deal [as 别名]
class Hearts:
def __init__(self):
self.roundNum = 0
self.trickNum = 0 # initialization value such that first round is round 0
self.dealer = -1 # so that first dealer is 0
self.passes = [1, -1, 2, 0] # left, right, across, no pass
self.currentTrick = Trick()
self.trickWinner = -1
self.heartsBroken = False
self.losingPlayer = None
self.passingCards = [[], [], [], []]
# Make four players
self.players = [Player("Danny"), Player("Desmond"), Player("Ben"), Player("Tyler")]
'''
Player physical locations:
Game runs clockwise
p3
p2 p4
p1
'''
# Generate a full deck of cards and shuffle it
self.newRound()
def handleScoring(self):
p, highestScore = None, 0
print "\nScores:\n"
for player in self.players:
print player.name + ": " + str(player.score)
if player.score > highestScore:
p = player
highestScore = player.score
self.losingPlayer = p
def newRound(self):
self.deck = Deck()
self.deck.shuffle()
self.roundNum += 1
self.trickNum = 0
self.trickWinner = -1
self.heartsBroken = False
self.dealer = (self.dealer + 1) % len(self.players)
self.dealCards()
self.currentTrick = Trick()
self.passingCards = [[], [], [], []]
for p in self.players:
p.discardTricks()
def getFirstTrickStarter(self):
for i,p in enumerate(self.players):
if p.hand.contains2ofclubs:
self.trickWinner = i
def dealCards(self):
i = 0
while(self.deck.size() > 0):
self.players[i % len(self.players)].addCard(self.deck.deal())
i += 1
def evaluateTrick(self):
self.trickWinner = self.currentTrick.winner
p = self.players[self.trickWinner]
p.trickWon(self.currentTrick)
self.printCurrentTrick()
print p.name + " won the trick."
# print 'Making new trick'
self.currentTrick = Trick()
print self.currentTrick.suit
def passCards(self, index):
print self.printPassingCards()
passTo = self.passes[self.trickNum] # how far to pass cards
passTo = (index + passTo) % len(self.players) # the index to which cards are passed
while len(self.passingCards[passTo]) < cardsToPass: # pass three cards
passCard = None
while passCard is None: # make sure string passed is valid
passCard = self.players[index].play(option='pass')
if passCard is not None:
# remove card from player hand and add to passed cards
self.passingCards[passTo].append(passCard)
self.players[index].removeCard(passCard)
def distributePassedCards(self):
for i,passed in enumerate(self.passingCards):
for card in passed:
self.players[i].addCard(card)
self.passingCards = [[], [], [], []]
#.........这里部分代码省略.........
示例8: Dealer
# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import deal [as 别名]
class Dealer(BaseClass):
"""
A dealer will manage players
and the game, from the point that the game starts
"""
def __init__(self, game, cd_kick):
BaseClass.__init__(self)
self.game = game
self.deck = Deck()
self.current_card = None
self.players = []
self.turn = 0
self.played_time = None
self.timeout = cd_kick
self.turn_direction = 1
self.playing = False
def pick_dealer(self):
max_card_value = 0
max_playerId = 0
for i in xrange(1, len(self.players) + 1):
c = random.choice(self.deck.cards)
if c.is_normal and int(c.value) > max_card_value:
max_card_value = int(c.value)
max_playerId = i
if max_playerId == 0:
max_playerId = random.randrange(1, len(self.players))
return max_playerId
def first_card(self):
card = None
while (not card) or (card.value == 'F') or (card.playerId > 0):
card = random.choice(self.deck.cards)
card.status = 2
return card
def start_game(self, total):
self.deck.deal(total)
self.players = []
for i in xrange(1, total + 1):
p = Player(i, self.deck, self)
self.players.append(p)
p.start_game()
self.turn = self.pick_dealer()
self.current_card = self.first_card()
self.game.com_bc_startgame()
for p in self.players:
self.game.com_s_deal(p.playerId, p.get_cards_str())
self.playing = True
self.game.com_s_go(self.turn, self.current_card.toString())
self.played_time = time.time()
def play(self, playerId, msg):
if not self.playing:
raise NotPlaying()
if self.turn != playerId:
raise NotTurn(playerId)
p = self.by_id(playerId)
p.play(msg)
self.game.com_bc_play(p.playerId, msg)
self.game.com_s_go(self.turn, self.current_card.toString())
if p.is_won():
self.game.com_bc_gg(playerId)
BaseClass.exeEvt(self, 'won', playerId)
if p.is_uno():
self.game.com_bc_uno(playerId)
self.played_time = time.time()
def kick_player(self, playerId):
try:
p = self.by_id(playerId)
except:
print "cant not find player:%d" % playerId
return
if self.turn == playerId:
self.set_turn(1)
p.dispose()
self.players.remove(p)
BaseClass.exeEvt(self, 'kick', playerId)
if len(self.players) == 1: #win
BaseClass.exeEvt(self, 'won', self.players[0].playerId)
def dispose(self):
for p in self.players:
#.........这里部分代码省略.........