forked from AdaGold/adagrams-py
-
Notifications
You must be signed in to change notification settings - Fork 89
Tiger - Lily & Stacy #59
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
Open
im-stacy
wants to merge
6
commits into
Ada-C18:master
Choose a base branch
from
im-stacy:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,81 @@ | ||
|
||
import random | ||
import copy | ||
POOL_OF_LETTERS = {"A" : 9, "N" : 6, "B" : 2, "O" : 8, "C" : 2, "P" : 2, "D" : 4 ,"Q" : 1, "E" : 12, "R" : 6, "F" : 2, "S" : 4, "G" : 3, "T" : 6, "H" : 2, "U" : 4, "I" : 9, "V" : 2, "J" : 1 , "W" : 2, "K" : 1, "X" : 1, "L" : 4, "Y" : 2, "M" : 2, "Z" : 1} | ||
|
||
def draw_letters(): | ||
pass | ||
distribution_of_letters = copy.deepcopy(POOL_OF_LETTERS) | ||
letters = [] | ||
while len(letters) < 10: | ||
userletters = random.choice(list(distribution_of_letters.items())) | ||
if userletters[1] > 0: | ||
letters.append(userletters[0]) | ||
distribution_of_letters[userletters[0]]-=1 | ||
return letters | ||
# solution 2(try random.sample) | ||
# letter_list = list(distribution_of_letters.keys()) | ||
# letter_count = list(distribution_of_letters.values()) | ||
# letters = random.sample(letter_list, k = 10, counts = letter_count) | ||
# return letters | ||
|
||
def uses_available_letters(word, letter_bank): | ||
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. 👍 |
||
pass | ||
counter = {} | ||
for letter in letter_bank: | ||
if letter in counter: | ||
counter[letter] += 1 | ||
else: | ||
counter[letter] = 1 | ||
|
||
for ch in word.upper(): | ||
if ch in counter and counter[ch] > 0: | ||
counter[ch] -= 1 | ||
else: | ||
return False | ||
return True | ||
|
||
def score_word(word): | ||
pass | ||
# use map to store letter to score relationships | ||
score_chart = { | ||
"AEIOULNRST": 1, | ||
"DG": 2, | ||
"BCMP": 3, | ||
"FHVWY": 4, | ||
"K": 5, | ||
"JX": 8, | ||
"QZ": 10 | ||
} | ||
|
||
total_score = 0 | ||
# add additional 8 points for words with special length | ||
if len(word) > 6 and len(word) < 11: | ||
total_score += 8 | ||
# find the score for each letter in word, and add score to total_score | ||
for letter, value in score_chart.items(): | ||
for ch in word.upper(): | ||
if ch in letter: | ||
total_score += value | ||
|
||
return total_score | ||
|
||
|
||
def get_highest_word_score(word_list): | ||
pass | ||
# Function iterate through the word_list, and update best_word when current word is the best word | ||
# store the first word and score to the empty best_word | ||
# update best_word with new value when current score is greater than previous best score | ||
# update best_word when there's a tie and the previous word length is not 10 and either current word length is 10 or shorter than previous word length | ||
best_word = None | ||
|
||
for word in word_list: | ||
score = score_word(word) | ||
|
||
if not best_word: | ||
best_word = (word, score) | ||
Comment on lines
+71
to
+72
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! We could also do this on line 67 initially: best_word = (word_list[0], score_word(word_list[0])) |
||
|
||
elif score > best_word[1]: | ||
best_word = (word, score) | ||
|
||
elif score == best_word[1] and len(best_word[0]) != 10 and (len(word) == 10 or len(word) < len(best_word[0])): | ||
best_word = (word, score) | ||
|
||
return best_word | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Oh what an interesting way to handle checking the letter and the quantity!