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

Adagrams Completed Kalki & Alice D. #20

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions .rakeTasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Settings><!--This file was automatically generated by Ruby plugin.
You are allowed to:
1. Remove rake task
2. Add existing rake tasks
To add existing rake tasks automatically delete this file and reload the project.
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Run tests" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="default" taksId="default" /></RakeGroup></Settings>
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ GEM

PLATFORMS
ruby
x64-mingw32

DEPENDENCIES
minitest
Expand Down
102 changes: 102 additions & 0 deletions lib/adagrams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# WAVE 1 - The method draw_letters extracts a sample of 10 letters from the letter_pool array
def draw_letters
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 Clever and simple way to set up the distribution of letters.

letter_pool = %w(
A A A A A A A A A
B B
C C
D D D D
E E E E E E E E E E E E
F F
G G G
H H
I I I I I I I I I
J
K
L L L L
M M
N N N N N N
O O O O O O O O
P P
Q
R R R R R R
S S S S
T T T T T T
U U U U
V V
W W
X
Y
Z
)
return letter_pool.sample(10)

end

# WAVE 2 - The method uses_available_letters? checks input against letters_in_hand and returns true if input is in letters_in_hand, false otherwise
def uses_available_letters?(input, letters_in_hand)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍


new_letters_in_hand = letters_in_hand.dup

input.upcase.chars.each do |character|
if new_letters_in_hand.include?(character)
position = new_letters_in_hand.index(character)
new_letters_in_hand.delete_at(position)
else
return false
end
end
return true
end

# WAVE 3 - The method score_word will tally points for words submitted by user
def score_word(word)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍


score = 0

word_char_array = word.upcase.chars

word_char_array.each do |character|
case character
when "A", "E", "I", "O", "U", "L", "N", "R", "S", "T"
score += 1
when "D", "G"
score += 2
when "B", "C", "M", "P"
score += 3
when "F", "H", "V", "W", "Y"
score += 4
when "K"
score += 5
when "J", "X"
score += 8
when "Q", "Z"
score += 10
end
end

if word_char_array.length >= 7
score += 8
end

return score
end


# WAVE 4 - The method highest_score_from returns the winning word and winning score; checks ties
def highest_score_from(words)
Comment on lines +85 to +86
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍


winner = {word: nil, score: 0}
words.each do |word|

if score_word(word) > winner[:score]
winner[:word] = word
winner[:score] = score_word(word)
elsif score_word(word) == winner[:score]
if ((winner[:word]).length != 10) && (word.length < (winner[:word]).length || word.length == 10)
winner[:word] = word
winner[:score] = score_word(word)
end
end
end
return winner
end