From 06742f11bfddd674f18a0baf373eace19558c524 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Mon, 28 Mar 2022 14:55:55 -0400 Subject: [PATCH 01/15] completed the first test in wave1 --- adagrams/game.py | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..653a4686 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,5 +1,49 @@ +import random + +# from tests.test_wave_01 import LETTER_POOL +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 + ''' + 1) importing the random module + 2) make each letter-value pair an element in a tuple/list? + put values of the letters in a list (Like 9 A's in a list, 2 B's) + 3) a method from the random module to shuffle the list + 4) list comprehension + ''' + letters = [] + for letter, number in LETTER_POOL.items(): + for i in range(number): + letters.append(letter) + random.shuffle(letters) + return letters[:10] def uses_available_letters(word, letter_bank): pass From 831b70d50b0dbaef36b5dedc4b6b6a6e784f27cb Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Mon, 28 Mar 2022 19:04:33 -0400 Subject: [PATCH 02/15] started wave2 --- adagrams/game.py | 43 +++++++++++++++++++++++++++++++------------ main.py | 2 +- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 653a4686..951b0c86 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,6 +1,5 @@ -import random - # from tests.test_wave_01 import LETTER_POOL +import random LETTER_POOL = { 'A': 9, 'B': 2, @@ -32,21 +31,41 @@ def draw_letters(): ''' - 1) importing the random module - 2) make each letter-value pair an element in a tuple/list? - put values of the letters in a list (Like 9 A's in a list, 2 B's) - 3) a method from the random module to shuffle the list - 4) list comprehension + 1) import the random module and make LETTER_POOL a global variable + 2) how should we iterate through the LETTER_POOL? + a) make each letter-value pair a dictionary as an element in a tuple/list? + B) put values of the letters in a list (Like nine A elements, two B elements, etc.) + 3) use a method from the random module to shuffle the list + 4) return the first 10 elements in the shuffled list ''' - letters = [] - for letter, number in LETTER_POOL.items(): - for i in range(number): - letters.append(letter) + # letters = [] + # for letter, number in LETTER_POOL.items(): + # for i in range(number): + # letters.append(letter) + + letters = [letter for letter, letter_frequency in LETTER_POOL.items() for number in range(letter_frequency)] + random.shuffle(letters) + return letters[:10] def uses_available_letters(word, letter_bank): - pass + ''' + 1) How do get the right quanities in letter_bank? + A) Use a helper function? + B) Iterate over the list, make a new list, and subtract? + C) Set subtraction? NO + D) Use letter_bank to determine frequency + 2) + 3) + ''' + # word_list = list(word) + # new_list = [] + # for letter in word: + # for i in range(len(letter_bank) - 1): + # if + + # print(word_list) def score_word(word): pass diff --git a/main.py b/main.py index bcd6ab0b..2bb06b44 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,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(): From 319499226ffc5fb4c16e2f3950e4493103a20372 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Mon, 28 Mar 2022 20:16:02 -0400 Subject: [PATCH 03/15] passed tests 1-4 in test_wave_02 --- adagrams/game.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 951b0c86..5beb5ff1 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -51,21 +51,21 @@ def draw_letters(): def uses_available_letters(word, letter_bank): ''' - 1) How do get the right quanities in letter_bank? - A) Use a helper function? - B) Iterate over the list, make a new list, and subtract? - C) Set subtraction? NO - D) Use letter_bank to determine frequency - 2) - 3) + 1) Iterate over each letter in word + 2) If the letter is not in letter_bank or the frequency of + the letter in word is greater than the frequency of the + letter in letter_bank... + 3) is_valid becomes False + 4) Break the loop + 5) return is_valid ''' - # word_list = list(word) - # new_list = [] - # for letter in word: - # for i in range(len(letter_bank) - 1): - # if - - # print(word_list) + is_valid = True + for letter in word: + if letter not in letter_bank or (word.count(letter) > letter_bank.count(letter)): + is_valid = False + break + return is_valid + def score_word(word): pass From f546074dd21fbb21c92accd343118f21ad437792 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Tue, 29 Mar 2022 16:22:30 -0400 Subject: [PATCH 04/15] finished wave 3 --- adagrams/game.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5beb5ff1..5ef72392 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -58,12 +58,22 @@ def uses_available_letters(word, letter_bank): 3) is_valid becomes False 4) Break the loop 5) return is_valid + 6) For the last test: the letters in word can be lower or upper case. + 7) The letter can only be used as frequent as it is in letter_bank. ''' + # letter_bank_uppercase = list(("".join(letter_bank)).upper()) + # letter_bank_lowercase = list(("".join(letter_bank)).lower()) + # letter_bank_diff_cases = tuple(letter_bank_uppercase + letter_bank_lowercase) + # print(letter_bank_diff_cases) + + word_uppercase = word.upper() + is_valid = True - for letter in word: - if letter not in letter_bank or (word.count(letter) > letter_bank.count(letter)): + for letter in word_uppercase: + if letter not in letter_bank or (word_uppercase.count(letter) > letter_bank.count(letter)): is_valid = False break + return is_valid From aa6794afdf434910a3ddcd18df65d55c10af70f3 Mon Sep 17 00:00:00 2001 From: cathos Date: Tue, 29 Mar 2022 14:00:07 -0700 Subject: [PATCH 05/15] passed two tests in wave3 --- adagrams/game.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5ef72392..4ce666a3 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -29,6 +29,17 @@ 'Z': 1 } +SCORE_CHART = { + ("A", "E", "I", "O", "U", "L", "N", "R", "S", "T") : 1, + ("D", "G") : 2, + ("B", "C", "M", "P") : 3, + ("F", "H", "V", "W", "Y") : 4, + ("K") : 5, + ("J","K") : 8, + ("Q","Z") : 10, +} + + def draw_letters(): ''' 1) import the random module and make LETTER_POOL a global variable @@ -78,7 +89,23 @@ def uses_available_letters(word, letter_bank): def score_word(word): - pass + ''' + Create a SCORE_CHART dictionary with letters: point values where letters is a tuple of letters and values are integers. + Initialize score integer. + If length of word between 7 and 10, add 8 to score. + iterate over string + iterate over the dictionary to get the point value + add to score + return score + ''' + score = 0 + if 7 <= len(word) <= 10: + score += 8 + for letter in word: + for k in SCORE_CHART: + if letter in k: + score += SCORE_CHART[k] + return score def get_highest_word_score(word_list): pass \ No newline at end of file From 698352bcfb0914c3cc30b1a92533b847449bfbbc Mon Sep 17 00:00:00 2001 From: cathos Date: Tue, 29 Mar 2022 14:11:41 -0700 Subject: [PATCH 06/15] passed all wave 3 tests --- adagrams/game.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 4ce666a3..7fd95370 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -35,7 +35,7 @@ ("B", "C", "M", "P") : 3, ("F", "H", "V", "W", "Y") : 4, ("K") : 5, - ("J","K") : 8, + ("J","X") : 8, ("Q","Z") : 10, } @@ -99,9 +99,10 @@ def score_word(word): return score ''' score = 0 - if 7 <= len(word) <= 10: + word_uppercase = word.upper() + if len(word_uppercase) >= 7 and len(word_uppercase) <= 10: score += 8 - for letter in word: + for letter in word_uppercase: for k in SCORE_CHART: if letter in k: score += SCORE_CHART[k] From 2373005f6eba54db99ec1f77a544952aef49563c Mon Sep 17 00:00:00 2001 From: cathos Date: Tue, 29 Mar 2022 15:45:06 -0700 Subject: [PATCH 07/15] started working on wave 4 --- adagrams/game.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 7fd95370..cb569fb4 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -109,4 +109,9 @@ def score_word(word): return score def get_highest_word_score(word_list): - pass \ No newline at end of file + ''' + ties: + 10 letters > fewest letters > first word + ''' + + pass From f2c774d7e50896519ca53c5925c53bd46b9200fb Mon Sep 17 00:00:00 2001 From: cathos Date: Wed, 30 Mar 2022 11:26:00 -0700 Subject: [PATCH 08/15] start of wave 4 --- adagrams/game.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index cb569fb4..b0c5932a 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -39,6 +39,35 @@ ("Q","Z") : 10, } +# ALTERNATE SCORE_CHART: +# 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(): ''' @@ -100,7 +129,7 @@ def score_word(word): ''' score = 0 word_uppercase = word.upper() - if len(word_uppercase) >= 7 and len(word_uppercase) <= 10: + if len(word_uppercase) >= 7 and len(word_uppercase) <= 10: # chaining inequalities like I had earlier should work, but why didn't it? score += 8 for letter in word_uppercase: for k in SCORE_CHART: From 2d173f259f011f4156328fa9be56bb3ed7003348 Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Wed, 30 Mar 2022 15:04:04 -0400 Subject: [PATCH 09/15] did some wave 4 pseudocode --- adagrams/game.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index cb569fb4..96861de4 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -108,10 +108,23 @@ def score_word(word): score += SCORE_CHART[k] return score + +def get_tie_break(word_list): + pass + + def get_highest_word_score(word_list): ''' ties: - 10 letters > fewest letters > first word + 10 letters > fewest letters > first word + 1) initialize an empty list variable for the highested_scoring_words + 2) initialize highested_score variable + 3) iterate over the word in word_list + 4) call score_word on each of the words + 5) store all of the highested scoring words into call score_word on each of the words + 6) if score > highested_score, overwrite the list with highest_ score_words, overwrite the highest_score with the score + 7) elif score == highested_score, add it to the highested_scoring_words + 8) if length of highested_scoring_words > 1, tie break function? ''' pass From 1db9197d0d7ac3fb5bbdbacac9ba3777d281295b Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Wed, 30 Mar 2022 15:09:10 -0400 Subject: [PATCH 10/15] worked on wave 4 pseudocode --- adagrams/game.py | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 35cd8084..2ffbd4e8 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -39,35 +39,6 @@ ("Q","Z") : 10, } -# ALTERNATE SCORE_CHART: -# 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(): ''' @@ -129,7 +100,7 @@ def score_word(word): ''' score = 0 word_uppercase = word.upper() - if len(word_uppercase) >= 7 and len(word_uppercase) <= 10: # chaining inequalities like I had earlier should work, but why didn't it? + if len(word_uppercase) >= 7 and len(word_uppercase) <= 10: score += 8 for letter in word_uppercase: for k in SCORE_CHART: @@ -154,6 +125,9 @@ def get_highest_word_score(word_list): 6) if score > highested_score, overwrite the list with highest_ score_words, overwrite the highest_score with the score 7) elif score == highested_score, add it to the highested_scoring_words 8) if length of highested_scoring_words > 1, tie break function? + 9) Tie-break should return the index of the highested scoring word + 10) the a tuple of highest_scoring_words the first element and + the score ''' pass From 661f743011aa10f70e950a0032a96f19ab50945a Mon Sep 17 00:00:00 2001 From: cathos Date: Wed, 30 Mar 2022 12:49:22 -0700 Subject: [PATCH 11/15] coded the structure of get_highest_word_score (wave 4) --- adagrams/game.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 2ffbd4e8..11f53ab2 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -109,7 +109,7 @@ def score_word(word): return score -def get_tie_break(word_list): +def get_index_tie_break(word_list): pass @@ -129,5 +129,16 @@ def get_highest_word_score(word_list): 10) the a tuple of highest_scoring_words the first element and the score ''' - - pass + highest_scoring_words = [] + high_score = 0 + high_score_index = 0 + for word in word_list: + score = score_word(word) + if score > high_score: + highest_scoring_words = [word] + high_score = score + elif score == high_score: + highest_scoring_words.append(word) + if len(highest_scoring_words) > 1: + high_score_index = get_index_tie_break(highest_scoring_words) + return highest_scoring_words[high_score_index], high_score From a9bd9f4d7445b9740a44574af9e17d6aa1e9957e Mon Sep 17 00:00:00 2001 From: cathos Date: Wed, 30 Mar 2022 15:19:54 -0700 Subject: [PATCH 12/15] partial working solution to wave 4, including tie break function --- adagrams/game.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 11f53ab2..2da7488d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -110,7 +110,16 @@ def score_word(word): def get_index_tie_break(word_list): - pass + ''' + ''' + highest_index = 0 + for i in range(len(word_list)-1): # I would skip the first item but we need to check if it is the shortest or 10 letters long. + if len(word_list[i]) == 10: + # highest_index = i # maybe return i at this point? otherwise, highest_rated will get overwritten by shorter words later. + return i + elif len(word_list[i]) < len(word_list[highest_index]): # will this work if the first word is 10 letters long? + highest_index = i + return highest_index def get_highest_word_score(word_list): From 1636590b26a056a0b760d0fa604b9c4a0bfe7a5e Mon Sep 17 00:00:00 2001 From: cathos Date: Wed, 30 Mar 2022 15:34:16 -0700 Subject: [PATCH 13/15] initial commit with all tests passing --- adagrams/game.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 2da7488d..2be990c7 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -113,7 +113,7 @@ def get_index_tie_break(word_list): ''' ''' highest_index = 0 - for i in range(len(word_list)-1): # I would skip the first item but we need to check if it is the shortest or 10 letters long. + for i in range(len(word_list)): # I would skip the first item but we need to check if it is the shortest or 10 letters long. if len(word_list[i]) == 10: # highest_index = i # maybe return i at this point? otherwise, highest_rated will get overwritten by shorter words later. return i From 567983f4f3989e27d4ab09d65cdb4d31d4e948ea Mon Sep 17 00:00:00 2001 From: cathos Date: Wed, 30 Mar 2022 15:36:48 -0700 Subject: [PATCH 14/15] added comments to tie break function --- adagrams/game.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adagrams/game.py b/adagrams/game.py index 2be990c7..4360e434 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -111,6 +111,8 @@ def score_word(word): def get_index_tie_break(word_list): ''' + Finds the winner to break a tie with rules: 10 letters > fewest letters > first word + Not sure why, but range(len(word_list)-1) didn't iterate over the loop properly. ''' highest_index = 0 for i in range(len(word_list)): # I would skip the first item but we need to check if it is the shortest or 10 letters long. From 526137be8f98682222b5d7afbde64539e8c9fd6e Mon Sep 17 00:00:00 2001 From: Esther Annorzie Date: Thu, 31 Mar 2022 15:08:39 -0400 Subject: [PATCH 15/15] added docstrings to functions --- adagrams/game.py | 87 ++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 55 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 4360e434..c4ddb241 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -42,17 +42,9 @@ def draw_letters(): ''' - 1) import the random module and make LETTER_POOL a global variable - 2) how should we iterate through the LETTER_POOL? - a) make each letter-value pair a dictionary as an element in a tuple/list? - B) put values of the letters in a list (Like nine A elements, two B elements, etc.) - 3) use a method from the random module to shuffle the list - 4) return the first 10 elements in the shuffled list + Creates a new randomized list of letters from LETTER_POOL. + Returns: A randomized list of ten letters. ''' - # letters = [] - # for letter, number in LETTER_POOL.items(): - # for i in range(number): - # letters.append(letter) letters = [letter for letter, letter_frequency in LETTER_POOL.items() for number in range(letter_frequency)] @@ -62,83 +54,68 @@ def draw_letters(): def uses_available_letters(word, letter_bank): ''' - 1) Iterate over each letter in word - 2) If the letter is not in letter_bank or the frequency of - the letter in word is greater than the frequency of the - letter in letter_bank... - 3) is_valid becomes False - 4) Break the loop - 5) return is_valid - 6) For the last test: the letters in word can be lower or upper case. - 7) The letter can only be used as frequent as it is in letter_bank. + Checks that each letter is listed in the dictionary as >= + as used in the word. + + Parameters: string, dict (word and letter frequency) + Returns a Boolean value representing the validity of the input. ''' - # letter_bank_uppercase = list(("".join(letter_bank)).upper()) - # letter_bank_lowercase = list(("".join(letter_bank)).lower()) - # letter_bank_diff_cases = tuple(letter_bank_uppercase + letter_bank_lowercase) - # print(letter_bank_diff_cases) word_uppercase = word.upper() - is_valid = True for letter in word_uppercase: if letter not in letter_bank or (word_uppercase.count(letter) > letter_bank.count(letter)): - is_valid = False - break + return False - return is_valid + return True def score_word(word): ''' - Create a SCORE_CHART dictionary with letters: point values where letters is a tuple of letters and values are integers. - Initialize score integer. - If length of word between 7 and 10, add 8 to score. - iterate over string - iterate over the dictionary to get the point value - add to score - return score + Score is given to each letter based on the score chart dictionary. + If the word is between 7 and 10, add 8 points to score. + + Parameters: A string of the word. + + Returns the score of the word. ''' score = 0 word_uppercase = word.upper() if len(word_uppercase) >= 7 and len(word_uppercase) <= 10: score += 8 for letter in word_uppercase: - for k in SCORE_CHART: - if letter in k: - score += SCORE_CHART[k] + for letter_freq in SCORE_CHART: + if letter in letter_freq: + score += SCORE_CHART[letter_freq] return score def get_index_tie_break(word_list): ''' - Finds the winner to break a tie with rules: 10 letters > fewest letters > first word - Not sure why, but range(len(word_list)-1) didn't iterate over the loop properly. + Checks if the length of the word is 10, then checks for the first word with the fewest letters + Otherwise, returns the first word. + + Parameter: List of highest scoring, tied words. + + Return the index of the winning word. ''' highest_index = 0 - for i in range(len(word_list)): # I would skip the first item but we need to check if it is the shortest or 10 letters long. + for i in range(len(word_list)): if len(word_list[i]) == 10: - # highest_index = i # maybe return i at this point? otherwise, highest_rated will get overwritten by shorter words later. return i - elif len(word_list[i]) < len(word_list[highest_index]): # will this work if the first word is 10 letters long? + elif len(word_list[i]) < len(word_list[highest_index]): highest_index = i return highest_index def get_highest_word_score(word_list): ''' - ties: - 10 letters > fewest letters > first word - 1) initialize an empty list variable for the highested_scoring_words - 2) initialize highested_score variable - 3) iterate over the word in word_list - 4) call score_word on each of the words - 5) store all of the highested scoring words into call score_word on each of the words - 6) if score > highested_score, overwrite the list with highest_ score_words, overwrite the highest_score with the score - 7) elif score == highested_score, add it to the highested_scoring_words - 8) if length of highested_scoring_words > 1, tie break function? - 9) Tie-break should return the index of the highested scoring word - 10) the a tuple of highest_scoring_words the first element and - the score + Calculate high score for each word using score_word and calculate the winner if there is a + tie using get_index_tie_break(). + + Parameter: A list of words. + + Returns a tuple of the highest scoring word and its high score. ''' highest_scoring_words = [] high_score = 0