|
print"BackJack!\n\n" print " 1 = Yes. 2 = No. Max Bet Is 250. Got It? \n\n" def shuffle return DECK.sort_by {rand} end
def decode_suit_name(a_num)
which_suit = (a_num - 1) / 13 suit_name = SUITS[which_suit] return suit_name end
def decode_value_name(a_num) which_value = (a_num - 1) % 13 value_name = VALUES[which_value] return value_name end
CARD_VALUES = ["ACE", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"] CARD_SUITS = ["Spades", "Hearts", "Clubs", "Diamonds"]
DECK = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,3 0,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52] my_deck = shuffle yourpot = 1000 comppot = 1000 card1 = CARD_VALUES[(my_deck[0] - 1) % 13] suit1 = CARD_SUITS[(my_deck[0] - 1) / 13]
card2 = CARD_VALUES[(my_deck[1] - 1) % 13] suit2 = CARD_SUITS[(my_deck[1] - 1) / 13]
card3 = CARD_VALUES[(my_deck[2] - 1) % 13] suit3 = CARD_SUITS[(my_deck[2] - 1) / 13]
card4 = CARD_VALUES[(my_deck[3] - 1) % 13] suit4 = CARD_SUITS[(my_deck[3] - 1) / 13]
while yourpot and comppot != 0 my_deck = shuffle
#card 1 if card1 == "ACE" x1 = 11 elsif card1 == "2" x1 = 2 elsif card1 == "3" x1 = 3 elsif card1 == "4" x1 = 4
elsif card1 == "5" x1 = 5 elsif card1 == "6" x1 = 6
elsif card1 == "7" x1 = 7 elsif card1 == "8" x1 = 8 elsif card1 == "9" x1 = 9
elsif card1 == "10" x1 = 10 else x1 = 10 end #card 2
if card2 == "ACE" x2 = 11 elsif card1 == "ACE" and card2 == "ACE" x2 = 1 elsif x1 == 11 and x2 == 11 x2 = 1
elsif card2 == "2" x2 = 2 elsif card2 == "3" x2 = 3 elsif card2 == "4" x2 = 4
elsif card2 == "5" x2 = 5 elsif card2 == "6" x2 = 6
elsif card2 == "7" x2 = 7 elsif card2 == "8" x2 = 8 elsif card2 == "9" x2 = 9
elsif card2 == "10" x2 = 10 else x2 = 10 end total = x1 + x2 #card 3 if card3 == "ACE" x3 = 11 elsif total > 10 and x3 == 11 x3 = 1
elsif card3 == "2" x3 = 2 elsif card3 == "3" x3 = 3 elsif card3 == "4" x3 = 4
elsif card3 == "5" x3 = 5 elsif card3 == "6" x3 = 6
elsif card3 == "7" x3 = 7 elsif card3 == "8" x3 = 8 elsif card3 == "9" x3 = 9
elsif card3 == "10" x3 = 10 else x3 = 10 end #card 4 if card4 == "ACE" x4 = 1 elsif card4 == "2" x4 = 2 elsif card4 == "3" x4 = 3 elsif card4 == "4" x4 = 4
elsif card4 == "5" x4 = 5 elsif card4 == "6" x4 = 6
elsif card4 == "7" x4 = 7 elsif card4 == "8" x4 = 8 elsif card4 == "9" x4 = 9
elsif card4 == "10" x4 = 10 else x4 = 10 end total = x1 + x2 print"\nYou Have #{yourpot} Chips\n\n\n The Dealer Has #{comppot} Chips\n\n\n How Many Chips Do You Want To Bet On This Hand? :\n\n" bet = gets.to_i if bet > 250 print"Thats Over The House Betting Max\n\n" next end if bet > yourpot print"You Don't Have That Many Chips!\n\n" next end compbet = bet if comppot < bet print"Computer Is All In\n" compbet = comppot
end
pot = bet + compbet yourpot = yourpot - bet comppot = comppot - bet print "Dealt A #{card1} Of #{suit1} And #{card2} Of #{suit2}\n\n\n Total = #{total}\n\n" if total == 21 print"You Win Perfect Blackjack!\n\n\n" yourpot = yourpot + pot end print "\nDo You Want A Hit? :\n\n\n" hit = gets.to_f
if hit == 1 total = total + x3 print "You Now Have A #{card3} Of #{suit3},\n\n#{card1} Of #{suit1} And #{card2} Of #{suit2}\n\n\n Total = #{total}\n\n" elsif total > 21 print "\nYou Lose Hand ... You Busted!\n\n" comppot = comppot + pot next print"Do You Want Another Hit? :\n\n" hit2 = gets.to_i elsif hit2 == 1 print"You Were Dealt A #{card4} Of #{suit4}\n\n" total = total + x4 print "You Now Have A #{card4} Of #{suit4},\n\n #{card3} Of #{suit3},#{card1} Of #{suit1} And #{card2} Of #{suit2}\n\n\n Total = #{total}\n\n" elsif total > 21 print "\nYou Lose Hand ... You Busted\n\n" comppot = comppot + pot next end
compcard1 = CARD_VALUES[(my_deck[5] - 1) % 13] compsuit1 = CARD_SUITS[(my_deck[5] - 1) / 13]
compcard2 = CARD_VALUES[(my_deck[6] - 1) % 13] compsuit2 = CARD_SUITS[(my_deck[6] - 1) / 13]
compcard3 = CARD_VALUES[(my_deck[7] - 1) % 13] compsuit3 = CARD_SUITS[(my_deck[7] - 1) / 13] #1 if compcard1 == "ACE" y1 = 11 elsif compcard1 == "2" y1 = 2 elsif compcard1 == "3" y1 = 3 elsif compcard1 == "4" y1 = 4
elsif compcard1 == "5" y1 = 5 elsif compcard1 == "6" y1 = 6
elsif compcard1 == "7" y1 = 7 elsif compcard1 == "8" y1 = 8 elsif compcard1 == "9" y1 = 9
elsif compcard1 == "10" y1 = 10 else y1 = 10 end #2 if compcard2 == "ACE" y2 = 11 elsif compcard1 == "ACE" and card2 == "ACE" y2 = 1 elsif y1 == 11 and y2 == 11 y2 = 1
elsif compcard2 == "2" y2 = 2 elsif compcard2 == "3" y2 = 3 elsif compcard2 == "4" y2 = 4
elsif compcard2 == "5" y2 = 5 elsif compcard2 == "6" y2 = 6
elsif compcard2 == "7" y2 = 7 elsif compcard2 == "8" y2 = 8 elsif compcard2 == "9" y2 = 9
elsif compcard2 == "10" y2 = 10 else y2 = 10 end total = x1 + x2 #3 if card3 == "ACE" y3 = 11 elsif total > 10 and y3 == 11 y3 = 1
elsif compcard3 == "2" y3 = 2 elsif compcard3 == "3" y3 = 3 elsif compcard3 == "4" y3 = 4
elsif compcard3 == "5" y3 = 5 elsif compcard3 == "6" y3 = 6
elsif compcard3 == "7" y3 = 7 elsif compcard3 == "8" y3 = 8 elsif compcard3 == "9" y3 = 9
elsif compcard3 == "10" y3 = 10 else y3 = 10 end comptotal = y1 + y2 print"The Dealer Has A #{compcard1} Of #{compsuit1},\n\n And #{compcard2} Of #{compsuit2}\n\n Total = #{comptotal}\n\n"
if comptotal < 17 comptotal = comptotal + y3 print"The Dealer Has Took A Hit\n\n And Got A #{compcard3} Of #{compsuit3}\n\n\n" print"the Dealer's Total Is Now #{comptotal}\n\n\n" end if total > comptotal and total < 22 winner = "You" elsif comptotal == total comppot = comppot + (pot / 2) yourpot = yourpot + (pot / 2) print "You Tied, So You Split The Pot\n\n" next else winner = "The Dealer!\n" end if winner == "You!\n" yourpot = yourpot + pot elsif winner == "The Dealer!\n" comppot = comppot + pot end print"\nWinner Is #{winner}\n\n" if comppot == 0 print "\n\nYou Won All The Chips, You Beat Dealer! Good Job!!\n\n" break end
still some kinks but play it! :] end
|