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

Cheetahs - Emma and Alyssa #70

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
57 changes: 57 additions & 0 deletions adagrams/const_dicts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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_DICT= {
"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,
}
48 changes: 44 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
import random
from adagrams.const_dicts import *

Choose a reason for hiding this comment

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

Great!


def draw_letters():
pass
letter_pool_list = []
for letter, number in LETTER_POOL.items():
letter_pool_list.extend([letter]*number)

Choose a reason for hiding this comment

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

Great way to handle the distribution!

hand_list = []
while len(hand_list) < 10:
random.shuffle(letter_pool_list)
hand_list.append(letter_pool_list.pop())
Comment on lines +9 to +11

Choose a reason for hiding this comment

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

This works well to generate a list of 10 random letters, but it's doing a lot of extra work. random.shuffle will randomize the list, and once it's randomized, selecting the first 10 letters will give you a random hand of letters. Reshuffling between each selection isn't necessary.

return hand_list

def uses_available_letters(word, letter_bank):
pass
word = word.upper()
new_letter_bank = []
new_letter_bank.extend(letter_bank)

Choose a reason for hiding this comment

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

👍

for letter in word:
if letter in new_letter_bank:
new_letter_bank.remove(letter)

Choose a reason for hiding this comment

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

Very clean solution!

else:
return False
return True


def score_word(word):
pass
word = word.upper()
sum = 0
if len(word) >= 7:
sum += 8
for letter in word:
sum += SCORE_CHART_DICT[letter]

Choose a reason for hiding this comment

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

Great SCORE_CHART_DICT design!

return sum

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

for word in word_list:
score = score_word(word)
high_word_length = len(highest_score_word)
word_length = len(word)
if score > highest_score:
highest_score = score
highest_score_word = word
elif score == highest_score:
if high_word_length == 10 and word_length < high_word_length or word_length == high_word_length:
continue
elif word_length < high_word_length or word_length == 10:
highest_score_word = word

Choose a reason for hiding this comment

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

Fantastic solution!

return (highest_score_word, highest_score)