joncodo / Crib

A crib engine to play the card game crib with AI and a card counter
3 stars 2 forks source link

game.rb: Code Review #10

Closed scott-steadman closed 10 years ago

scott-steadman commented 10 years ago

I haven't played cribbage in a while, so take my comments lightly.

scott-steadman commented 10 years ago

You may want to make the attributes read-only. Reason: To prevent accidental modification of the attributes.

Example code:

attr_reader :player1, :player2, :deck, :crib

def initialize
  @deck    = Deck.new
  @player1 = Player.new
  @player2 = Player.new
  @crib    = []
end
scott-steadman commented 10 years ago

in start_round method have players draw from deck. Reason: improve readability, and get rid of temporary variable.

Example code:

def start_round
  6.times do
    player1.draw_from(deck)
    player2.draw_from(deck)
  end
end
joncodo commented 10 years ago

Great idea. I can't wait to do all of this Friday night. Maybe have a look again on Sunday night?

scott-steadman commented 10 years ago

Sure! I'll watch the repo so I know when you've pushed your changes.

scott-steadman commented 10 years ago

Have score method return a string. Reason: you may not want to write the score to stdout.

Example code:

def score
  ["Player1 Score: #{player1.score}", "Player2 Score: #{player2.score}"].join("\n")
end

Another option would be to have score take a destination as a parameter. Reason: you can tell the method where to write the output, and let it handle formatting...

def write_score(io=STDOUT)
  io.puts "Player1 Score: #{player1.score}"
  io.puts "Player2 Score: #{player2.score}"
end