-
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: Zheng Cao & Nicoleta Brandolini #24
base: master
Are you sure you want to change the base?
Conversation
…een added for edge case)
ScrabbleWhat We're Looking For
|
@@ -1,5 +1,6 @@ | |||
*.gem | |||
*.rbc | |||
.vscode/ |
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.
Interesting, you're using VS Code
module Scrabble | ||
class Scoring | ||
|
||
SCORE_CHART = { |
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 way to store the letter scores, and nice use of a CONSTANT.
score = 0 | ||
word.each_char do |c| | ||
return nil if !SCORE_CHART.keys.include?(c.upcase) | ||
SCORE_CHART.each do |key, value| |
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 actually don't need this loop, you can instead just do:
score += SCORE_CHART[c.upcase]
Take advantage of the fact that this is a hash.
end | ||
|
||
it 'if tied, prefer a word with 7 letters' do | ||
Scrabble::Scoring.highest_score_from(["ZZZZZZ", "AAAAADB"]).must_equal "AAAAADB" |
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, you considered the order!
|
||
# Returns the `highest_scoring_word` score | ||
def highest_word_score | ||
return Scrabble::Scoring.score(highest_scoring_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.
Well done
end | ||
end | ||
|
||
describe 'highest_scoring_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's the result of this method if nothing has been played.
end | ||
|
||
describe 'draw_tiles' do | ||
it "Fills tiles array until it has 7 letters from the given tile 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 probably remove some tiles from the player's hand (like 2) and then call draw_tiles
and see if it draws the right number of tiles (like 5).
"U" => 4, "V" => 2, "W" => 2, "X" => 1, "Y" => 2, "Z" => 1 } | ||
|
||
def initialize | ||
@tiles = [] |
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 sets @tiles
to an empty array and doesn't put any tiles in it.
|
||
attr_reader :tiles, :number_of_tiles | ||
|
||
LETTER_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.
This is great for the letter quantities, but you're using this hash to store the tiles in the bag. This is problematic for a couple of reasons.
- All instances of
TileBag
are sharing this constant. So if you remove a "z" from oneTileBag
instance, you've removed it from them all. - This structure makes any letter equally likely to be drawn from the bag. However there is only 1 "z" and 12 "E"'s.
end | ||
end | ||
|
||
describe 'draw_tiles' 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 happens when you draw all the tiles?
Also you need to check that the number of each drawn tile has gone down.
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?