本文整理汇总了Python中hand.Hand.add方法的典型用法代码示例。如果您正苦于以下问题:Python Hand.add方法的具体用法?Python Hand.add怎么用?Python Hand.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hand.Hand
的用法示例。
在下文中一共展示了Hand.add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_three_of_a_kind
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add [as 别名]
def test_three_of_a_kind(self):
deck = Deck()
deck.get_new_deck()
community_cards = []
community_cards.append (Card('2', 'D'))
community_cards.append (Card('2', 'C'))
community_cards.append (Card('4', 'D'))
my_hand = Hand(community_cards)
my_hand.add (Card('2', 'S'))
my_hand.add (Card('6', 'D'))
assert my_hand.three_of_a_kind() and not my_hand.one_pair()
示例2: test_one_pair
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add [as 别名]
def test_one_pair(self):
deck = Deck()
deck.get_new_deck()
community_cards = []
community_cards.append (Card('2', 'D'))
community_cards.append (Card('3', 'D'))
community_cards.append (Card('4', 'D'))
my_hand = Hand(community_cards)
my_hand.add (Card('2', 'S'))
my_hand.add (Card('6', 'D'))
assert my_hand.one_pair() and not my_hand.is_flush()
示例3: test_straight_flash
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add [as 别名]
def test_straight_flash(self):
deck = Deck()
deck.get_new_deck()
community_cards = []
community_cards.append (deck.deal())
community_cards.append (deck.deal())
community_cards.append (Card('2', 'D'))
community_cards.append (Card('3', 'D'))
community_cards.append (Card('4', 'D'))
my_hand = Hand(community_cards)
my_hand.add (Card('5', 'D'))
my_hand.add (Card('6', 'D'))
assert my_hand.is_straight() and my_hand.is_flush()
示例4: test_flushes2
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add [as 别名]
def test_flushes2(self):
deck = Deck()
deck.get_new_deck()
community_cards = []
community_cards.append (deck.deal())
community_cards.append (deck.deal())
community_cards.append (Card('2', 'D'))
community_cards.append (Card('3', 'D'))
community_cards.append (Card('4', 'D'))
my_hand = Hand(community_cards)
my_hand.add (Card('T', 'D'))
my_hand.add (Card('J', 'D'))
assert my_hand.is_flush()
示例5: Player
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add [as 别名]
class Player(object):
score = 0
num_wins = 0
def __init__(self, name="", ai=True):
self.name = name
self.hand = Hand()
self.live = True
self.busted = False
self.ai = ai
def optimize(self):
# Optimize Ace value for player score
for card in self.hand.cards:
if self.score > 21:
if card.value == 11:
card.value = 1
self.score -= 10
def draw_card(self, card):
self.hand.add(card)
self.score += card.value
self.optimize()
if self.score > 21:
self.live = False
def get_card(self, index):
card = self.hand.cards[index]
return card
def gen_name(self):
# Use names.txt to generate random AI name
line = random.randint(100, 4000)
self.name = linecache.getline('names.txt', line)
self.name = self.name.split()[0]
def hit(self, max_val, live_players):
# Human determines decision
if not self.ai:
choice = raw_input("{0}, do you want a hit? (yes/no): ".format(self.name))
if choice in ("yes", "y", "yeah", "yea"):
return True
elif choice in("no", "n", "nope"):
return False
else:
return hit(self, max_val, live_players)
# AI determines decision
else:
# In lead
if self.score == max_val:
if self.score >= 19:
return False
else:
return True
# Not in lead
else:
if self.score < 11:
return True
if self.score < 18:
hit_chance = random.randint(0, 5)
if hit_chance > 1:
return True
else:
return False
else:
return False
示例6: Deck
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add [as 别名]
count_my_one_pair = 0
count_my_hand_strength = 0
deck = Deck()
for i in xrange(int(total)):
deck.get_new_deck()
community_cards = []
community_cards.append (community_cards1 or deck.deal())
community_cards.append (community_cards2 or deck.deal())
community_cards.append (community_cards3 or deck.deal())
community_cards.append (community_cards4 or deck.deal())
community_cards.append (community_cards5 or deck.deal())
my_hand = Hand(community_cards)
my_hand.add (my_cards1)
my_hand.add (my_cards2)
if my_hand.is_flush(): count_my_flushes += 1.0
if my_hand.is_straight(): count_my_straights += 1.0
if my_hand.four_of_a_kind(): count_my_four_of_a_kind += 1.0
if my_hand.three_of_a_kind(): count_my_three_of_a_kind += 1.0
if my_hand.one_pair(): count_my_one_pair += 1.0
count_my_hand_strength += my_hand.get_strength()
count_their_straights = 0
count_their_flushes = 0
count_their_four_of_a_kind = 0
count_their_three_of_a_kind = 0
count_their_one_pair = 0
count_their_hand_strength = 0
示例7: Player
# 需要导入模块: from hand import Hand [as 别名]
# 或者: from hand.Hand import add [as 别名]
class Player(object):
def __init__(self):
self.topHand = Hand()
self.midHand = Hand()
self.botHand = Hand()
def addTop(self, card):
if len(self.topHand) >=3:
raise OFCError('This hand is full!')
return
self.topHand.add(card)
def addMid(self, card):
if len(self.midHand) >= 5:
raise OFCError('This hand is full!')
return
self.midHand.add(card)
def addBot(self, card):
if len(self.botHand) >= 5:
raise OFCError('This hand is full!')
return
self.botHand.add(card)
def fullHands(self):
return len(self.botHand) == 5 and len(self.midHand) == 5 and len(self.topHand) == 3
def printStatus(self):
print ("Top Hand: ")
self.topHand.printHand()
print ("\n\nMiddle Hand: ")
self.midHand.printHand()
print ("\n\nBottom Hand: ")
self.botHand.printHand()
def addCard(self, card, hand):
if hand == 1:
self.addBot(card)
elif hand == 2:
self.addMid(card)
elif hand == 3:
self.addTop(card)
def playManual(self, deck):
nextCard = deck.pop()
print "\nthe current card is " + nextCard.value
choice = raw_input("where would you like this card?\nplease enter bot or 1 for bottom,\nmid or 2 for middle, top or 3 for top\n--> ")
if choice == "1" or choice == "bot":
try:
self.addBot(nextCard)
except OFCError:
print("that hand is full! try again")
deck.heap(nextCard)
self.playManual(deck)
elif choice == "2" or choice == "mid":
try:
self.addMid(nextCard)
except OFCError:
print("that hand is full! try again")
deck.heap(nextCard)
self.playManual(deck)
elif choice == "3" or choice == "top":
try:
self.addTop(nextCard)
except OFCError:
print("that hand is full! try again")
deck.heap(nextCard)
self.playManual(deck)
else:
print "that choice was not recognized!"
deck.heap(nextCard)
def playRandom(self, card):
spaces = []
for i in range(5 - len(self.botHand)):
spaces.append(1)
for i in range(5 - len(self.midHand)):
spaces.append(2)
for i in range(3 - len(self.topHand)):
spaces.append(3)
if len(spaces) == 0:
raise OFCError("No empty spaces!")
else:
choice = random.choice(spaces)
self.addCard(card, choice)