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

Amethyst - Elaine Watkins #105

Open
wants to merge 1 commit into
base: main
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,4 @@ Implement a function called `get_highest_word_score` in `game.py`. This method s
- In the case of tie in scores, use these tie-breaking rules:
- prefer the word with the fewest letters...
- ...unless one word has 10 letters. If the top score is tied between multiple words and one is 10 letters long, choose the one with 10 letters over the one with fewer tiles
- If the there are multiple words that are the same score and the same length, pick the first one in the supplied list
- If the there are multiple words that are the same score and the same length, pick the first one in the supplied list
165 changes: 161 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,168 @@
import random

LETTER_POOL = {
'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
}
Comment on lines +3 to +30
Copy link

@ameerrah9 ameerrah9 Mar 28, 2023

Choose a reason for hiding this comment

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

Hey Elaine! Great job completing Adagrams! Congrats on your first project at Ada 🎉 I noticed you created this data structure but you aren't making use of it. It's common practice to remove any unused code so we don't take up any unnecessary space in memory. We can discard this 😁👍🏾







def draw_letters():
pass

letter_pool = [
'J', 'K', 'Q', 'X', 'Z',
'B', 'C', 'F', 'H', 'M', 'P', 'V', 'W', 'Y',
'G',
'D', 'L', 'S', 'U',
'N', 'R', 'T',
'O',
'A', 'I',
'E'
]

weight = [
1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2,
3,
4, 4, 4, 4,
6, 6, 6,
8,
9, 9,
12
]

user_hand = []

for i in range(10):
random_choice = random.choices(letter_pool, weights=weight, k = 1)

tile = letter_pool.index(random_choice[0])
weight[tile] -= 1
if weight[tile] == 0:
weight.pop(tile)
letter_pool.pop(tile)

user_hand.append(random_choice[0])

return user_hand
Comment on lines +61 to +74
Copy link

@ameerrah9 ameerrah9 Mar 28, 2023

Choose a reason for hiding this comment

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

Amazing job with this solution! You were able to successfully use random.choices with your letter pool and their weights 👍🏾 I think this is an optimal approach to this function. I noticed you removed the weight from the letter that was grabbed using .index()! Solid approach 💯







def uses_available_letters(word, letter_bank):
pass
uppercase_word = word.upper()
for char in uppercase_word:
if char not in letter_bank or uppercase_word.count(char) > letter_bank.count(char):
return False
return True
Comment on lines 81 to +86
Copy link

@ameerrah9 ameerrah9 Mar 28, 2023

Choose a reason for hiding this comment

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

Nice use of .count()! I also noticed you returned True no matter what happens because False will only be returned in that conditional is met 👍🏾 You could also use word.upper() in your for loop instead of creating another variable in memory 🥳







def score_word(word):
pass
score_chart = {
'A': 1,
'E': 1,
'I': 1,
'O': 1,
'U': 1,
'L': 1,
'N': 1,
'R': 1,
'S': 1,
'T': 1,
'D': 2,
'G': 2,
'B': 3,
'C': 3,
'M': 3,
'P': 3,
'F': 4,
'H': 4,
'V': 4,
'W': 4,
'Y': 4,
'K': 5,
'J': 8,
'X': 8,
'Q': 10,
'Z': 10
}

Comment on lines +94 to +122

Choose a reason for hiding this comment

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

Excellent choice for this data structure 💯

cap_word = word.upper()
word_score = 0
for char in cap_word:
if score_chart[char]:
word_score += score_chart[char]
else:
continue
# if length of word is between 6 - 10
if len(cap_word) >= 7 and len(cap_word) <= 10:
word_score += 8

scores_list = list()
scores_list.append(word_score)
Comment on lines +134 to +135

Choose a reason for hiding this comment

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

I noticed you created this list but you're not using it anywhere 😄 we generally don't want to create variables we won't be using, we can discard it

return word_score
Comment on lines +123 to +136

Choose a reason for hiding this comment

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

Amazing work with this logic Elaine!







def get_highest_word_score(word_list):
pass
high_score = 0
winning_word = ""
ties = []
multiple_tie_words = []

for word in word_list:
score = score_word(word)
multiple_tie_words.append(word)

if score in ties:
if len(ties) >= 1:
winning_word = max(word_list, key=len)
if len(ties) >= 2 or len(word) != 10:
if len(word_list) == 2 and len(winning_word) == 10:
winning_word = max(word_list, key=len)
else:
winning_word = min(word_list, key=len)

if score > high_score:
high_score = score
winning_word = word

ties.append(score)

return winning_word, high_score