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

Sockets - Chantal & Tatiana #24

Open
wants to merge 7 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}"
}
]
}
115 changes: 115 additions & 0 deletions lib/adagrams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
require 'awesome_print'
require 'pry'

def draw_letters
letters = [
"A", "A", "A", "A", "A", "A", "A", "A", "A",
"B", "B",
"C", "C",

Choose a reason for hiding this comment

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

This data would be a great thing to store in a constant!

"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

Choose a reason for hiding this comment

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

You don't need to call draw_letters here. Your job is to define the method, the tests and the wave_X_game.rb will handle calling it.


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)

Choose a reason for hiding this comment

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

When you call delete_at here, you modify the original hand of letters! While that makes the tests pass, it also introduces a bug:

hand = ['A', 'B', 'C']
word = 'ABC'
puts uses_available_letters?(word, hand)
# => true
puts uses_available_letters?(word, hand)
# => false

How might you address this problem?

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'

Choose a reason for hiding this comment

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

While this case statement works, it means that the information about which letter has which score is locked into this piece of code, and can't easily be used elsewhere. For example, if you wanted to display the value of each letter in a hand, you would need to repeat this work.

An alternative approach would be to store the letter scores in a hash, something like this:

LETTER_SCORES = {
  "A" => 1
  "B" => 3,
  "C" => 3,
  "D" => 2,
  # ...
}

Then to get the score for a letter, you can say LETTER_SCORES[letter].

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 = []

Choose a reason for hiding this comment

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

Watch your indentation through here. Have you installed rubocop and rufo to automatically adjust your formatting?

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 = find_best_word.first

Choose a reason for hiding this comment

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

Please remove debugging output (like line 100) before submitting projects.

shortest = 10

find_best_word.each do |entry|
if entry[:word].length == 10
return winner = entry
elsif entry[:word].length < shortest
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