Skip to content
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
69 changes: 65 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,72 @@
import random

def draw_letters():
pass

letter_list = ['A','A','A','A','A','A','A','A','A','B','B',
Copy link

Choose a reason for hiding this comment

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

I would suggest making your letter_list a global constant variable LETTER_LIST this would clean up your function and remind yourself/other developers this should not be changed

'C', 'C', 'D', 'D', 'D','D','E','E','E','E','E','E','E','E',
'E','E','E','E','F','F','G','G','G','H','H','I','I','I',
'I', 'I', 'I', 'I', 'I', 'I', 'J', 'K', 'L', 'L', 'L', 'L', 'M', 'M',
'N', 'N', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O',
'P', 'P', 'Q', 'R', 'R', 'R', 'R', 'R', 'R', 'S', 'S', 'S', 'S', 'T',
'T','T','T','T','T', 'U', 'U', 'U', 'U', 'V', 'V', 'W','W', 'X', 'Y','Y','Z']
letters = letter_list.copy()
chosen_letters = []
for i in range(10):
Copy link

Choose a reason for hiding this comment

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

instead of a for loop, you could use a while loop that will continue until the length of chosen_letters is less than 10.

letter = random.choice(letters)
letters.remove(letter)
chosen_letters.append(letter)
return chosen_letters

def uses_available_letters(word, letter_bank):
pass

letters_used = letter_bank.copy()
Copy link

Choose a reason for hiding this comment

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

yay for making a copy! Definitely want to avoid side effects.

for letter in word:
if letter in letters_used:
letters_used.remove(letter)
else:
return False
break
Copy link

Choose a reason for hiding this comment

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

the break is unnecessary here. Once you return False the code after will be unreachable.

return True

def score_word(word):
pass

letter_points = {
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']
Comment on lines +34 to +40
Copy link

Choose a reason for hiding this comment

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

great way to group the data that was given

}
sum = 0
word_length = len(word)
cap_word = word.upper()
for letter in cap_word:
for score in letter_points:
if letter in letter_points[score]:
sum += score
if word_length >= 7:
sum += 8
return sum

def get_highest_word_score(word_list):
Copy link

Choose a reason for hiding this comment

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

Great way to approach finding the highest score.

pass
words_and_scores = []
for word in word_list:
score = score_word(word)
words_and_scores.append(tuple([word, score]))
num=(0, 0)
for item in words_and_scores:
if item[1]>num[1]:
num=item
elif item[1]==num[1]:
if len(num[0])==10:
break
elif len(item[0])==len(num[0]):
break
elif len(item[0])==10:
num=item
break
elif len(item[0])<len(num[0]):
num=item
return num
3 changes: 2 additions & 1 deletion tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ def test_letter_not_selected_too_many_times():

# Assert
for letter in letters:
assert letter_freq[letter] <= LETTER_POOL[letter]
if letter_freq[letter] > LETTER_POOL[letter]:
assert letter_freq[letter] <= LETTER_POOL[letter]