Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
20e4630
first rev of scrabble
nlcurry Mar 8, 2016
ead7d52
first rev of files
nlcurry Mar 8, 2016
423c01e
first rev of files
nlcurry Mar 8, 2016
4deeb61
first rev of files
nlcurry Mar 8, 2016
3a9074f
passed first test
SuzHarrison Mar 8, 2016
200726e
Added 2 tests on scoring_spec and score chart and first two methods i…
nlcurry Mar 8, 2016
b2f92a9
forgot to save scrabble file
nlcurry Mar 8, 2016
8641558
added to score method in scrabble.rb but now need to start putting th…
SuzHarrison Mar 8, 2016
822a194
added connection from scrabble to lib folder. passed first test for s…
SuzHarrison Mar 8, 2016
b767359
Excluded words with greater than 7 letters from score calculation. Ad…
nlcurry Mar 8, 2016
bbda4eb
added specs for the newly updated methods.
nlcurry Mar 8, 2016
42bc78e
added highest score method without tiebreaking rules
SuzHarrison Mar 8, 2016
4b1df58
Added test to find word with highest value
nlcurry Mar 8, 2016
b70aa64
sorted the tied words,add tie breaking features.
SuzHarrison Mar 9, 2016
164693e
Found bugs. Working on tiebreaker test.
nlcurry Mar 9, 2016
ae7cddc
Finished tiebreaker section. Untested.
nlcurry Mar 9, 2016
5fa1eac
specs added word jogged
SuzHarrison Mar 9, 2016
5901076
added hash words for tiebreaker test
nlcurry Mar 10, 2016
659a408
Started over with tiebreaking conditions and finished. Moving to wave…
nlcurry Mar 10, 2016
fe8e190
Started on wave 2, player files.
nlcurry Mar 10, 2016
ff334a8
touble with adding total_score method
SuzHarrison Mar 10, 2016
2a60476
scrabble file slightly changed with require relative
SuzHarrison Mar 10, 2016
ead84d8
Finished wave 2
nlcurry Mar 11, 2016
2b8c167
started tilebag. trying to initialize and get full hash of tiles avai…
SuzHarrison Mar 11, 2016
66b30b1
Started wave 3
nlcurry Mar 11, 2016
9ecbd81
added methods for tiles_remaining and tiles_drawn.
SuzHarrison Mar 11, 2016
b43291a
Finished Tilebag methods and specs
nlcurry Mar 11, 2016
2be5fc4
Started on wave 3 player modification
nlcurry Mar 11, 2016
2341f0e
tests and code for PLayer enhancement
SuzHarrison Mar 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions RakeFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "rake/testtask"

Rake::TestTask.new do |t|
t.libs = ["lib"]
t.warning = true
t.test_files = FileList["specs/*_spec.rb"]

end

task default: :test
Binary file added lib/.DS_Store
Binary file not shown.
91 changes: 91 additions & 0 deletions lib/player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
class Player
attr_accessor :name

def initialize (name)
@name = name
end

def hash_players
hash_players = {
"Suzanne" => ["cramps", "develop", "mixup", "doggies"],
"Jeremy" => ["zebra", "naysays", "pigsty"],
"Nadine" => ["mice"]
}
end

def plays
played_words = []
hash_players.each do |name, words|
if @name == name
played_words += words
end
end
return played_words
end

def self.score(word)
super
end

def play(word)
if won? == true
return false
else
hash_players.each do |name, words|
if @name == name
words << word
end
end
return Scoring.score(word)
end
end

def total_score
total_array_values = 0
hash_players.each do |name, array|
if @name == name
array.each do |word|
total_array_values += Scoring.score(word)
end
end
end
return total_array_values
end

def won?
if total_score >100
return true
else
return false
end
end

def highest_scoring_word
win_word = ""
hash_players.each do |name,array|
if @name == name
win_word = Scoring.highest_score_from(array)
end
end
return win_word
end

def highest_word_score
highest_score = 0
highest_score = Scoring.score(highest_scoring_word)
end

tiles = []

def tiles
self.draw_tiles
return tiles
end

def draw_tiles
tiles = self.tiles
tiles_needed = 7 - tiles.length
tiles = Tilebag.draw_tiles(tiles_needed)
end

end
50 changes: 50 additions & 0 deletions lib/scoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class Scoring
#some sort of data structure to store the individual letter scores
SCORE_CHART = {
"A"=>1, "B"=>3, "C"=>3, "D"=>2,
"E"=>1, "F"=>4, "G"=>2, "H"=>4,
"I"=>1, "J"=>8, "K"=>5, "L"=>1,
"M"=>3, "N"=>1, "O"=>1, "P"=>3,
"Q"=>10, "R"=>1, "S"=>1, "T"=>1,
"U"=>1, "V"=>4, "W"=>4, "X"=>8,
"Y"=>4, "Z"=>10
}

def self.score(word)
word_array = word.upcase.split("")

word_score = 0

if word.length <= 7
word_array.each do |letter|
word_score += SCORE_CHART[letter]
#returns score value for given word. word input as string.
end
#seven letter word get 50point bonus
word.length == 7 ? word_score += 50 : word_score
end
return word_score
end

