Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gem 'sinatra', '~>1.4.7'
gem 'rerun', '~>0.11.0'
gem 'thin', '~>1.6.4'
37 changes: 37 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
GEM
remote: https://rubygems.org/
specs:
daemons (1.2.3)
eventmachine (1.2.0.1)
ffi (1.9.10)
listen (3.0.6)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9.7)
rack (1.6.4)
rack-protection (1.5.3)
rack
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
rerun (0.11.0)
listen (~> 3.0)
sinatra (1.4.7)
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
thin (1.6.4)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (~> 1.0)
tilt (2.0.2)

PLATFORMS
ruby

DEPENDENCIES
rerun (~> 0.11.0)
sinatra (~> 1.4.7)
thin (~> 1.6.4)

BUNDLED WITH
1.11.2
Binary file added lib/.DS_Store
Binary file not shown.
82 changes: 82 additions & 0 deletions lib/scoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#require_relative '../scrabble' # allows this class to access scrabble and run through irb

class Scrabble::Scoring

attr_reader :word

include Scrabble
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scrabble looks like it's an empty class. Why include it here?


LETTER_POINTS = {
1 => ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"],
2 => ["D", "G"],
3 => ["B", "C", "M", "P"],
4 => ["F", "H", "V", "W", "Y"],
5 => ["K"],
8 => ["J", "X"],
10 => ["Q", "Z"]
}

def initializer (word)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean initialize?

@word = word["word"]
end

# returns the score value for a single given word
def self.score(word)
score = 0
tiles = 0

word_array = word.upcase.split("")

word_array.each do |letter|
LETTER_POINTS.each do |points, letters_array|
Copy link

@GreyKn GreyKn Apr 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be replicating the functionality of #char_score, would there be a way to use that method here?

if letters_array.include? letter
score += points
tiles += 1
end
end
end
# if all seven tiles are used the below tenary will add 50 points to the users score else return score
tiles >= 7 ? score += 50 : score
score
end

# returns the score value for a single given letter
def self.char_score(char)
score = 0

LETTER_POINTS.each do |points, letters_array|
if letters_array.include? char.upcase
score += points
end
end
score
end

def self.highest_score_from(array_of_words) # array_of_words = ["cats", "fee", "no"]

array_of_word_values = []
array_of_words.each do |word|
array_of_word_values << [word, self.score(word), word.length] # = [["cats", 7, 4], ["fee", 7, 3], ["no", 2, 2]]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using an array of arrays:

[["cats", 7, 4], ["fee", 7, 3], ["no", 2, 2]]

Consider using an array of hashes so you have context of each value

[
  {word: "cats", score: 7, length: 4}, 
  {word: "fee", score: 7, length: 3}, 
  {word: "no", score: 2, length: 2}
]

end

highest_score_array = array_of_word_values[0] # ["cats", 7, 4]

array_of_word_values.each do |word_array| # ["cats", 7, 4]
Copy link

@GreyKn GreyKn Apr 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use some array methods to make this a little bit easier.

highest_score_array = array_of_words_values.max_by { |word_array| word_array[1] }
highest_score = highest_score_array[0]

Now we could use select to find all words with that score

words_with_highest_scores = array_of_words_values.select {|word| word[1] == highest_score}

Then sort by length (in case there were more than 1 word with the same score

words_sorted_by_length = words_with_highest_scores.sort_by { |word| word[2] }

Since sort_by puts things in ascending order, the last element should be the winner

return words_sorted_by_length.last[0]

# compares the score of the words
if word_array[1] == highest_score_array[1] # compare score
# compares the length of the words
if word_array[2] < highest_score_array[2]
highest_score_array[2] == 7 ? highest_score_array : highest_score_array = word_array
#highest_score_array = word_array # replace the highest score to the word_array being referenced
elsif word_array[2] >= highest_score_array[2]
if highest_score_array[2] < 7
word_array[2] == 7 ? highest_score_array = word_array : highest_score_array
end
end
elsif word_array[1] > highest_score_array[1]
highest_score_array = word_array
end
end
return highest_score_array[0]
end
end
10 changes: 10 additions & 0 deletions lib/scrabble.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# using this module as a namespace, not a mixin
module Scrabble


end

# putting this at the end because otherwise it will read scoring.rb before it creates
# the Scrabble module, meaning the code in scoring.rb won't work
require_relative './scoring'
Binary file added powerpoint/scrabble layout style.pptx
Binary file not shown.
Binary file added public/.DS_Store
Binary file not shown.
Binary file added public/images/blank_tile.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/footer_background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/reset_red.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/score_it2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/score_it2_green.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/score_tile.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/scrabble_background1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/scrabble_background2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/scrabble_letters.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/scrabble_word.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/scrabble_word2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/tiles_style2.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/wood_style1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading