Skip to content
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

created edits branch and pushed all files to it #2

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d44d379
created edits branch and pushed all files to it
ellevargas Aug 30, 2016
5c3dac7
added basics to Scrabble main and started helper TDD
ellevargas Aug 30, 2016
2875610
I cannot label my files apparently
ellevargas Aug 30, 2016
887b073
removed spec_helper - it was an extra file
ellevargas Aug 30, 2016
60516b6
removed spec from lib - the correct file is now there
ellevargas Aug 30, 2016
e403c11
Fixnum and case sensitive tests working
OLegge Aug 30, 2016
91b85c2
Three working tests, returns score
OLegge Aug 30, 2016
d0f9efc
Added 50-point test, tests 1-4 passing
ellevargas Aug 30, 2016
f2673ac
Changed test word from potatos (lel) to majesty
ellevargas Aug 30, 2016
da546b3
Broke out dat Single Responsibility business and now we have methods …
OLegge Aug 30, 2016
7dcdab7
yay first push to master branch, all tests passing currently
ellevargas Aug 30, 2016
66d3499
Merge pull request #1 from livmaria7891/Edits
ellevargas Aug 31, 2016
624ebd8
5 tests now working and also it returns highest score
ellevargas Aug 31, 2016
64b0e2f
wrote 2 tie tests
OLegge Aug 31, 2016
f3a855c
Added winner class variable solidified tied method
OLegge Aug 31, 2016
f4dc217
first wave fully working with 10 tests
ellevargas Sep 1, 2016
1420e93
all tests written for wave 2 and 3 tests passing
ellevargas Sep 1, 2016
0aae47a
All but two tests working in Wave 2
OLegge Sep 1, 2016
ca937ba
Wave 2 completed and approved by Chris all tests working
OLegge Sep 1, 2016
1c4c012
waves 1 and 2 complete and working with tests, wave 3 has 5 tests wor…
ellevargas Sep 2, 2016
fbe4aa1
OMG all waves working and all tests passing
OLegge Sep 2, 2016
25505af
Split out classes into individual rb files - all tests working in all…
OLegge Sep 2, 2016
9cb77d4
I'm changing this thing for a demo
ellevargas Jun 8, 2017
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
13 changes: 13 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ["lib", "specs"]
t.warning = false
t.verbose = false
t.test_files = FileList['specs/*_spec.rb']
puts "Running TestTask"
end

task default: :test do
puts "Running my Rakefile"
end
2 changes: 2 additions & 0 deletions Scrabble.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Scrabble
end
67 changes: 67 additions & 0 deletions lib/Player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require_relative '../Scrabble.rb'
require_relative 'Scrabble.rb'
require_relative 'Scoring.rb'

class Scrabble::Player

attr_reader :name, :player_words, :player_hand

def initialize(name)

raise ArgumentError unless name.class == String
@name = name
@player_words = []
@player_hand = []
end

def plays
return @player_words
end

def play(word)
if won? == true
puts "You have already won"
return false
else
@player_words << word
return Scrabble::Scoring.score(word)
end
end

def total_score
total_score = 0
@player_words.each do |word|
total_score += Scrabble::Scoring.score(word)
end
return total_score
end

def won?
if total_score > 100 #calls the method
return true
else
false
end
end

def highest_scoring_word
return Scrabble::Scoring.score_highest(@player_words)
end

def highest_word_score
return Scrabble::Scoring.score(highest_scoring_word)
end

def tiles
return @player_hand
end

def draw_tiles(tile_bag)

@player_hand << tile_bag.draw_tiles(7 - @player_hand.length)

return @player_hand.flatten!

end

end
72 changes: 72 additions & 0 deletions lib/Scoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require_relative '../Scrabble.rb'
require_relative 'Scrabble.rb'
require_relative 'Player.rb'

class Scrabble::Scoring

LETTER_SCORES = {"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.capitalize_word(word)
raise ArgumentError unless word.class == String
word = word.upcase!
return word
end


def self.score(word)
capitalize_word(word)
word.length == 7 ? score = 50 : score = 0
letters = word.split(//)
letters.each do |char|
score += LETTER_SCORES[char]
end
return score
end


def self.score_highest(word_array)
highest_score = ["", 0]

word_array.each do |word|
if score(word) > highest_score[1]
highest_score = [word, score(word)]
elsif highest_score[1] == score(word)
highest_score = tie_breaker(highest_score, [word, score(word)])
end
end
return highest_score[0]
end


def self.tie_breaker(pair1, pair2)
if pair1[0].length != 7 && pair2[0].length != 7

if pair1[0].length < pair2[0].length
return pair1
elsif pair1[0].length > pair2[0].length
return pair2
else
return pair1
end

elsif pair1[0].length == 7 || pair2[0].length == 7
if pair1[0].length == 7 && pair2[0].length == 7
return pair1

elsif pair1[0].length ==7
return pair1

else
return pair2
end
end
end

end
69 changes: 69 additions & 0 deletions lib/Scrabble.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# STUCK? Did you remember to .self the method?
#STUCK STILL?? Check the class!!!
# I'm a sample comment!

require_relative '../Scrabble.rb'
require_relative 'Player.rb'
require_relative 'Scoring.rb'

class Scrabble::TileBag

attr_reader :tile_bag

def initialize

@tile_bag = {"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}

return @tile_bag
end

def draw_tiles(num)
unless num <= 7
raise ArgumentError.new("You cannot draw more than 7 tiles")
end

draw_tiles = []
while num > 0
tile = @tile_bag.keys.sample(1)[0]

if @tile_bag[tile] != 0
@tile_bag[tile] -= 1
draw_tiles << tile
num -= 1
end
end
return draw_tiles
end

def tiles_remaining
tiles_remaining = @tile_bag.values
sum = tiles_remaining.inject {|sum, element| sum + element}
return sum
end

end

#test1 = Scrabble::TileBag.new
# testplayer = Scrabble::Player.new("Elle")

t = Scrabble::TileBag.new
person = Scrabble::Player.new("Bill")
puts person.draw_tiles(t)

# print testplayer.player_bag.inspect
# print testplayer.player_hand
# puts testplayer.inspect
# print testplayer.inspect
#print testplayer.player_bag


#print testplayer.draw_tiles(@player_hand)
# # puts test1.draw_tiles(12)
# print test1.tiles_remaining

# test1.play("potato")
# test1.play("apple")
# test1.play("majesty")
# test1.play("xylophone")
# puts test1.total_score
# puts test1.won?
Loading