-
Notifications
You must be signed in to change notification settings - Fork 26
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
Ampers: Mary, Alex #13
base: master
Are you sure you want to change the base?
Conversation
ScrabbleWhat We're Looking For
|
module Scrabble | ||
class Scoring | ||
attr_reader :word, :letter | ||
|
||
@@letters_hash = { ["a", "e", "i", "o", "u", "l", "n", "r", "s", "t"] => 1, ["d", "g"] => 2, ["b", "c", "m", "p"] => 3, ["f", "h", "v", "w", "y"] => 4, ["k"] => 5, ["j", "x"] => 8, ["q", "z"] => 10 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good data structure for this, but it probably doesn't need to be a class variable. A constant would be a better choice.
module Scrabble | ||
class Scoring | ||
attr_reader :word, :letter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have an attr_reader
here? You will never create an instance of Scoring
It only has class methods!
score << @letter | ||
end | ||
|
||
return score.length == 7 ? score.sum + 50 : score.sum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good use of a ternary
it 'returns the highest word if there are two words' do | ||
end | ||
it 'returns the highest word if there are two words' do | ||
Scrabble::Scoring.highest_score_from(["dog", "quail"]).must_equal "quail" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also vary the order here to make sure.
Scrabble::Scoring.highest_score_from(["quail", "dog"]).must_equal "quail"
specs/scoring_spec.rb
Outdated
|
||
it 'if tied, prefer a word with 7 letters' do | ||
Scrabble::Scoring.highest_score_from(["aaaaaaa", "ggge"]).must_equal "aaaaaaa" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
lib/tilebag.rb
Outdated
attr_accessor :tilebag | ||
|
||
def initialize | ||
@tilebag = { "a" => 9, "b" => 2, "c" => 2, "d" => 4, "e" => 12, "f" => 2, "g" => 3, "h" => 2, "i" => 9, "j" => 1, "k" => 1, "l" => 4, "m" => 2, "n" => 6, "o" => 8, "p" => 2, "q" => 1, "r" => 6, "s" => 4, "t" => 6, "u" => 4, "v" => 2, "w" => 2, "x" => 1, "y" => 2, "z" => 1 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're giving each letter an equal chance of being drawn with this data structure, but there are 12 "E" tiles and only 1 "J".
lib/tilebag.rb
Outdated
hand = [] | ||
num.times do | ||
letter = @tilebag.keys.sample | ||
@tilebag[letter] = @tilebag[letter] - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could continually draw down the number of a specific tile into the negatives.
lib/tilebag.rb
Outdated
letter = @tilebag.keys.sample | ||
@tilebag[letter] = @tilebag[letter] - 1 | ||
if @tilebag[letter] < 1 | ||
letter = @tilebag.keys.sample |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't guarantee that a letter out of tiles won't be drawn. You need to rethink your data structure here.
specs/tilebag_spec.rb
Outdated
it 'has a collection of all tiles' do | ||
new_bag = Scrabble::TileBag.new | ||
new_bag.must_be_instance_of Scrabble::TileBag | ||
new_bag.tilebag.length.must_equal 26 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to test the internal structure of the Tilebag
as a user you don't care that the TileBag
has a hash attribute, in fact that shouldn't even be accessible to you. Instead you should test the tiles_remaining
method and the other methods listed in the requirements.
specs/tilebag_spec.rb
Outdated
end | ||
|
||
it 'removes drawn tiles from tile bag' do | ||
old_total = @bag.tilebag.values.sum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also test that you can't draw more tiles out of the bag than exist.
Scrabble
Congratulations! You're submitting your assignment.
Comprehension Questions
score
method in theScoring
class a class method instead of an instance method?Enumerable
mixin? If so, where and why was it helpful?