From dc65e8004b2d7c64ca03368f6bd24cae6f9281de Mon Sep 17 00:00:00 2001 From: Allie Soliz Date: Mon, 20 Mar 2023 22:59:45 -0400 Subject: [PATCH 01/10] pass test_wave_01 --- adagrams/game.py | 48 +++++++++++++++++++++++++++++++++-- tests/test_wave_01.py | 58 +++++++++++++++++++++++-------------------- 2 files changed, 77 insertions(+), 29 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..5ce0a161 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,11 +1,55 @@ +import random + +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 +} + + def draw_letters(): - pass + letter_list = [] + + while len(letter_list) != 10: + # letter, quantity = random.choice(list(LETTER_POOL.items())) + letter = random.choice(list(LETTER_POOL.keys())) + if LETTER_POOL[letter] > 0: + letter_list.append(letter) + LETTER_POOL[letter] -= 1 + + return letter_list + def uses_available_letters(word, letter_bank): pass + def score_word(word): pass + def get_highest_word_score(word_list): - pass \ No newline at end of file + pass diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index ef48e03b..ee00b278 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -3,34 +3,35 @@ from adagrams.game import draw_letters 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, + '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 } + def test_draw_letters_draws_ten(): # Arrange/Act letters = draw_letters() @@ -38,6 +39,7 @@ def test_draw_letters_draws_ten(): # Assert assert len(letters) == 10 + def test_draw_letters_is_list_of_letter_strings(): # Arrange/Act letters = draw_letters() @@ -49,6 +51,7 @@ def test_draw_letters_is_list_of_letter_strings(): assert type(elem) == str assert len(elem) == 1 + def test_letter_not_selected_too_many_times(): for i in range(1000): @@ -61,11 +64,12 @@ def test_letter_not_selected_too_many_times(): letter_freq[letter] += 1 else: letter_freq[letter] = 1 - + # Assert for letter in letters: assert letter_freq[letter] <= LETTER_POOL[letter] + def test_draw_letters_returns_different_hands(): # Arrange/Act hand1 = draw_letters() @@ -73,4 +77,4 @@ def test_draw_letters_returns_different_hands(): hand3 = draw_letters() # Assert - assert hand1 != hand2 or hand2 != hand3 \ No newline at end of file + assert hand1 != hand2 or hand2 != hand3 From 5b58aa8c173016dd2f49c52628ea102a694069da Mon Sep 17 00:00:00 2001 From: Allie Soliz Date: Mon, 20 Mar 2023 23:26:30 -0400 Subject: [PATCH 02/10] pass test-wave-02 --- adagrams/game.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5ce0a161..c173b5d6 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -44,7 +44,13 @@ def draw_letters(): def uses_available_letters(word, letter_bank): - pass + letter_bank_copy = letter_bank.copy() + for letter in word.upper(): + if letter in letter_bank_copy: + letter_bank_copy.remove(letter) + else: + return False + return True def score_word(word): From 8b05ebab968310cd1ea342cbedaa8706337cde33 Mon Sep 17 00:00:00 2001 From: Allie Soliz Date: Mon, 20 Mar 2023 23:52:48 -0400 Subject: [PATCH 03/10] pass test_wave_03 --- adagrams/game.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index c173b5d6..d3a273fd 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -54,7 +54,24 @@ def uses_available_letters(word, letter_bank): def score_word(word): - pass + SCORE_CHART= { + "AEIOULNRST": 1, + "DG": 2, + "BCMP": 3, + "FHVWY": 4, + "K": 5, + "JX": 8, + "QZ": 10 + } + score = 0 + + for key, value in SCORE_CHART.items(): + for letter in word.upper(): + if letter in key: + score += value + if 7 <= len(word) <= 10: + score +=8 + return score def get_highest_word_score(word_list): From 4ccb33aa1b8fdef1a97cd8ec84f8c6fd22798981 Mon Sep 17 00:00:00 2001 From: Allie Soliz Date: Tue, 21 Mar 2023 00:37:02 -0400 Subject: [PATCH 04/10] pass test_wave_04 --- adagrams/game.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index d3a273fd..67320d4d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -54,7 +54,7 @@ def uses_available_letters(word, letter_bank): def score_word(word): - SCORE_CHART= { + SCORE_CHART = { "AEIOULNRST": 1, "DG": 2, "BCMP": 3, @@ -70,9 +70,35 @@ def score_word(word): if letter in key: score += value if 7 <= len(word) <= 10: - score +=8 + score += 8 return score def get_highest_word_score(word_list): - pass + best_word = "" + highest_score = 0 + + for i in range(0, len(word_list)): + current_word_score = score_word(word_list[i]) + if current_word_score > highest_score: + best_word = word_list[i] + highest_score = current_word_score + + elif current_word_score == highest_score: + if (len(word_list[i]) == 10) and (len(best_word) == 10): + best_word = best_word + highest_score = highest_score + elif (len(word_list[i]) == 10) and (len(best_word) != 10): + best_word = word_list[i] + highest_score = current_word_score + elif (len(word_list[i]) != 10) and (len(best_word) == 10): + best_word = best_word + highest_score = highest_score + elif len(word_list[i]) > len(best_word): + best_word = best_word + highest_score = highest_score + elif len(word_list[i]) < len(best_word): + best_word = word_list[i] + highest_score = current_word_score + + return best_word, highest_score From 9cc7427b9fd4d6272a523043c6f74411a7cf50bc Mon Sep 17 00:00:00 2001 From: Allie Soliz Date: Tue, 21 Mar 2023 08:47:14 -0400 Subject: [PATCH 05/10] cleanup spaces --- adagrams/game.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 67320d4d..c6cf3115 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -34,7 +34,6 @@ def draw_letters(): letter_list = [] while len(letter_list) != 10: - # letter, quantity = random.choice(list(LETTER_POOL.items())) letter = random.choice(list(LETTER_POOL.keys())) if LETTER_POOL[letter] > 0: letter_list.append(letter) @@ -100,5 +99,4 @@ def get_highest_word_score(word_list): elif len(word_list[i]) < len(best_word): best_word = word_list[i] highest_score = current_word_score - return best_word, highest_score From a40b65e95064f3d434687b474763524c6398cd17 Mon Sep 17 00:00:00 2001 From: Allie Soliz Date: Tue, 21 Mar 2023 08:54:10 -0400 Subject: [PATCH 06/10] adds commentary for draw_letters() function --- adagrams/game.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index c6cf3115..5e51650e 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -33,12 +33,18 @@ def draw_letters(): letter_list = [] + # While the length of letter_list list is not 10, continue finding an available letter while len(letter_list) != 10: + # convert the keys in the LETTER_POOL dictionary into a list + # randomly choose a letter form this list letter = random.choice(list(LETTER_POOL.keys())) + # check if the random letter selected is available in the LETTER_POOL dicrionary if LETTER_POOL[letter] > 0: + # if the letter is available, append the selected letter to the letter_list list letter_list.append(letter) + # once the letter is used, decrement the quantity available for this letter in the LETTER_POOL dictionary LETTER_POOL[letter] -= 1 - + # return letter_list list that contains 10 randomly selected letters return letter_list From e8cb3ab47a882b71b1988ca0ba5b95c5fa0fdb3b Mon Sep 17 00:00:00 2001 From: Allie Soliz Date: Tue, 21 Mar 2023 08:57:11 -0400 Subject: [PATCH 07/10] adds commentary for score_word(word) function --- adagrams/game.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/adagrams/game.py b/adagrams/game.py index 5e51650e..21d7ee4a 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -49,12 +49,18 @@ def draw_letters(): def uses_available_letters(word, letter_bank): + # makes a list copy of the letter_bank list so as not to modify the original list letter_bank_copy = letter_bank.copy() + # iterates through each capitalized letter in the word the user passes in for letter in word.upper(): + # checks if the current letter if found in the letter_bank_copy list if letter in letter_bank_copy: + # if the current letter is found, remove that instance from the list letter_bank_copy.remove(letter) else: + # on the first instance the current letter is not found in the letter_bank_copy list, return False return False + # return True if all of the letters in word are found in the letter_bank list return True From c879a946e52976501e321429240059bf4aa6a918 Mon Sep 17 00:00:00 2001 From: Allie Soliz Date: Tue, 21 Mar 2023 16:29:08 -0400 Subject: [PATCH 08/10] updates commentary for uses_available_letters(word, letter_bank) function --- adagrams/game.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 21d7ee4a..7284bf9a 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -60,7 +60,7 @@ def uses_available_letters(word, letter_bank): else: # on the first instance the current letter is not found in the letter_bank_copy list, return False return False - # return True if all of the letters in word are found in the letter_bank list + # ends function and returns True if all of the letters in word are found in the letter_bank list return True From e809a406fc80bacef967136a9913aaf1847f6bd5 Mon Sep 17 00:00:00 2001 From: Allie Soliz Date: Tue, 21 Mar 2023 16:31:45 -0400 Subject: [PATCH 09/10] adds commentary for score_word(word) function --- adagrams/game.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 7284bf9a..2614e76e 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -65,6 +65,7 @@ def uses_available_letters(word, letter_bank): def score_word(word): + # SCORE_CHART is a chart that contains the point value for each letter SCORE_CHART = { "AEIOULNRST": 1, "DG": 2, @@ -74,14 +75,21 @@ def score_word(word): "JX": 8, "QZ": 10 } + # initializes score variable that will keep track of the accumulating score for each letter found in the user's word score = 0 - + # grabs the key and value of each dicionary key-pair in the SCORE_CHART dictionary for key, value in SCORE_CHART.items(): + # iterate through each letter in capitalized word for letter in word.upper(): + # searches for each letter in a key of letters from SCORE_CHART if letter in key: + # if the current letter is found in any of the keys from SCORE_CHART, add that key's value to the score score += value + # checks if the length of the word is between 7 and 10 if 7 <= len(word) <= 10: + # if the length of the word is between 7 and 10, an additional 8 bonus points are added to score score += 8 + # returns the final score return score From 849ddc5f80cbb4271885e46bd39dae5a8cc908e0 Mon Sep 17 00:00:00 2001 From: Allie Soliz Date: Tue, 21 Mar 2023 16:36:34 -0400 Subject: [PATCH 10/10] adds commentary for get_highest_word_score(word_list) function --- adagrams/game.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 2614e76e..ebec2aaf 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -94,29 +94,40 @@ def score_word(word): def get_highest_word_score(word_list): + # initialize best_word variable that will hold the best_word best_word = "" + # initialize highest_score variable that will hold the highest_score highest_score = 0 - + # iterate through numvers 0 to the length of the word_list for i in range(0, len(word_list)): + # grab the score for the current word iteration by calling score_word function current_word_score = score_word(word_list[i]) + # checks if the current_word_score iteration is greater than the highest_score if current_word_score > highest_score: + # if current_word_score is greater than highest_score, update best_word and highest_score best_word = word_list[i] highest_score = current_word_score - + # else if current_word_scre equals highest_score: elif current_word_score == highest_score: + # if current_word_score is equal to highest_score, keep first instance if (len(word_list[i]) == 10) and (len(best_word) == 10): best_word = best_word highest_score = highest_score + # else if the length of current word_list iteration is 10 while the length of best_word is not equal to 10, then update best_word and highest_score elif (len(word_list[i]) == 10) and (len(best_word) != 10): best_word = word_list[i] highest_score = current_word_score + # else if the length of current word_list iteration is not 10 while the length of best_word is equal to 10, keep current best_word and highest_score elif (len(word_list[i]) != 10) and (len(best_word) == 10): best_word = best_word highest_score = highest_score + # else if the length of current word_list iteration is greater than the length of best_word, keep current best_word and highest_score elif len(word_list[i]) > len(best_word): best_word = best_word highest_score = highest_score + # else if the length of current word_list iteration is less than the length of best_word, update best_word and highest_score elif len(word_list[i]) < len(best_word): best_word = word_list[i] highest_score = current_word_score + # return the final results of best_word and highest_score return best_word, highest_score