def self.highest_score_from(array_of_words)
win_score = 0
win_word = array_of_words[0]


array_of_words.each do |word|
score_inst = self.score(word)
#checks if current winning score is less than or equal
#to the current word's score, then uses the tiebreaker
#conditions to determine winning word and score
if score_inst > win_score
win_score = score_inst
win_word = word
elsif score_inst == win_score && word.length < win_word.length
win_word = word
win_score = score_inst
end
end
return win_word

end
end
42 changes: 42 additions & 0 deletions lib/tilebag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class Tilebag
attr_reader :tilebag

def initialize
#@tilebag = {}
@tilebag = {
"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}

end

def draw_tiles(num)
keys = []
letters = []
count = 0

if self.tiles_remaining >= num
while count < num
keys = (@tilebag.keys).shuffle
letter = keys[0]
if @tilebag[letter] > 0
@tilebag[letter] = @tilebag[letter] - 1
letters << letter
count = count + 1
end
end
return letters
else
return "Out of tiles"
end


end

def tiles_remaining
values = @tilebag.values
remaining = values.inject(0) { |sum, item| sum + item }
return remaining
end

end
7 changes: 7 additions & 0 deletions scrabble.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


module Scrabble
require_relative "./lib/scoring.rb"
require_relative "./lib/player.rb"
require_relative "./lib/tilebag.rb"
end
Binary file added specs/.DS_Store
Binary file not shown.
85 changes: 85 additions & 0 deletions specs/player_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
require_relative "./spec_helper"
require_relative "../scrabble"


describe Player do
it "it is an object we have acccess to" do
Player.wont_be_nil
end
end

describe "Player#name" do
suzanne = Player.new("Suzanne")
it "should return Suzanne" do
suzanne.name.must_equal("Suzanne")
end
end

describe "Player#plays" do
suzanne = Player.new("Suzanne")
it "should return words:" do
suzanne.plays.must_equal(["cramps", "develop", "mixup", "doggies"])
end
end

describe "Player#play(word)" do
suzanne = Player.new("Suzanne")
nadine = Player.new("Nadine")
it "adds input word to the array" do
suzanne.play("spider").must_equal(false)
end
it "adds input word to the array" do
nadine.play("cat").must_equal(5)
end
end

describe "Player#total_score" do
suzanne = Player.new("Suzanne")
it "should return 151 for Suzanne" do
suzanne.total_score.must_equal(151)
end
end

describe "Player#won?" do
suzanne = Player.new("Suzanne")
it "return true for player with >100 points" do
suzanne.won?.must_equal(true)
end
end

describe "Player#highest_scoring_word" do
suzanne = Player.new("Suzanne")
nadine = Player.new("Nadine")
jeremy = Player.new("Jeremy")
it "should return highest scoring played word" do
suzanne.highest_scoring_word.must_equal("develop")
end
it "should return highest scoring played word" do
nadine.highest_scoring_word.must_equal("mice")
end
it "should return highest scoring played word" do
jeremy.highest_scoring_word.must_equal("naysays")
end
end

describe "Player#highest_word_score" do
suzanne = Player.new("Suzanne")
it "should return highest word score" do
suzanne.highest_word_score.must_equal(63)
end
end

describe "Player#tiles" do
suzanne = Player.new("Suzanne")
it "should return a collection of letters can play (max 7)" do
suzanne.tiles.must_equal.Array
end
end

describe "Player#draw_tiles(tile_bag)" do
suzanne = Player.new("Suzanne")
it "should fill tiles array until it has 7 letters" do
suzanne.draw_tiles
suzanne.tiles.length.must_equal(7)
end
end
46 changes: 46 additions & 0 deletions specs/scoring_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require_relative "./spec_helper"
require_relative "../scrabble"


describe Scoring do
it "it is an object we have acccess to" do
Scoring.wont_be_nil
end

TEST_SCORE = {
"jogged" => 16,
"zebra" => 16,
"xylophone" => 0,
"develop" => 63,
"pigsty" => 12,
"doggies" => 60,
"zenith" => 18,
"cramps" => 12,
"naysays" => 63,
"mixup" => 16
}

HASH_WORDS = {
"jogged" => ["jogged"],
"mixup" => ["mixup", "jogged", "pigsty", "zebra", "cramps"],
"zebra" => ["jogged", "zebra", "pigsty", "mixup", "cramps"],
"zenith" => ["jogged", "zebra", "pigsty", "mixup", "cramps", "zenith"],
"develop" => ["jogged", "zebra", "develop", "pigsty", "doggies", "naysays", "mixup", "cramps", "zenith"]
}

describe "Scoring#score" do
TEST_SCORE.each do |word, score|
it "should return #{ score } for '#{ word }'" do
Scoring.score(word).must_equal(score)
end
end
end

describe "Scoring#highest_score_from" do
HASH_WORDS.each do |word,array|
it "should return #{word} with the highest score and tiebreaker" do
Scoring.highest_score_from(array).must_equal(word)
end
end
end
end
11 changes: 11 additions & 0 deletions specs/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "simplecov"
SimpleCov.start

require "minitest"
require "minitest/spec"
require "minitest/autorun"
require "minitest/reporters"

#give us some really pretty output
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new

Loading