-
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
Scrabble - Jackie & Leti (Ampers) #8
base: master
Are you sure you want to change the base?
Conversation
…ssed the initialize test for it.
…d fixed all tests related to it.
…_from(scoring.rb) method to score every word from the given array and find the 'winner word'.
… assertion to draw_tiles player_spec.
…tead of if statments.
… a unecessary require command at the top of file.
ScrabbleWhat We're Looking For
|
lib/scoring.rb
Outdated
# Set the points for that word to initialize at zero and calculate the points of each word, adding them to the points variable: | ||
points = 0 | ||
|
||
letters_array.each do |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 works, but is there a more compact way to do this, maybe with a hash?
lib/scoring.rb
Outdated
scoring_table = {} | ||
|
||
# Set the scores of each word: | ||
array_of_words.each {|word| scoring_table["#{word}"] = score(word)} |
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 the interpolation here:
array_of_words.each {|word| scoring_table[word] = score(word)}
will work
end | ||
|
||
it 'returns the highest word if there are two words' do | ||
winning_words = Scrabble::Scoring.highest_score_from(["dog", "academy"]) |
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 order can potentially be important in the highest_score_from
method repeating these tests by varying the order is useful.
Something like:
winning_words = Scrabble::Scoring.highest_score_from(["academy", "dog"])
winning_words.must_equal "academy"
# _________________PLAY METHOD____________________ | ||
# Accepts a word as an argument and add it to the plays array. | ||
|
||
def play(word) |
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.
Read the description again. This method is required to return false
if they have already won prior to playing the word.
# Returns true if the toal score is more than 100, otherwise returns false. | ||
|
||
def won? | ||
total_score > 100 ? true : 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.
Good ternary
end | ||
end | ||
|
||
describe "#play(word)" 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.
What about:
- Playing more than 1 word.
- Playing an invalid word
- Playing words after the player has already won!
specs/player_spec.rb
Outdated
|
||
end | ||
|
||
it "Returns false if player has 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.
won?
should return true
if the player has >= 100 points. It's play
that should return false
lib/tile_bag.rb
Outdated
attr_reader :bag | ||
|
||
def initialize | ||
@bag = { |
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.
There's a number of problems with this data structure. Most pressing is that it gives each letter an equal chance of being drawn. This is despite the fact that there are a lot more "E" tiles than "Z".
new_letter = @bag.keys.sample | ||
tiles_drawn << new_letter | ||
@bag[new_letter] -= 1 | ||
@bag.delete_if { |letter, quantity| quantity == 0 } |
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 that you're keeping the number of tiles from going negative.
end | ||
|
||
describe '#tiles_remaining' do | ||
it "returns number of tiles remaining in bag" 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.
You should also test to see what happens when I try to draw more tiles than are in the bag!
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?