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

Pine - Victoria Duke and Michelle Bodart #32

Open
wants to merge 14 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
126 changes: 122 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,129 @@
import random
import english_dictionary
from english_dictionary.scripts.read_pickle import get_dict
# This dictionary package is not a comprehensive list of all English words.
# The dictionary does not recognize suffixes, e.g. "voted" is not recognized, but "vote" is.
english_dict = get_dict()

LETTER_POOL = ["A", "A", "A", "A", "A", "A", "A", "A", "A",
"B", "B",
"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"]

SCORE_CHART = {
"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
}

def draw_letters():
pass
is_freq_correct = False
#Loop to check if letter frequency is correct in relation to LETTER_POOL
while is_freq_correct == False:
letter_bank = random.choices(LETTER_POOL, k=10)
# random.choices() documentation at https://docs.python.org/3/library/random.html
is_freq_correct = True
#Begin with assuming frequency is correct
#print(letter_bank)
for letter in letter_bank:
if letter_bank.count(letter) > LETTER_POOL.count(letter):
is_freq_correct = False
#Letter frequency is incorrect. Breaks the loop and creates new hand of letter.
break
Comment on lines +73 to +77

Choose a reason for hiding this comment

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

Great error checking!

#print(f"After freq check {letter_bank}")
return letter_bank

#for testing: draw_letters()

def uses_available_letters(word, letter_bank):
pass
word = word.upper()

Choose a reason for hiding this comment

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

👍

#Return True if every letter in input word is available (in the right quantities) in letter_bank
for letter in word:
if letter in letter_bank and word.count(letter) <= letter_bank.count(letter):
continue
else:
#Will return False if input word uses letters not in letter_bank,
# and/or over the quantity of the letter available in letter_bank.
return False
Comment on lines +87 to +92

Choose a reason for hiding this comment

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

Another way to write this conditional is:

Suggested change
if letter in letter_bank and word.count(letter) <= letter_bank.count(letter):
continue
else:
#Will return False if input word uses letters not in letter_bank,
# and/or over the quantity of the letter available in letter_bank.
return False
if not letter in letter_bank or word.count(letter) > letter_bank.count(letter):
return False

return True

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

Choose a reason for hiding this comment

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

💯


def get_highest_word_score(word_list):
pass

highest_score = 0
highest_words = []
for word in word_list:
score = score_word(word)
if highest_score < score:
highest_score = score
highest_words = [word]
elif highest_score == score:
highest_words.append(word)

Choose a reason for hiding this comment

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

Great solution!


if len(highest_words) == 1: # This means that there is no tie
return(highest_words[0], highest_score)
else: # This means there is a tie, applies tie-breaking logic
for word in highest_words:
if len(word) == 10:
return(word, highest_score)
return(min(highest_words, key=len), highest_score)
Comment on lines +119 to +122

Choose a reason for hiding this comment

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

👍


def word_in_english_dictionary(word):
word = word.lower()
if word in english_dict.keys():
return True
else:
return False
Comment on lines +124 to +129

Choose a reason for hiding this comment

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

Nice extension!

4 changes: 4 additions & 0 deletions adagrams/ui_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def display_needs_valid_input_message():
print("You entered in a word that contains characters not in the letter bank")
display_game_instructions()

def display_needs_valid_input_message_2():
print("You entered in a word that contains characters not in the letter bank or is not in the English dictionary")
display_game_instructions()

def display_score(score):
print(f"Your submitted anagram scored {score} points")

Expand Down
33 changes: 30 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from adagrams.ui_helper import *
from adagrams.game import draw_letters, uses_available_letters, score_word, get_highest_word_score
from adagrams.game import draw_letters, uses_available_letters, score_word, get_highest_word_score, word_in_english_dictionary

def wave_1_run_game():
display_welcome_message()
Expand All @@ -14,7 +14,7 @@ def wave_1_run_game():
display_retry_instructions()
continue_input = input()
game_continue = continue_input == "y"

display_goodbye_message()

def wave_2_run_game():
Expand Down Expand Up @@ -84,6 +84,31 @@ def wave_4_run_game():
display_highest_score(get_highest_word_score(played_words))
display_goodbye_message()

def wave_5_run_game():
display_welcome_message()
game_continue = True
played_words = []
while game_continue:
print("Let's draw 10 letters from the letter pool...")
letter_bank = draw_letters()
display_drawn_letters(letter_bank)
display_game_instructions()
user_input_word = input()

while not (uses_available_letters(user_input_word, letter_bank) and word_in_english_dictionary(user_input_word)):
display_needs_valid_input_message_2()
user_input_word = input()

score = score_word(user_input_word)
display_score(score)
played_words.append(user_input_word)

display_retry_instructions()
continue_input = input()
game_continue = continue_input == "y"
display_highest_score(get_highest_word_score(played_words))
display_goodbye_message()

def main(wave):
if(wave == 1):
wave_1_run_game()
Expand All @@ -93,8 +118,10 @@ def main(wave):
wave_3_run_game()
elif(wave == 4):
wave_4_run_game()
elif(wave == 5):
wave_5_run_game()
else:
print("Please input a wave number. Valid wave numbers are 1, 2, 3, 4.")
print("Please input a wave number. Valid wave numbers are 1, 2, 3, 4, 5.")

if __name__ == "__main__":
args = sys.argv
Expand Down
13 changes: 12 additions & 1 deletion tests/test_wave_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ def test_uses_available_letters_does_not_change_letter_bank():
# Assert
assert is_valid == True
assert letters == letters_copy


# Student made test
def test_uses_available_letters_not_case_sensitive():
# Arrange
letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
word = "acd"

# Act
is_valid = uses_available_letters(word, letters)

# Assert
assert is_valid == True
13 changes: 12 additions & 1 deletion tests/test_wave_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,15 @@ def test_get_highest_word_tie_same_length_prefers_first():
assert score_word(words[0]) == 18
assert score_word(words[1]) == 18
assert best_word[0] == words[0]
assert best_word[1] == 18
assert best_word[1] == 18

# Student made test, not used
# def test_get_highest_word_input_empty_list():
# # Arrange
# words = []

# # Act
# best_word = get_highest_word_score(words)

# # Assert
# assert best_word == (None, 0)
26 changes: 26 additions & 0 deletions tests/test_wave_05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from adagrams.game import word_in_english_dictionary


def test_word_in_english_dictionary_valid_word_returns_true():
# Arrange
word = "banana"

# ACT
is_valid = word_in_english_dictionary(word)

# Assert
assert is_valid == True



def test_word_in_english_dictionary_invalid_word_returns_false():
# Arrange
word = "xlkdfa;elkfjl"

# Act
is_valid = word_in_english_dictionary(word)

# Assert
assert is_valid == False

Choose a reason for hiding this comment

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

Fantastic!