b5453b97 by Barry

Bug fix for alises using unicode.

Lots of fixes for blackjack
1 parent 91ac8517
......@@ -46,21 +46,22 @@ class Deck:
self.shuffle(number_of_decks)
def shuffle(self, number_of_decks):
self.cards = []
self.draw_pile = []
for d in range(number_of_decks):
for suit in SUITS:
for card in CARDS:
self.cards.append(card + suit)
self.draw_pile.append(card + suit)
def draw(self,number_of_cards=1):
def draw(self, number_of_cards=1):
drawn_cards = []
for n in range(number_of_cards):
choice = randrange(0,len(self.cards))
drawn_cards.append(self.cards.pop(choice))
print("CARDS LEFT: {}".format(self.cards_left()))
choice = randrange(0, len(self.draw_pile))
drawn_cards.append(self.draw_pile.pop(choice))
return drawn_cards
def cards_left(self):
return len(self.cards)
return len(self.draw_pile)
class Blackjack:
def __init__(self, bet):
......@@ -78,6 +79,13 @@ class Blackjack:
self.dealer_points = self.dealer_hand.get_points()
#print("Dealer: {}".format(dealer_points,))
def draw(self):
self.player_hand.add_cards(self.deck.draw(1))
def dealer_draw(self):
while self.player_hand.get_points() <= 21 and (self.dealer_hand.get_points() < 17 or self.dealer_hand.get_points() < self.player_hand.get_points()):
self.dealer_hand.add_cards(self.deck.draw(1))
def is_busted(self):
if self.player_points > 21:
return 1
......@@ -87,9 +95,17 @@ class Blackjack:
return 0
def is_win(self):
self.dealer_draw()
self.dealer_points = self.dealer_hand.get_points()
self.player_points = self.player_hand.get_points()
# TODO: Check for blackjack Ace + 10 pt
if self.player_hand.is_blackjack() and not self.dealer_hand.is_blackjack():
if self.player_points > 21:
return (-self.bet, 'You Bust: {}')
elif self.player_hand.is_blackjack() and not self.dealer_hand.is_blackjack():
return (self.bet + self.bet * 1.5, 'Blackjack, you win: {}')
elif self.dealer_points > 21:
return (self.bet * 2, 'Dealer Busts: {}')
elif self.dealer_hand.is_blackjack():
return (-self.bet, 'You lose: {}')
elif self.player_points > self.dealer_points:
......@@ -99,20 +115,53 @@ class Blackjack:
else:
return (-self.bet, 'You lose: {}')
def print_hand(self):
dealers = ' '.join(self.dealer_hand.get_cards()[1:])
print("Dealer's Hand: {}".format(dealers))
def print_hand(self, show_dealer=False):
if show_dealer:
dealers = ' '.join(self.dealer_hand.get_cards())
print("Dealer's Hand: {} for {} points".format(dealers, self.dealer_hand.get_points()))
else:
dealers = ' '.join(self.dealer_hand.get_cards()[1:])
print("Dealer's Hand: {}".format(dealers))
self.player_points = self.player_hand.get_points()
print("Player's Hand: {} for {} points".format(' '.join(self.player_hand.get_cards()), self.player_hand.get_points()))
def get_actions(self):
points = self.player_hand.get_points()
cards = self.player_hand.get_cards()
actions = []
if self.player_hand.is_blackjack():
pass
elif points < 21 and not self.is_busted() == 2:
actions.append('hit')
actions.append('stand')
actions.append('double')
elif len(cards) == 2:
if cards[0][0] == cards[1][0]:
actions.append('split')
return actions
print("Player's Hand: {} for {} points".format(' '.join(self.player_hand.get_cards()), self.player_points))
bet = 10
bj = Blackjack(bet)
bj.print_hand()
busted = bj.is_busted()
if busted == 1:
print("YOU BUST")
elif busted == 2:
print("Dealer Busts, YOU WIN!")
else:
win, response = bj.is_win()
print(response.format(win,))
actions = bj.get_actions()
done = False
while len(actions) > 0:
action = raw_input('Please choose an option [{}]'.format(', '.join(actions)))
if action == 'stand':
break
elif action == 'hit':
bj.draw()
bj.print_hand()
actions = bj.get_actions()
win, response = bj.is_win()
print('\n')
bj.print_hand(show_dealer=True)
print('\n')
print(response.format(win,))
......
No preview for this file type
......@@ -514,7 +514,7 @@ Stuff:
if member:
aliases = db_get_aliases(member['member_id'])
if aliases:
client.send_message(message.channel, '{} has the following aliases: {}'.format(username, ', '.join(aliases)))
client.send_message(message.channel, '{} has the following aliases: {}'.format(username, byteify(', '.join(aliases))))
else:
client.send_message(message.channel, 'No known alises for {} yet {}'.format(username, message.author.mention()))
else:
......@@ -527,7 +527,7 @@ Stuff:
member = db_get_member(username=username)
if member:
db_add_aliases(member['member_id'], alias)
client.send_message(message.channel, '{} has been added to your aliases'.format(alias))
client.send_message(message.channel, '{} has been added to your aliases'.format(byteify(alias)))
else:
client.send_message(message.channel, 'Something horrible happened and it is all your fault, try logging out / on again or play a game. (or fuck off i dunno i\'m just an error message. Who am I to tell you how to run your life...)')
return
......