Skip to content

BlackJack Assignment submission. #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

codeblahblah
Copy link

@jwo After changing the Card's to_s to show "QH" instead of queen-hearts"....
Should we change the Game#status to make @player_hand.cards and @delaer_hand.cards more readable?

@jwo
Copy link
Member

jwo commented Feb 20, 2014

Initial code looks fine, no issues there.

Should we change the Game#status to make @player_hand.cards and @delaer_hand.cards more readable?

I think it should return data; if you want to have a method, or a class, that formats it nicely, I think that's a good addition to the project.

@codeblahblah
Copy link
Author

@jwo Okay. Will add that to the wishlist.
I'm stuck here : "If a player busts (goes over 21), the game should #standfor the player."
Should I be looking aroung Game#hit ?

@jwo
Copy link
Member

jwo commented Feb 21, 2014

Try on the player-hand.. if it's over 21 and hits, that's an exception and it shouldn't grab a card.

@codeblahblah
Copy link
Author

@jwo I did this:

  def hit
   if @player_hand.value > 21
     stand
     puts "You bust! Dealer wins."
    else
      @player_hand.hit!(@deck)
    end
  end

I only got this far for the test case as I do not understand how you to make method call on a mock object which will change the properties thereof.

it "should stand for a player if he/she busts" do
      deck = double(:deck, :cards => [Card.new(:spades, 10), Card.new(:clubs, 9), Card.new(:clubs, 8), Card.new(:diamonds, 9), Card.new(:hearts, 6)])
      dealer_hand = Hand.new
      player_hand = Hand.new
      game = double(:game,
        :deck => deck,
        :player_hand => player_hand,
        :dealer_hand => dealer_hand )
      2.times { player_hand.hit!(deck) }
      2.times { dealer_hand.hit!(deck) }
      game.stub(:hit)
      player_hand.hit!(deck)
    end

@jwo
Copy link
Member

jwo commented Feb 25, 2014

Use a real Game object, with a mock card object.

At some point, the objects must be real.

@codeblahblah
Copy link
Author

@jwo Understood. However, the Game object comes with a randomised Deck object which I cannot change/set to suit this specific scenario?

@jwo
Copy link
Member

jwo commented Feb 25, 2014

although that's the idea, set the game's deck to something where you have the cards predetermined.

On Tue, Feb 25, 2014 at 10:16 AM, drammopo [email protected]
wrote:

@jwo Understood. However, the Game object comes with a randomised Deck object which I cannot change/set to suit this specific scenario?

Reply to this email directly or view it on GitHub:
#40 (comment)

@codeblahblah
Copy link
Author

@jwo There's no setter method - only @deck = Deck.new...should I create a backdoor just for testing?

@jwo
Copy link
Member

jwo commented Feb 25, 2014

With the following class:

class Deck

  attr_reader :cards
  def initialize
    @cards = 1..52 #build cards
  end
end

You could do:

describe Deck do
  it "has cards" do
    the_cards = [double, double]
    deck = Deck.new
    deck.stub(:cards) { the_cards}
    expect(deck.cards).to eq(the_cards)
  end
end

So, you're stubbing the #cards method on deck and forcing it to return a known state.

This only works if you are diligent in only using attr_reader methods and not @cards variables

@jwo
Copy link
Member

jwo commented Feb 25, 2014

(then you would pass in your Deck to Game, and you know what happens)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants