#TODO: rules: # dealer stands on all 17s or dealer hits soft 17 # number of dekcs # double any two cards, double 9, 10, 11 only, double 10, 11 only # double after split alloweed # no surrender, late surrender, early surrender # hole card rule: united states (obo, original bets only), # eurpose (enhc, european no hole card) # australia (obbo, original & busted bets only) # http://www.blackjackinfo.com/blackjack-rules.php import random decks = 4 maxsplits = 3 deck = ["a", 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]*4 class hand: def __init__(self,*cards): self.hand = [x for x in cards] self.doubledown = False self.bet = bet def hit(): self.hand.append(nextcard()) def stand(): pass def double(): self.bet=bet*2 self.hit() self.doubledown = True def split(): global hands self.hand=[self.hand[0], nextcard()] hands.append(newhand(self.hand[1], nextcard())) def surrender(): pass def nextcard(): a = random.choice(stack) stack.remove(a) return a def shuffle(): global stack stack = deck*decks def newgame(newbet): global hands, dealerhand, splits, bet shuffle() hands = [] dealerhand=[nextcard(),nextcard()] bet=newbet hands.append(hand(nextcard(), nextcard())) def checkgame(): dealertotal=0 ace=False if dealerhand.count("a")>=1: dealertotal=dealertotal+dealerhand.count("a")-1 ace=True dealertotal=dealertotal+reduce(lambda a, b: a+b, filter(lambda a: a!="a",dealerhand)) if ace and dealertotal>10: ace=False dealertotal=dealertotal+1 if ace and dealertotal==10: dealerstatus="blackjack" elif dealertotal>21: dealerstatus="bust" elif dealertotal==21: dealerstatus="21" elif dealertotal>=17: dealerstatus="17+" else: dealerstatus="16-" playerstatus = [] for hand in hands: handtotal=0 ace=False if hand.count("a")>=1: handtotal=handtotal+hand.count("a")-1 ace=True handtotal=handtotal+reduce(lambda a, b: a+b, filter(lambda a: a!="a",hand)) playerstatus.append(handtotal, ace) return dealerstatus, playerstatus def hitdealer(): global dealerhand dealerhand.append(nextcard()) newgame(10) #Richard Albert Nichols III (http://www/gate.net/~inhahe)