From bdfb03d83e470d88d6d292f71eea142ec080d37b Mon Sep 17 00:00:00 2001 From: Lukas Weinwurm Date: Sat, 9 Mar 2013 17:07:22 +0100 Subject: [PATCH 1/3] shows QH instead of queen-hearts --- blackjack.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/blackjack.rb b/blackjack.rb index b6dcda9..0fbd21a 100644 --- a/blackjack.rb +++ b/blackjack.rb @@ -14,7 +14,7 @@ def value end def to_s - "#{@value}-#{suit}" + "#{@value}#{suit}" end end @@ -29,7 +29,7 @@ def initialize def self.build_cards cards = [] - [:clubs, :diamonds, :spades, :hearts].each do |suit| + [:C, :D, :S, :H].each do |suit| (2..10).each do |number| cards << Card.new(suit, number) end @@ -83,7 +83,7 @@ def stand end def status - {:player_cards=> @player_hand.cards, + {:player_cards => @player_hand.cards, :player_value => @player_hand.value, :dealer_cards => @dealer_hand.cards, :dealer_value => @dealer_hand.value, From 49bc5e6ad58494a1fcaae8fe9f1717949c8c3eb1 Mon Sep 17 00:00:00 2001 From: Lukas Weinwurm Date: Sat, 9 Mar 2013 17:41:06 +0100 Subject: [PATCH 2/3] add stand for player if he busts and update test --- blackjack.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/blackjack.rb b/blackjack.rb index 0fbd21a..0cd8146 100644 --- a/blackjack.rb +++ b/blackjack.rb @@ -14,7 +14,7 @@ def value end def to_s - "#{@value}#{suit}" + "#{@value}#{suit.to_s.chars.first.upcase}" end end @@ -29,7 +29,7 @@ def initialize def self.build_cards cards = [] - [:C, :D, :S, :H].each do |suit| + [:clubs, :diamonds, :spades, :hearts].each do |suit| (2..10).each do |number| cards << Card.new(suit, number) end @@ -75,6 +75,12 @@ def initialize def hit @player_hand.hit!(@deck) + if @player_hand.value > 21 + puts "Player busted!" + stand + else + status + end end def stand @@ -135,7 +141,7 @@ def inspect it "should be formatted nicely" do card = Card.new(:diamonds, "A") - card.to_s.should eq("A-diamonds") + card.to_s.should eq("AD") end end From b3e30f023df37f433029ad61746abf2cbe9db9a9 Mon Sep 17 00:00:00 2001 From: Lukas Weinwurm Date: Sat, 9 Mar 2013 18:07:47 +0100 Subject: [PATCH 3/3] adds dealer hand does not show both cards until player stands --- blackjack.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/blackjack.rb b/blackjack.rb index 0cd8146..1ff2ec9 100644 --- a/blackjack.rb +++ b/blackjack.rb @@ -78,8 +78,9 @@ def hit if @player_hand.value > 21 puts "Player busted!" stand + end_status else - status + pre_status end end @@ -88,7 +89,13 @@ def stand @winner = determine_winner(@player_hand.value, @dealer_hand.value) end - def status + def pre_status + { :player_cards => @player_hand.cards, + :player_value => @player_hand.value, + :dealer_cards => @dealer_hand.cards[0] } + end + + def end_status {:player_cards => @player_hand.cards, :player_value => @player_hand.value, :dealer_cards => @dealer_hand.cards, @@ -109,7 +116,7 @@ def determine_winner(player_value, dealer_value) end def inspect - status + pre_status end end