-
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
Ana Lisa & Jamila: Octos-C9 #21
base: master
Are you sure you want to change the base?
Conversation
ScrabbleWhat We're Looking For
The big learning goals I'm looking to see demonstrated on this project are:
You've made a good start on all of these, but there are substantial pieces missing for each. Please review my inline comments, and try and focus on these learning goals for Ride Share and next week's Hotel project. I'll be excited to see what you come up with. I appreciate that both of you have been putting in the hours recently - keep up the hard work and dedication! |
LETTER_VALUES = | ||
{ | ||
:A => 1, | ||
:E => 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.
I like this choice of data structure!
# iterate over each letter | ||
user_word.each do |letter| | ||
letter = letter.to_sym | ||
if LETTER_VALUES.has_key?(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.
This check on line 52 is redundant! Above (line 36) you do a regex match, and here you check whether the LETTER_VALUES
hash contains the letter. One or the other would suffice. I think I prefer the check here, since that makes it easy if you ever need to change the letters (maybe our version of scrabble starts allowing words with apostrophes).
# RETURNS WORD FROM ARRAY LENGTH 1 | ||
elsif array_of_words.length == 1 | ||
return array_of_words[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.
Since both the if
and elsif
branches of this conditional have a return, you can omit the else
entirely. It's not a huge difference, but it saves you some indentation.
end | ||
|
||
it 'if tied, prefer a word with 7 letters' do | ||
array_of_words = ['dog', 'course', 'lungers'] | ||
Scrabble::Scoring.highest_score_from(array_of_words).must_equal 'lungers' | ||
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.
Since lungers
gets the 7-letter bonus, I don't think you actually have a tie here. There isn't a pair of English words that allow you to test this logic, but zzzzzz
and oratory
will do.
"Why bother" you ask? Well, if Miriam-Webster adds zzzzzz
as an onomatopoeia for snoring, we need to be prepared, or you could envision a scrabble app that works across languages or that allows users to add their own words. Moreover, maybe this is the mathematician in me speaking, but I believe there's beauty and joy to be found in writing code that isn't just "good enough", but which truly solves the problem.
end | ||
|
||
it 'returns the highest word if there are two words' do | ||
array_of_words = ['cat', 'zoo'] | ||
Scrabble::Scoring.highest_score_from(array_of_words).must_equal 'zoo' |
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.
It might be wise to reverse the order of this array and check that you get the same result. You would be surprised at how often this sort of thing turns up a bug. This applies to all the tiebreaker tests in this section.
# if word_scores.include?(nil) | ||
# binding.pry | ||
# end | ||
return word_scores.inject(:+) |
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.
Beautiful!
end | ||
|
||
def highest_scoring_word | ||
Scrabble::Scoring.highest_score_from(plays) |
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 missing an end here - highest_scoring_word
is defined inside of won
. Turns out this is valid Ruby syntax, but it'd probably not what you wanted.
if total_score > 100 | ||
return true | ||
else | ||
return false |
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
describe 'won?' do | ||
it 'if player has > 100 point score, return true' do | ||
word = "crazy" | ||
word_1 = 'janky' |
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.
Here are some other questions I would like to see answered by these tests:
- What if the player has not played any words at all?
- What if the player has < 100 points?
- What if the player has exactly 100 points?
|
||
# Assert | ||
player.total_score.must_be Integer | ||
|
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 calculate the score and check the result.
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?