-
Notifications
You must be signed in to change notification settings - Fork 68
C17 Otters - Natalya and Lin #38
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: master
Are you sure you want to change the base?
Changes from all commits
a3204c8
ef59983
3969555
b16b279
df7a175
1a5e6ea
aa0a8d7
bc57f38
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,116 @@ | ||
| 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", "E", "I", "O", "U", "L", "N", "R", "S", "T"): 1, | ||
| ("D", "G"): 2, | ||
| ("B", "C", "M", "P"): 3, | ||
| ("F", "H", "V", "W", "Y"): 4, | ||
| ("K", ): 5, | ||
| ("J", "X"): 8, | ||
| ("Q", "Z"): 10 | ||
| } | ||
|
|
||
| def draw_letters(): | ||
| pass | ||
| # Create a copy of LETTER_POOL so it won't change the original data | ||
| letter_pool_copy = LETTER_POOL.copy() | ||
| drawn_letters = [] | ||
|
|
||
| for i in range(10): | ||
| # Choose a random letter 10 times | ||
| letter = random.choice(list(letter_pool_copy.keys())) | ||
|
|
||
| # Check letter qty, updating the LETTER_POOL_copy to reflect the distribution | ||
| # if qty == 1 remove it from the copy so it won't be chosen again | ||
| # if qty > 1, decrease the qty by 1 | ||
| if letter_pool_copy[letter] == 1: | ||
| del letter_pool_copy[letter] | ||
| else: | ||
| letter_pool_copy[letter] -= 1 | ||
| drawn_letters.append(letter) | ||
| return drawn_letters | ||
|
|
||
| def uses_available_letters(word, letter_bank): | ||
| pass | ||
| # Create a copy of letter_bank so it won't change the original data | ||
| letter_bank_copy = letter_bank.copy() | ||
| word = word.upper() | ||
|
|
||
| # Check if each single character exists in leeter_bank_copy: | ||
| # if not, return False. | ||
| # if yes, remove it from letter_bank_copy | ||
| # If all letters in the letter_bank_copy, return True | ||
| for char in word: | ||
| if char not in letter_bank_copy: | ||
| return False | ||
| letter_bank_copy.remove(char) | ||
|
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. 💯 |
||
| return True | ||
|
|
||
| def score_word(word): | ||
| pass | ||
| score = 0 | ||
| word = word.upper() | ||
|
|
||
| # Check each character in the word to find it's score in SCORE_CHART: | ||
| # sum the score of each chacracter | ||
| for letter in word: | ||
| for char, value in SCORE_CHART.items(): | ||
| if letter in char: | ||
| score += value | ||
|
Comment on lines
+83
to
+85
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. The dictionary structure of SCORE_CHART is not optimal for this problem. The setup here with tuples as keys makes it necessary to search for the letter, but a dictionary where each letter is a key and the point value is the dictionary value would remove the need for this inner loop. |
||
|
|
||
| # If the lenght of the word more than 6 characters, add 8 to the total score | ||
| if len(word) > 6: | ||
| score += 8 | ||
|
|
||
| return score | ||
|
|
||
|
|
||
| def get_highest_word_score(word_list): | ||
| pass | ||
| words_score = {} | ||
| max_value = 0 | ||
|
|
||
| # Create a dictionary of word: score. Find the highest score between current and previous word. | ||
| for word in word_list: | ||
| words_score[word] = score_word(word) | ||
| max_value = max(max_value, words_score[word]) | ||
|
|
||
| # Create a list of all words that have the highest score. | ||
| words_max_value = [word for word, score in words_score.items() if score == max_value] | ||
|
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! |
||
|
|
||
| # Check if words_max_value list has more than 1 word: | ||
| # sort the list of words based on it's length | ||
| # if the lenght of the word 10 letters: | ||
| # return the first word with the lenght 10 letters and it's score | ||
| # in all other cases return the first word in the list words_max_value as it has the fewest letters. | ||
| if len(words_max_value) > 1: | ||
| words_max_value = sorted(words_max_value, key=len) | ||
|
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. This works because the function
|
||
| for word in words_max_value: | ||
| if len(word) == 10: | ||
| return word, max_value | ||
| return words_max_value[0], max_value | ||
|
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 solution! |
||
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.
Great solution!