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

Amber Tanaka: Orca Whale #54

Open
wants to merge 4 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
108 changes: 104 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,111 @@
import random
import copy
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
}
LETTER_POINTS = {
Copy link

Choose a reason for hiding this comment

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

Nice use of consts!

'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
}
##----------- WAVE 1 ----------- ##
def draw_letters():
pass
letter_pool = copy.deepcopy(LETTER_POOL)
chosen_letters = []
while len(chosen_letters) < 10:
random_letter = random.choice(list(letter_pool))
if letter_pool[random_letter] > 0:
chosen_letters.append(random_letter)
letter_pool[random_letter] -= 1
Comment on lines +63 to +67
Copy link

Choose a reason for hiding this comment

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

Very clever! One small improvement: the call to list repeatedly transforms the keys of the dictionary into a list. By putting this outside the loop and assigning it to a variable we can reduce some duplicated effort.

return chosen_letters


##----------- WAVE 2 ----------- ##
def uses_available_letters(word, letter_bank):
pass
letter_bank_copy = copy.deepcopy(letter_bank)
new_word = word.upper()
for letter in new_word:
if letter not in letter_bank_copy:
return False
else:
letter_bank_copy.remove(letter)
return True
Comment on lines 72 to +80
Copy link

Choose a reason for hiding this comment

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

Nice compact and clean!


##----------- WAVE 3 ----------- ##
def score_word(word):
pass
points = 0
cased_word = word.upper()
if len(cased_word) >= 7:
points += 8
for letter in cased_word:
points += LETTER_POINTS[letter]

return points
Comment on lines 83 to +91
Copy link

Choose a reason for hiding this comment

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

Gorgeous!


##----------- WAVE 4 ----------- ##
def get_highest_word_score(word_list):
pass
champ_list = []
best_word = word_list[0]
high_score = score_word(best_word)
champ_list.append(best_word)
champ_list.append(high_score)
for word in word_list:
if score_word(word) > champ_list[1]:
champ_list[0] = word
champ_list[1] = score_word(word)
elif score_word(word) == champ_list[1] and len(word) < len(champ_list[0]) and len(champ_list[0]) != 10:
champ_list[0] = word
champ_list[1] = score_word(word)
elif score_word(word) == champ_list[1] and len(word) == 10 and len(champ_list[0]) != 10:
champ_list[0] = word
champ_list[1] = score_word(word)
return champ_list
Comment on lines +100 to +110
Copy link

Choose a reason for hiding this comment

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

This works great! As an extra exercise, can you consider how you might write this differently by nesting some of your conditional blocks? Do you think this would make it more or less readable? There's no right answer here, it's subjective!


1 change: 0 additions & 1 deletion tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def test_draw_letters_is_list_of_letter_strings():
assert len(elem) == 1

def test_letter_not_selected_too_many_times():

for i in range(1000):
# Arrange/Act
letters = draw_letters()
Expand Down
11 changes: 11 additions & 0 deletions tests/test_wave_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from adagrams.game import uses_available_letters


def test_uses_available_letters_true_word_in_letter_bank():

# Arrange
letters = ["D", "O", "G", "X", "X", "X", "X", "X", "X", "X"]
word = "DOG"
Expand All @@ -13,7 +15,9 @@ def test_uses_available_letters_true_word_in_letter_bank():
# Assert
assert is_valid == True


def test_uses_available_letters_false_word_in_letter_bank():

# Arrange
letters = ["D", "O", "X", "X", "X", "X", "X", "X", "X", "X"]
word = "DOG"
Expand All @@ -24,7 +28,10 @@ def test_uses_available_letters_false_word_in_letter_bank():
# Assert
assert is_valid == False



def test_uses_available_letters_false_word_overuses_letter():

# Arrange
letters = ["A", "X", "X", "X", "X", "X", "X", "X", "X", "X"]
word = "AAA"
Expand All @@ -35,7 +42,9 @@ def test_uses_available_letters_false_word_overuses_letter():
# Assert
assert is_valid == False


def test_uses_available_letters_does_not_change_letter_bank():

# Arrange
letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
letters_copy = letters[:]
Expand All @@ -48,7 +57,9 @@ def test_uses_available_letters_does_not_change_letter_bank():
assert is_valid == True
assert letters == letters_copy


def test_uses_available_letters_ignores_case():
pass
# Arrange
letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]

Expand Down
7 changes: 7 additions & 0 deletions tests/test_wave_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@
from adagrams.game import score_word

def test_score_word_accurate():

# Assert
assert score_word("A") == 1
assert score_word("DOG") == 5
assert score_word("WHIMSY") == 17


def test_score_word_accurate_ignores_case():

# Assert
assert score_word("a") == 1
assert score_word("dog") == 5
assert score_word("wHiMsY") == 17


def test_score_zero_for_empty():
pass
# Assert
assert score_word("") == 0


def test_score_extra_points_for_seven_or_longer():
pass
# Assert
assert score_word("XXXXXXX") == 64
assert score_word("XXXXXXXX") == 72
Expand Down
8 changes: 8 additions & 0 deletions tests/test_wave_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from adagrams.game import score_word, get_highest_word_score

def test_get_highest_word_score_accurate():

# Arrange
words = ["X", "XX", "XXX", "XXXX"]

Expand All @@ -14,7 +15,9 @@ def test_get_highest_word_score_accurate():
assert best_word[0] == "XXXX"
assert best_word[1] == 32


def test_get_highest_word_score_accurate_unsorted_list():

# Arrange
words = ["XXX", "XXXX", "XX", "X"]

Expand All @@ -26,6 +29,7 @@ def test_get_highest_word_score_accurate_unsorted_list():
assert best_word[1] == 32

def test_get_highest_word_tie_prefers_shorter_word():

# Arrange
words = ["MMMM", "WWW"]

Expand All @@ -39,6 +43,7 @@ def test_get_highest_word_tie_prefers_shorter_word():
assert best_word[1] == 12

def test_get_highest_word_tie_prefers_shorter_word_unsorted_list():
pass
# Arrange
words = ["WWW", "MMMM"]

Expand All @@ -52,6 +57,7 @@ def test_get_highest_word_tie_prefers_shorter_word_unsorted_list():
assert best_word[1] == 12

def test_get_highest_word_tie_prefers_ten_letters():
pass
# Arrange
words = ["AAAAAAAAAA", "BBBBBB"]

Expand All @@ -63,6 +69,7 @@ def test_get_highest_word_tie_prefers_ten_letters():
assert best_word[1] == 18

def test_get_highest_word_tie_prefers_ten_letters_unsorted_list():
pass
# Arrange
words = ["BBBBBB", "AAAAAAAAAA"]

Expand All @@ -74,6 +81,7 @@ def test_get_highest_word_tie_prefers_ten_letters_unsorted_list():
assert best_word[1] == 18

def test_get_highest_word_tie_same_length_prefers_first():
pass
# Arrange
words = ["AAAAAAAAAA", "EEEEEEEEEE"]

Expand Down