The limitations so far are that I have not written logic in order to turn an Ace into an 11 or 1 given the circumstance, which should not be too difficult but I have to be up at 4:45am tomorrow so I am running out of time. I also want if the player draws a 21 in the initial hand for the game to be immediately over, but I feel that I will have to put the whole thing in a while loop with a break if statement in order for this to work correctly. I will get back to this...Enjoy for now!
- puts ' '
- puts "So you want to play Blackjack?"
- # Part 0__________________________________
- # Build array of cards to make a full deck
- one_suit = [2,3,4,5,6,7,8,9,10,10,10,10,11];
- full_deck = one_suit*4;
- deck = full_deck.dup;
- # Part 1_____________________________________________
- # Shuffle: Where the deck is shuffled before starting
- new_deck = deck.shuffle
- # Part 2_________________________________________________________________
- # Initial Deal: Where cards are initially dealt to both Player and Dealer
- player_initial_hand = new_deck[51] + new_deck[50]
- dealer_initial_hand = new_deck[49] + new_deck[48]
- puts ' '
- puts "Your hand: #{new_deck[51]}, #{new_deck[50]} = #{player_initial_hand}"
- new_deck.pop
- new_deck.pop
- new_deck.pop
- new_deck.pop
- # Part 3_________________________________________________________
- # Player's turn: Decided to hit or stay via interactive get.chomp
- puts "Would you like to hit or stay?"
- until gets.chomp == "stay"
- player_initial_hand += new_deck.last
- new_deck.pop
- puts "Hand = #{player_initial_hand}. Would you like to hit or stay?"
- end
- puts ' '
- puts "Players's final hand: #{player_initial_hand}"
- # Part 4____________________________________________________________________________
- # Dealer's turn: Hits or stays based on casino rules of hitting on anything below 15
- until dealer_initial_hand >= 15
- dealer_initial_hand += new_deck.last
- new_deck.pop
- end
- puts "Dealer's final hand: #{dealer_initial_hand}"
- puts ' '
- # Part 5______________________________________________________________________
- # Evaluation: This will use boolean logic to see if player or dealer wins game
- if player_initial_hand == 21
- puts "#{player_initial_hand}"
- puts "BLACKJACK, You Win!"
- elsif player_initial_hand <= 21 && player_initial_hand > dealer_initial_hand && dealer_initial_hand <=21
- puts "#{player_initial_hand}, vs. #{dealer_initial_hand}"
- puts "You win!"
- elsif player_initial_hand == dealer_initial_hand
- puts "#{player_initial_hand}, vs. #{dealer_initial_hand}"
- puts "Draw"
- elsif player_initial_hand <= 21 && player_initial_hand < dealer_initial_hand && dealer_initial_hand <=21
- puts "#{player_initial_hand}, vs. #{dealer_initial_hand}"
- puts "You lose"
- elsif player_initial_hand <= 21 && dealer_initial_hand > 21
- puts "#{player_initial_hand}, vs. #{dealer_initial_hand}"
- puts "Dealer Bust, You Win!"
- else player_initial_hand > 21
- puts "#{player_initial_hand}, vs. #{dealer_initial_hand}"
- puts "BUST! You Lose."
- end
- # The End
No comments:
Post a Comment