-
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
&&: Mariko and Monalisa's Scrabble #7
base: master
Are you sure you want to change the base?
Conversation
Merge branch 'master' of https://github.com/MonalisaC/Scrabble
Merge branch 'master' of https://github.com/MonalisaC/Scrabble
ScrabbleWhat We're Looking For
|
return total | ||
end | ||
|
||
def self.pick_winner(highest_scoring_words) |
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.
Nice a helper method! Good use of min_by
.
return highest_scoring_words.min_by { |word| word.length } | ||
end | ||
|
||
def self.highest_scoring_words(array_of_words) |
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 Enumerables.
|
||
def self.highest_score_from(array_of_words) | ||
def self.highest_score_from(array_of_words) |
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.
Very neat how you broke this down.
# letters is a array of upcase letters | ||
letters = word.upcase.chars.to_a | ||
|
||
letters.map{ | 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.
You don't need map
here, map
is used to convert an array to something else. If you wanted to use map
you could:
scores = letters.map do |letter|
CHART[letter.toupcase]
end
return scores.sum
end | ||
|
||
it 'returns the only word in a length-1 array' do | ||
Scrabble::Scoring.highest_score_from(['BANJO']).must_equal 'BANJO' | ||
end | ||
|
||
it 'returns the highest word if there are two words' 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.
Good job swapping the order!
end | ||
|
||
|
||
it 'Adds the input word to the plays Array' 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 words, after the player has won?
|
||
it "Fills tiles array, after player uses the tiles" do | ||
player.draw_tiles(tilebag) | ||
word = player.tiles.join |
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.
Clever
class TileBag | ||
attr_reader :tiles | ||
def initialize | ||
@tiles = ["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.
Awesome data structure here.
|
||
describe 'TileBag' do | ||
|
||
let(:tilebag) {Scrabble::TileBag.new} |
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.
Nice use of a let
tilebag.draw_tiles(0).length.must_equal 0 | ||
|
||
end | ||
it "removes the tiles from the default set" 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.
An edge-case would be drawing more tiles than exist 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?