-
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
Karinna & Angelica - Scrabble - Octos #9
base: master
Are you sure you want to change the base?
Conversation
…ethods, and got tests to pass.
ScrabbleWhat We're Looking For
Good job overall! The big learning goals I'm looking to see demonstrated on this project are:
I feel that you've done a good job of demonstrating all three of these. Your test coverage could use some work - several of your methods are missing interesting cases - but it seems like you're on the right track. I've left some inline comments for you to review, please do so, and keep up the hard work! |
|
||
LETTER_SCORES = { "a" => 1,"b" => 3,"c" => 3,"d" => 2,"e" => 1,"f" => 4,"g" => 2,"h" => 4, | ||
"i" => 1,"j" => 8,"k" => 5, "l" => 1,"m" => 3,"n" => 1,"o" => 1,"p" => 3, | ||
"q" => 10, "r" => 1, "s" => 1, "t" => 1, "u" => 1, "v" => 4, "w" => 4, |
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.
I like this choice of data structure.
LETTER_SCORES[letter] | ||
end | ||
|
||
points = score_array.inject(points,:+) |
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.
Excellent use of map
and inject
in this method.
hashes_array = self.get_hashes(array_of_words) | ||
winner_score = self.get_winner_score(hashes_array) | ||
hashes_array = self.get_winner_hashes(hashes_array, winner_score) | ||
seven_letters = self.seven_letters(hashes_array) |
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.
I love the idea of breaking the pieces of this out into separate methods. However, in this case I think I agree that you may have gone a little too far, in that each of the components is so far removed from the others that it's hard to see the pattern. This would make it difficult to refactor if, for example, you wanted to switch to the inline tie-breaking style we did in class.
That being said, I definitely don't want to discourage functional decomposition. This is still way more readable than one enormous method. Figuring out where to draw the line is a bit of an art form.
return false | ||
elsif score.nil? | ||
return 0 | ||
else |
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 job catching this behavior.
def won? | ||
if self.total_score > 100 | ||
return true | ||
else |
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.
Since >
will always return true
or false
, this could be shortened to:
def won?
return total_score > 100
end
|
||
def draw_tiles(num) | ||
|
||
available = @total_tiles.select do |tile, quant| |
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.
By this logic, you're as likely to draw an e
as you are a z
! It also means that you won't ever get more than one of the same letter, which could be bad if you need to draw the last two tiles from the bag and they're both i
. However, the way you've set up your data structures, it would be difficult to do it any other way.
Instead, you might keep all the letters in the bag in an array. You could seed the array with code like:
def initialize
letters = {
# the hash you had before
}
@tiles = []
letters.each do |letter, count|
count.times do
@tiles << letter
end
end
end
Then you could pull a random tile with sample
and get a nice even distribution.
|
||
describe '#won?' do | ||
|
||
it "returns false if the player does not have over 100 points" do |
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.
I would like to see more precision around the "edge" between winning and not winning. What happens if the player has:
- 99 points
- 100 points
- 101 points
end | ||
|
||
it 'returns the highest word if there are two words' do | ||
words = ['cat', 'house'] | ||
Scrabble::Scoring.highest_score_from(words).must_equal 'house' | ||
end |
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.
Like we discussed in class, it would probably be wise to check multiple orderings of these words, that is, both ['dog', 'fish']
and ['fish', 'dog']
. You'd be surprised how often this sort of thing turns up a bug.
it "Sets up instance with a collection of tiles" do | ||
new_pool = Scrabble::TileBag.new | ||
quantities = { "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 } | ||
new_pool.total_tiles.must_equal quantities |
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.
I don't know that I like this test - seems like you're just copying the data that you have in tile_bag.rb. That means it's not likely to find a bug, and if that data ever changes (Scrabble rules change or you do find a bug) you'll have to make the update in more than one place.
Instead, it might be better in this case to test less. Maybe check that you get the right number of tiles and leave it at that.
|
||
it "raises an argument error if the user tries to take more tiles than are available" do | ||
new_bag = Scrabble::TileBag.new | ||
result = proc { new_bag.draw_tiles(100) } |
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.
I like this test! Good work!
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?