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

Working copy #23

Open
wants to merge 6 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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Local File",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${file}"
}
]
}
117 changes: 117 additions & 0 deletions lib/adagrams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
require 'awesome_print'
require 'pry'

def draw_letters
letters = [
"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", "Y",
"Z"
]
drawn_letters = letters.sample(10)
return drawn_letters
end


draw_letters

def uses_available_letters?(input, letters_in_hand)
input.each_char do |letter|
index = letters_in_hand.index(letter)
if index.nil?
return false
else
letters_in_hand.delete_at(index)
end
end
return true
end

def score_word (word)
score = 0
word.upcase.each_char do |letter|

case letter
when "A", 'E', 'I', 'O', 'U', 'L', 'R', 'N', '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.length > 6 && word.length < 11
score += 8
end

return score

end


def highest_score_from (words)

score_list = words.map do |element|
{ word: element, score: score_word(element) }
end

find_best_word = []
max = 0

score_list.each do |element|
if element[:score] > max
find_best_word = [element]
max = element[:score]
elsif element[:score] == max
find_best_word << element
end
end
p find_best_word
winner = []
shortest = find_best_word[0][:word].length

find_best_word.each do |entry|
if entry[:word].length == 10
winner << entry
break
elsif entry[:word].length < shortest
puts ">>>>>>>>>>>> #{entry}"
winner << [entry]
shortest = entry[:word].length
end
end

return winner
end

1 change: 1 addition & 0 deletions specs/adagrams_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
end

end


describe 'score_word method' do
it 'returns an accurate numerical score according to the score chart' do
Expand Down
3 changes: 2 additions & 1 deletion wave-1-game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def display_drawn_letters(letters)

def run_game
display_welcome_message
display_drawn_letters(draw_letters)
display_drawn_letters
end

run_game