Panda, Tiger, and Eagle level #1

Open
wants to merge 3 commits into
from

Projects

None yet

2 participants

@HerbCSO
HerbCSO commented Aug 5, 2012

I've now done all three levels. However, I don't think the implementation of the Eagle level is really ideal, so I'm hoping to get some better ideas from you or the other commits. ;]

@jwo
Member
jwo commented Aug 6, 2012

Nice job on these.. The eagle is a big tough -- but I'd start with having a DealerHand and a PlayerHand --- and depending on if the player has finished, the DealerHand shows all cards, or a DownCard and Card.

@jwo jwo commented on an outdated diff Aug 6, 2012
@@ -225,6 +228,14 @@ def inspect
game.status[:winner].should_not be_nil
end
+ it "should #stand for the player if they bust" do
+ game = Game.new
+ while game.status[:player_value] < 21
+ game.hit
+ end
+ game.status[:winner].should_not be_nil
@jwo
jwo Aug 6, 2012 Member

This works --- and we didn't cover should_receive and should_not_receive, but I think that could make sense here. Just thoughts for later -- you could assert that the dealer does not receive a message to hit.

@HerbCSO HerbCSO Eagle level completed
I added the Eagle level assignment. Not sure if this is really the most effective
way to do this, so more than happy for better ideas on how to implement, but this
should work.

Also replaced the test for stand for player if they bust with the should_receive
method from rspec  - very cool, thx for pointing that out jwo!
85aece4
@HerbCSO
HerbCSO commented Aug 8, 2012

@jwo, not sure if you saw the update to the Eagle level yet.

@jwo jwo commented on the diff Aug 8, 2012
blackjack.rb
@@ -63,18 +93,35 @@ def play_as_dealer(deck)
end
end
+class PlayerHand < Hand
+end
+
+class DealerHand < Hand
+ def hit!(deck)
+ if @cards.length == 0
+ downcard = deck.cards.shift
+ @cards << DownCard.new(downcard.suit, downcard.value)
+ else
+ @cards << deck.cards.shift
+ end
+ end
+end
+
class Game
attr_reader :player_hand, :dealer_hand
def initialize
@deck = Deck.new
@player_hand = Hand.new
@jwo
jwo Aug 8, 2012 Member

You probably want to use a PlayerHand here (or not have a PlayerHand class)

@jwo jwo commented on an outdated diff Aug 8, 2012
@@ -56,6 +85,7 @@ def value
end
def play_as_dealer(deck)
+ @cards.each { |card| card.game_done }
@jwo
jwo Aug 8, 2012 Member

Since game_done is a "destructive" method, you probably want to signify that with game_done! .. the bang at the end of a method indicates (by convention) that this is unsafe.

@jwo
Member
jwo commented Aug 8, 2012

Great job! Looks good -- I added some comments, but your code got the job done and looks good to maintain.

@HerbCSO
HerbCSO commented Aug 8, 2012

Thanks @jwo - I decided to remove PlayerHand since it wasn't really needed anymore and I changed #game_done to #game_done! - forgot the convention there, thanks!

I'm looking forward to seeing more elegant solutions than mine. ;]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment