forked from AdaGold/adagrams-py
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Spruce - Ngozi Amaefule #42
Open
ngoziamaefule
wants to merge
5
commits into
Ada-C16:master
Choose a base branch
from
ngoziamaefule: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
5 commits
Select commit
Hold shift + click to select a range
2d750ed
completed draw_letters function by randomly choosing a letter and add…
shainabeth 6738500
Wave 02 complete; all tests passed
ngoziamaefule 82e5da0
Completed Wave 2 by adding a scoring system that returns the sum of t…
shainabeth 6a9cedc
Wave 04 Complete; passed all tests. Invoked function from Wave 03 to …
ngoziamaefule 2470532
Refactoring complete
ngoziamaefule 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 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,146 @@ | ||
import random | ||
|
||
POOL_OF_LETTERS = { | ||
'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 | ||
} | ||
|
||
# Wave 01 | ||
|
||
""" | ||
The draw_letters function builds a hand of 10 letters | ||
for the user. The letters are randomly drawn from the | ||
pool of letters. | ||
""" | ||
|
||
def draw_letters(): | ||
pass | ||
pool_of_letters = POOL_OF_LETTERS.copy() | ||
list_of_letters = list(pool_of_letters.keys()) | ||
|
||
draw_ten = [] | ||
|
||
while len(draw_ten) < 10: | ||
random_letter = random.randint(0, len(list_of_letters) - 1) | ||
letter = list_of_letters[random_letter] | ||
|
||
if pool_of_letters[letter] == 0: | ||
continue | ||
|
||
draw_ten.append(letter) | ||
pool_of_letters[letter] -= 1 | ||
|
||
|
||
return draw_ten | ||
|
||
# Wave 02 | ||
|
||
""" | ||
The use_available_letters function checks to see | ||
whether or not the input word only uses characters | ||
that are contained within a collection (or hand) | ||
of drawn letters. | ||
""" | ||
|
||
def uses_available_letters(word, letter_bank): | ||
pass | ||
letter_list = letter_bank[:] | ||
letter_map = {} | ||
|
||
if len(word) > len(letter_list): | ||
return False | ||
|
||
whole_word = [] | ||
for letter in letter_list: | ||
if letter in letter_map: | ||
letter_map[letter] += 1 | ||
else: | ||
letter_map[letter] = 1 | ||
|
||
for letter in word: | ||
if letter not in letter_map.keys() or letter_map[letter] == 0: | ||
return False | ||
|
||
whole_word.append(letter) | ||
letter_map[letter] -= 1 | ||
|
||
return len(whole_word) == len(word) | ||
|
||
# Wave 03 | ||
|
||
""" | ||
The score_word function returns the score of a given word as | ||
defined by the Adagrams game. | ||
""" | ||
|
||
def score_word(word): | ||
pass | ||
score_map = { | ||
"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 | ||
} | ||
|
||
LONG_WORD_BONUS = 8 | ||
LONG_WORD_BONUS_LENGTH = 7 | ||
BASIC_SCORE = 0 | ||
|
||
score = LONG_WORD_BONUS if len(word) >= LONG_WORD_BONUS_LENGTH else BASIC_SCORE | ||
|
||
for letter in word.upper(): | ||
if letter in score_map: | ||
score += score_map[letter] | ||
|
||
return score | ||
|
||
# Wave 04 | ||
|
||
""" | ||
The get_highest_word_score function checks for the | ||
highest scored word that the user has submitted. | ||
""" | ||
|
||
def get_highest_word_score(word_list): | ||
pass | ||
score_dict = {} | ||
max_score = 0 | ||
|
||
for word in word_list: | ||
score_dict[word] = score_word(word) | ||
|
||
max_score = max(score_dict.values()) | ||
shortest_word_length = 10 | ||
shortest_word = None | ||
|
||
for word, score in score_dict.items(): | ||
if score == max_score: | ||
if len(word) == 10: | ||
return word, score | ||
elif len(word) < shortest_word_length: | ||
shortest_word_length = len(word) | ||
shortest_word = word | ||
|
||
return shortest_word, max_score |
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.
Good job making a copy! Otherwise we'd side-effect the letter bank and destroy the letters in it!