-
Notifications
You must be signed in to change notification settings - Fork 134
Ada C19 Amethyst Kaliane V. #125
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,100 @@ | ||
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 | ||
} | ||
|
||
SCORE_CHART = { | ||
'A': 1, | ||
'B': 3, | ||
'C': 3, | ||
'D': 2, | ||
'E': 1, | ||
'F': 4, | ||
'G': 2, | ||
'H': 4, | ||
'I': 1, | ||
'J': 8, | ||
'K': 5, | ||
'L': 1, | ||
'M': 3, | ||
'N': 1, | ||
'O': 1, | ||
'P': 3, | ||
'Q': 10, | ||
'R': 1, | ||
'S': 1, | ||
'T': 1, | ||
'U': 1, | ||
'V': 4, | ||
'W': 4, | ||
'X': 8, | ||
'Y': 4, | ||
'Z': 10 | ||
} | ||
|
||
def draw_letters(): | ||
pass | ||
letters = [] | ||
pool = LETTER_POOL.copy() | ||
while len(letters) < 10: | ||
hand = random.choice(list(pool)) | ||
if pool[hand] <= 0: | ||
continue | ||
pool[hand] -= 1 | ||
letters.append(hand) | ||
return letters | ||
Comment on lines
61
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you made ✨Hard Mode✨! Using
The tests do not focus on the statistical accuracy of your code. Instead, the tests check for outcomes that should NOT be possible such as having more than 1 Z in our hand. Hard Mode is a totally valid way of making this project so don't fret about resubmitting or redoing this (if you have time, you definitely can but it's low-priority compared to the other Learn, PSE, and projects you also need to focus on). |
||
|
||
def uses_available_letters(word, letter_bank): | ||
pass | ||
bank = letter_bank.copy() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of a copy to avoid side effects on |
||
for character in word: | ||
character = character.upper() | ||
if character in bank: | ||
bank.remove(character) | ||
else: | ||
return False | ||
return True | ||
Comment on lines
+74
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can refactor this slightly by using for character in word.upper():
if character not in bank:
return False
bank.remove(character)
return True |
||
|
||
def score_word(word): | ||
pass | ||
score = 0 | ||
for character in word: | ||
character = character.upper() | ||
score += SCORE_CHART[character] | ||
if len(word) >= 7: | ||
score += 8 | ||
return score | ||
Comment on lines
82
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Nice work! This is a really clean solution ✨ |
||
|
||
def get_highest_word_score(word_list): | ||
pass | ||
candidates = [(w, score_word(w)) for w in word_list] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 Beautiful use of a list comprehension to build a list of tuples!! |
||
highest_score = max(candidates, key = lambda c: c[1]) | ||
ties = [c for c in candidates if c[1] == highest_score[1]] | ||
if len(ties) == 1: | ||
return ties[0] | ||
for c in candidates: | ||
if len(c[0]) == 10: | ||
return c | ||
return min(ties, key=lambda t: len(t[0])) | ||
Comment on lines
+93
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 Great use of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work using the uppercase naming convention to indicate that this is a constant variable ✨
Since
LETTER_POOL
is accessed by one function, it would be reasonable to place them inside the functions rather than as a constant. There are tradeoffs, the structures would clutter the function some, but it keeps the data as close as possible to where it's being used, and would mean other functions couldn't access it to accidentally alter the contents.