Skip to content
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

Amethyst Sarah Watkins #131

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 62 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,69 @@
import random

def draw_letters():
pass
#letter pool is a dictionary with letters as keys and quanity values
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}

hold_letters = []

while len(hold_letters) < 10:
letter = random.choice(list(letter_pool.keys()))

if letter_pool[letter] > 0:
hold_letters.append(letter)
letter_pool[letter] -= 1
Comment on lines +11 to +16

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we want to make sure that we are making a list of letters we the appropriate weights (if we have "A": 4 then that should correspond to ["A', "A", "A", "A"]. We could do some with an implementation could look something like this:

letters = []
for letter in LETTER_POOL: # this will give us the keys
   letters += letter * LETTER_POOL[letter]

then we could get our 10 like so:

 hold_letters = random.sample(letters, 10)   


return hold_letters


def uses_available_letters(word, letter_bank):
pass
bank_copy = letter_bank.copy()

word = word.lower()
bank_copy = [letter.lower() for letter in bank_copy]

for letter in word:
if letter in bank_copy:
bank_copy.remove(letter)
else:
return False
return True


def score_word(word):
pass
letter_scores = {
"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
}

score = 0
for letter in word.upper():
score += letter_scores[letter]
if len(word) >= 7 and len(word) <= 10:
score += 8
return score


def get_highest_word_score(word_list):
pass
highest_score = 0
winning_word = ""

for word in word_list:
score = score_word(word)

if score > highest_score:
highest_score = score
winning_word = word
elif score == highest_score:
if len(word) == 10:
winning_word = word
elif len(word) < len(winning_word) and len(winning_word) != 10:
winning_word = word

return (winning_word, highest_score)