-
Notifications
You must be signed in to change notification settings - Fork 69
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
Whales C17- Nishat Salsabil and Julie Warren Adagrams #43
base: master
Are you sure you want to change the base?
Changes from all commits
55aba18
a669eae
6540b62
5a3c4a6
1f28ee8
58a7536
f16e137
fe35680
685d27e
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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 | ||
} | ||
|
||
LETTER_SCORE_DICT = { | ||
1: ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"], | ||
2: ["D", "G"], | ||
3: ["B", "C", "M", "P"], | ||
4: ["F", "H", "V", "W", "Y"], | ||
5: ["K"], | ||
8: ["J", "X"], | ||
10: ["Q", "Z"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,80 @@ | ||
import random | ||
import copy | ||
from adagrams.constants import LETTER_POOL, LETTER_SCORE_DICT | ||
|
||
def draw_letters(): | ||
pass | ||
''' | ||
input: none | ||
output: return list of 10 strings, 1 letter each | ||
frequency of each letter cannot exceed the value of | ||
each letter in the LETTER_POOL | ||
''' | ||
hand = [] | ||
letter_freq = {} | ||
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. Excellent use of a dictionary to keep track of letters and their frequencies |
||
|
||
while len(hand) < 10: | ||
random_letter = random.choice(list(LETTER_POOL)) | ||
if random_letter in letter_freq: | ||
if letter_freq[random_letter] < LETTER_POOL[random_letter]: | ||
letter_freq[random_letter] += 1 | ||
hand.append(random_letter) | ||
else: | ||
letter_freq[random_letter] = 1 | ||
hand.append(random_letter) | ||
return(hand) | ||
|
||
|
||
def uses_available_letters(word, hand): | ||
''' | ||
input: word (a string) and hand (a list of strings, one char each) | ||
output: Returns True if each char is uniquely in hand. Returns | ||
False otherwise or if char in word is not in hand. | ||
''' | ||
word = word.upper() | ||
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! This will not introduce a side effect because strings are immutable! |
||
hand_copy = copy.deepcopy(hand) | ||
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 way to avoid side effects! |
||
for letter in word: | ||
if letter in hand_copy: | ||
hand_copy.remove(letter) | ||
elif letter not in hand_copy: | ||
return False | ||
return True | ||
|
||
def uses_available_letters(word, letter_bank): | ||
pass | ||
|
||
def score_word(word): | ||
pass | ||
''' | ||
input: word (a string of characters) | ||
output: Returns a total score based on the value of each char in | ||
word, as defined in LETTER_SCORE_DICT. Words between 7 and 10 | ||
char score an extra 8 points. | ||
''' | ||
score = 0 | ||
word = word.upper() | ||
for letter in word: | ||
for key, value in LETTER_SCORE_DICT.items(): | ||
if letter in value: | ||
score += key | ||
if 7 <= len(word) <= 10: | ||
score += 8 | ||
return score | ||
|
||
|
||
def get_highest_word_score(word_list): | ||
''' | ||
input: list of strings representing each word user has created | ||
output: returns tuple with highest scoring word and score. If tied: | ||
shortest length word is preferred, unless length is 10 char | ||
''' | ||
played_word_dict = {} | ||
for word in word_list: | ||
score = score_word(word) | ||
played_word_dict[word] = score | ||
|
||
highest_score = max(played_word_dict.values()) | ||
best_word_list = [key for key, value in played_word_dict.items()\ | ||
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. Lovely list comprehension! |
||
if value == highest_score] | ||
|
||
def get_highest_word_score(word_list): | ||
pass | ||
if len(best_word_list) > 1: | ||
for word in best_word_list: | ||
if len(word) == 10: | ||
return word, highest_score | ||
return min(best_word_list, key=len), highest_score |
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.
Yay docstrings!