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
6f37025
Set Github. Both cloned the forked repo. Installed gems.set up spec f…
Mar 8, 2016
15db1f0
Starting to set up scrabble.rb file to accept class files.
jweeber Mar 8, 2016
3975b0c
Create a Scrabble::Scoring class which contains a hashe to store the …
Mar 8, 2016
1a63d65
all files added
Mar 8, 2016
55f3a02
added a red failing test and can rake our own test. added test scores…
jweeber Mar 8, 2016
4b9e1aa
working on self.score method. may try writing the specs first.
jweeber Mar 8, 2016
bf25d02
Try many ways to create a test. No one worked as expected, but feelin…
Mar 8, 2016
675ff56
first test working finally
jweeber Mar 8, 2016
289a246
created a method for assignin a point for a letter
Mar 9, 2016
89e3fc3
mistakenly added changes
jweeber Mar 9, 2016
8caab14
resolving merge conflict
jweeber Mar 9, 2016
3c3a63f
changed data structure - reversed keys and values, created clearer me…
jweeber Mar 9, 2016
0fd4e9a
Made a BONUS constant vatiable. Created a test for the 50 bonus points.
Mar 9, 2016
d2faf4d
Made a BONUS constant vatiable. Created a test for the 50 bonus points
Mar 9, 2016
8b876e1
wrote test spec for new highest word method. tried a test for raising…
jweeber Mar 9, 2016
ea1f8c8
worked in the tightpart
Mar 10, 2016
caa0fed
added blocks for determining winner if there is a tie. Now picks the …
jweeber Mar 10, 2016
5a57709
created test for the case of tied between two words with same length
Mar 10, 2016
de3613e
Created method for ArgumentError in method score
Mar 10, 2016
ef7e5f9
started player class with play and plays methods. Created 3 specs for…
jweeber Mar 10, 2016
6801746
Created method total_score
Mar 11, 2016
d6c9bca
fixed total_score method test -PASSES
jweeber Mar 11, 2016
ff8bb00
the won method is in there and works. we have 2 tests for it that bot…
jweeber Mar 11, 2016
2d77389
added highest scoring word and highest word score methods and tests f…
jweeber Mar 11, 2016
f1b9537
Created Scrabble::TileBag, its initialization, and draw_tiles(num) me…
Mar 11, 2016
1270b3b
Finished draw_tiles(num) method
Mar 11, 2016
88e2bdd
added tiles_remaining method and one test that passes, but breaks oth…
jweeber Mar 11, 2016
e6de957
created tiles method and connected instance of tilebag with instance …
jweeber Mar 11, 2016
510b32c
Got tiles method working. Created its tests
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
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Scrabble
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3.0
9 changes: 9 additions & 0 deletions Rakefile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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
67 changes: 67 additions & 0 deletions lib/player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
class Scrabble::Player
attr_accessor :name, :array_words
attr_reader :player_tiles

def initialize(name)
@name = name
@array_words = []
@array_of_scores = []
# @new_draw = Scrabble::TileBag.new
@bag_tiles = Scrabble::TileBag.new
@player_tiles = @bag_tiles.draw_tiles(7) #[A:, B:, C:, A:, T:, M:, :O]
end

def plays
return @array_words
# => ["cat","pull","yes"]
end

def play(word) # takes word from player
# @player_tiles
@array_words << word
@player_tiles.pop(word.length)
# tiles_length = 7 - X
#4

@player_tiles += @bag_tiles.draw_tiles(word.length)

# @new_tiles = @bag_tiles.draw_tiles(@tiles_length)

# @tiles_length = 7
# @all_tiles = @player_tiles
Scrabble::Scoring.score(word)
# Return to a Numeric
end

def total_score
@array_words.each do |word|
@array_of_scores << Scrabble::Scoring.score(word)
end
# => array_of_scores = [4, 6, 8,]
return @array_of_scores.reduce(:+)
end

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

def highest_scoring_word
Scrabble::Scoring.highest_score_from(@array_words)
end

def highest_word_score
total_score
pairs = @array_of_scores.zip(@array_words)
pairs.max[0]
end

def tiles
@player_tiles
end

end
49 changes: 49 additions & 0 deletions lib/scoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Scrabble::Scoring
BONUS = 50
SCORES = {
A: 1, E: 1, I: 1, O: 1, U: 1, L: 1, N: 1, R: 1, S: 1, T: 1, D: 2, G: 2,
B: 3, C: 3, M: 3, P: 3, F: 4, H: 4, V: 4, W: 4, Y: 4, K: 5, J: 8, X: 8,
Q: 10, Z: 10
}


def self.score(word)
if word.length > 7
raise ArgumentError.new
end

word = word.upcase.split(//) # change letters of word to uppercase to match keys
points = 0 # points start at 0
points += BONUS if word.length == 7

word.each do |letter|
points += SCORES[letter.to_sym]
end
return points
end


def self.highest_score_from(array_of_words)
# => array_of_words = ["melissa", "cat"]
all_scores = []
array_of_words.each do |one_word|
all_scores << self.score(one_word)
# => all_scores = [59, 59, 4, 6]
end

pairs = all_scores.zip(array_of_words)
# example: [[59, "pull"], [43, "cat"], [59, "yes"], [3, "andrea"], [7, "carlos"]]
winners = []

pairs.each do |pair|
if pair[0] == pairs.max[0]
winners << pair
end
end
winners
tie_winner = winners.min_by do |winner|
winner[1].size
end
return tie_winner[1]
end
end
29 changes: 29 additions & 0 deletions lib/tilebag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Scrabble::TileBag

def initialize
@tiles = { A: 9, N: 6, B: 2, O: 8, C: 2, P: 2, D: 4, Q: 1,
E: 12,R: 6, F: 2, S: 4, G: 3, T: 6,H: 2, U: 4, I: 9,
V: 2, J: 1, W: 2, K: 1, X: 1, L: 4, Y: 2, M: 2, Z: 1
}
end

def draw_tiles(num)
sample = @tiles.keys.sample(num)
# =>[:J, :B, :F, :L, :Y, :I, :C]

@tiles.each do |letter, quantity|
if sample.include? letter
quantity -= 1
@tiles[letter] = quantity
end
# @tiles
end
return sample # =>[:J, :B, :F, :I, :C]
end

def tiles_remaining
# returns total number of tiles in the general bag
leftover_tiles = @tiles.values.reduce(:+)
return leftover_tiles
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

end
require_relative './lib/player'
require_relative './lib/scoring'
require_relative './lib/tilebag'
5 changes: 5 additions & 0 deletions specs/coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"result": {
"covered_percent": 100.0
}
}
7 changes: 7 additions & 0 deletions specs/coverage/.resultset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"RSpec": {
"coverage": {
},
"timestamp": 1457474541
}
}
Empty file.
Loading