-
Notifications
You must be signed in to change notification settings - Fork 12
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
Sekhrw/master #34
base: sekhrw/master
Are you sure you want to change the base?
Sekhrw/master #34
Changes from all commits
ad0220f
b2ee322
000feb3
30ae6de
361e455
403e782
dd87533
7489d88
f725186
97b9293
81d9a32
d1a1f4a
055f825
f1794ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Scrabble | ||
class Scrabble | ||
def letter_score(letter) | ||
case letter.downcase | ||
when "a", "e", "i", "o", "u", "l", "n", "r", "s", "t" | ||
return 1 | ||
when "d", "g" | ||
return 2 | ||
when "m", "b", "c", "p" | ||
return 3 | ||
when "f", "h", "v", "w", "y" | ||
return 4 | ||
when "k" | ||
return 5 | ||
when "j", "x" | ||
return 8 | ||
when "q", "z" | ||
return 10 | ||
else | ||
return 0 | ||
end | ||
end | ||
#SCORE = 0 | ||
def word_score(word) | ||
score = 0 | ||
word.split("").each do |letter| | ||
letter = letter_score(letter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just gets a bit confusing with the use of the |
||
score += letter | ||
end | ||
return score | ||
end | ||
|
||
def highest_word_score(word_list) | ||
scores = {} | ||
|
||
word_list.split(",").each do |palabra| | ||
#word_array.push(palabra) | ||
word_total = word_score(palabra) | ||
scores[word_total] ||= [] | ||
scores[word_total] << palabra | ||
end | ||
|
||
highest_score = scores.keys.sort[-1] | ||
if scores[highest_score].length > 1 | ||
best_word = scores[highest_score].sort_by { |x| x.length } | ||
best_word[0] | ||
else | ||
return scores[highest_score] | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require "./lib/scrabble" | ||
|
||
class Player < Scrabble::Scrabble | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this class be within the overall module? |
||
|
||
attr_reader :name, :plays, :total_score | ||
def initialize(name) | ||
@name = name | ||
@plays = [] | ||
#@total_score = total_score | ||
end | ||
|
||
def play(word) | ||
@plays.push(word) | ||
#score = word_score(word) | ||
#@total_score.push(score) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd recommend removing your commented out code when you submit your PRs |
||
return @plays | ||
end | ||
|
||
def total_score | ||
total = 0 | ||
all_words = @plays | ||
all_words.each do |word| | ||
#word_score(word) | ||
total += word_score(word) | ||
end | ||
return total | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Watch your indentation here - looks like you have one extra indent |
||
end | ||
|
||
def won? | ||
return total_score >= 100 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this |
||
end | ||
|
||
def highest_scoring_word | ||
all_words = @plays | ||
s = "'#{all_words.join("','")}'" | ||
highest_word_score(s) | ||
end | ||
|
||
def highest_score_number #we need to extract string from array | ||
s = highest_scoring_word | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this method is quite confusing, possibly based on the name of the variable. I'd recommend renaming to something more explicit to describe the data that is stored. |
||
high_score = 0 | ||
s.each do |word| | ||
#word_score(word) | ||
high_score += word_score(word) | ||
end | ||
return high_score | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require "./lib/scrabble" | ||
|
||
class TileBag < Scrabble::Scrabble | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment re: putting this code inside the module |
||
def initialize | ||
@bag = ["b", "b", "c", "c", "f", "f", "p", "p", "v", "v"] | ||
@dealt_tiles = [] | ||
@default_tiles = draw_tiles(7) | ||
end | ||
|
||
|
||
def draw_tiles(num) | ||
tiles = @dealt_tiles | ||
num.times do | ||
t = @bag.sample | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally recommend using a more explicit variable name |
||
tiles.push(t) | ||
remove_tiles(t) | ||
end | ||
tiles | ||
end | ||
|
||
def remove_tiles(letter) | ||
spot = @bag.index(letter) | ||
@bag.delete_at(spot) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this potentially delete more than one of the same letter in the |
||
|
||
end | ||
end | ||
|
||
#def generate_answer | ||
# possible_words = ["beef", "onion", "boot", "shoe", "dog", "cat", "fireball", "mandrake"] | ||
# @answer = possible_words.sample.split("") | ||
#end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require "./lib/scrabble_player_class" | ||
|
||
describe Player do | ||
before :each do | ||
@player = Scrabble::Scrabble::Player.new("Jack") | ||
end | ||
|
||
|
||
describe "returns the @name instance variable" do | ||
it "returns @name" do | ||
expect(@player.name).to eq "Jack" | ||
end | ||
end | ||
|
||
describe "shows words played" do | ||
it "returns @plays" do | ||
expect(@player.play("apple")).to eq ["apple"] | ||
end | ||
end | ||
|
||
|
||
describe "shows total score" do | ||
it "returns score of all words played" do | ||
@player.play("venus") | ||
@player.play("zzzzzzzzzzzzzz") | ||
@player.play("a") | ||
expect(@player.total_score).to eq 7 | ||
end | ||
end | ||
|
||
describe "tells if the player has over 100 points" do | ||
it "returns ture or false" do | ||
@player.play("zzzzzzzzzzzzzz") | ||
expect(@player.won?).to be false | ||
end | ||
end | ||
|
||
describe " tells the highest scoring word" do | ||
it "returns the highest scoring word" do | ||
@player.play("venus") | ||
@player.play("zzzzzzzzzzzzzz") | ||
@player.play("a") | ||
|
||
expect(@player.highest_scoring_word).to eq "a" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused about how this is the highest scoring word. Am I missing something? |
||
end | ||
end | ||
|
||
describe " gives the highest scoring number" do | ||
it "gives the higest scoring number" do | ||
@player.play("venus") | ||
@player.play("zzzzzzzzzzzzzz") | ||
@player.play("a") | ||
|
||
expect(@player.highest_score_number).to eq 4 | ||
end | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "./lib/scrabble" | ||
|
||
describe Scrabble do | ||
before :each do | ||
@scrabble = Scrabble::Scrabble.new | ||
|
||
end | ||
|
||
describe "#letter_score" do | ||
it "scores the letter a" do | ||
expect(@scrabble.letter_score("a")).to eq 1 | ||
end | ||
|
||
#it "scores the letter e" do | ||
# expect(@scrabble.letter_score("e")).to eq 1 | ||
#end | ||
|
||
it "scores the letter m" do | ||
expect(@scrabble.letter_score("m")).to eq 3 | ||
end | ||
|
||
it "scores the letter b" do | ||
expect(@scrabble.letter_score("b")).to eq 3 | ||
end | ||
|
||
it "scores the letter c" do | ||
expect(@scrabble.letter_score("c")).to eq 3 | ||
end | ||
|
||
it "scores the letter p" do | ||
expect(@scrabble.letter_score("p")).to eq 3 | ||
end | ||
end | ||
|
||
describe "#word_score" do | ||
it "iterates through letters and changes them to integers" do | ||
expect(@scrabble.word_score("Me")).to eq 4 | ||
end | ||
end | ||
|
||
describe "#highest_word_score" do | ||
it "call that index on word_array" do | ||
expect(@scrabble.highest_word_score("aei, b, e")).to eq " b" | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require "./lib/tile_bag" | ||
|
||
describe TileBag do | ||
before :each do | ||
@tile_bag = Scrabble::Scrabble::TileBag.new | ||
end | ||
|
||
describe '@default_tiles' do | ||
it "selects 7 random tiles" do | ||
expect(@tile_bag).to eq ['b', "b", "a"] | ||
end | ||
end | ||
|
||
describe "gives us 3 tiles" do | ||
it "returns random tiles" do | ||
expect(@tile_bag.draw_tiles(3)).to eq ['b', "b", "a"] | ||
end | ||
end | ||
|
||
describe "subtracts tiles from our bag" do | ||
it "subtracts tiles" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering what the difference is between this test and the test above on line 9? |
||
expect(@tile_bag).to eq ['b', "b", "a"] | ||
end | ||
end | ||
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.
This is a bit confusing where the name of the module is the same as the class, so I'd recommend a minor re-name if possible