From b1901b6e5f99ffb141fb263c19e488d7ac5150b7 Mon Sep 17 00:00:00 2001 From: jae Date: Mon, 28 Mar 2022 17:26:40 -0500 Subject: [PATCH 01/29] wave 1 --- README.md | 16 ++++++------- adagrams/game.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index aa13c4c7..9cb37aeb 100644 --- a/README.md +++ b/README.md @@ -95,16 +95,16 @@ $ pip install -r requirements.txt Summary of one-time project setup: One person: -- [ ] Fork the project respository -- [ ] Invite team members to the respository +- [x ] Fork the project respository +- [ x] Invite team members to the respository All team members: -- [ ] `cd` into your `projects` folder -- [ ] Clone the project onto your machine -- [ ] `cd` into the `adagrams-py` folder -- [ ] Create the virtual environment `venv` -- [ ] Activate the virtual environment `venv` -- [ ] Install the dependencies with `pip` +- [x ] `cd` into your `projects` folder +- [ x] Clone the project onto your machine +- [ x] `cd` into the `adagrams-py` folder +- [ x] Create the virtual environment `venv` +- [ x] Activate the virtual environment `venv` +- [ x] Install the dependencies with `pip` ## Project Development Workflow diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..0de17be3 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,7 +1,65 @@ + +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 +} + def draw_letters(): - pass + user_pool = copy.deepcopy(letter_pool) + letters = [] + while len(letters)< 10: + draw = random.choice(list(user_pool)) + for letter, count in user_pool.items(): + if user_pool[letter] == 0: + continue + if letter == draw: + letters.append(draw) + user_pool[letter] -= 1 + + return letters + def uses_available_letters(word, letter_bank): + ''' + word = 'some word' + letter_bank = draw_letters() + return TRUE or FALSE + + for letter in word: + if letter not in letter_bank: + return FALSE + else: + if letter in letter_bank: + if word has same letter more than once, letter_bank must also! + + ''' pass def score_word(word): From a56bd5e32205627d5d9253f0fbc2688672eff193 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Mon, 28 Mar 2022 18:36:48 -0400 Subject: [PATCH 02/29] "Renamed variable letters to letter_bank." --- adagrams/game.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 0de17be3..11690d0c 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -33,17 +33,17 @@ def draw_letters(): user_pool = copy.deepcopy(letter_pool) - letters = [] - while len(letters)< 10: + letter_bank = [] + while len(letter_bank)< 10: draw = random.choice(list(user_pool)) for letter, count in user_pool.items(): if user_pool[letter] == 0: continue if letter == draw: - letters.append(draw) + letter_bank.append(draw) user_pool[letter] -= 1 - return letters + return letter_bank def uses_available_letters(word, letter_bank): From 6fc4d00c988bbafe761cbe95ee4625a674b57db8 Mon Sep 17 00:00:00 2001 From: jae Date: Mon, 28 Mar 2022 17:51:28 -0500 Subject: [PATCH 03/29] updated dictionary iteration from .items to .keys() --- adagrams/game.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 11690d0c..602c5438 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -36,7 +36,7 @@ def draw_letters(): letter_bank = [] while len(letter_bank)< 10: draw = random.choice(list(user_pool)) - for letter, count in user_pool.items(): + for letter in user_pool.keys(): if user_pool[letter] == 0: continue if letter == draw: @@ -48,10 +48,14 @@ def draw_letters(): def uses_available_letters(word, letter_bank): ''' - word = 'some word' + word = word.upper() + letter_bank = draw_letters() return TRUE or FALSE + ## make sure that case doesn't matter for word input + ## do not change the letter_bank (no remove from list! only compare to list) + for letter in word: if letter not in letter_bank: return FALSE From cc2f561058a04c17f77c19c9198c63657e01dfb6 Mon Sep 17 00:00:00 2001 From: jae Date: Mon, 28 Mar 2022 19:33:10 -0500 Subject: [PATCH 04/29] wave 2, doesn't pass last test(something to do with case, still) --- adagrams/game.py | 49 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 602c5438..9d5512b5 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -45,26 +45,45 @@ def draw_letters(): return letter_bank +from collections import Counter def uses_available_letters(word, letter_bank): - ''' - word = word.upper() + input_word = word.upper() + word_counter = Counter(input_word) + letter_bank_counter = Counter(letter_bank) + + for letter in input_word: + if letter not in letter_bank: + return False + + for (k,v), (k2,v2) in zip(word_counter.items(), letter_bank_counter.items()): + if k == k2 and v <= v2: + return True + else: + return False - letter_bank = draw_letters() - return TRUE or FALSE - ## make sure that case doesn't matter for word input - ## do not change the letter_bank (no remove from list! only compare to list) - for letter in word: - if letter not in letter_bank: - return FALSE - else: - if letter in letter_bank: - if word has same letter more than once, letter_bank must also! - - ''' - pass + + + ''' + word = word.upper() + + letter_bank = draw_letters() + return TRUE or FALSE + + ## make sure that case doesn't matter for word input + ## do not change the letter_bank (no remove from list! only compare to list) + + for letter in word: + if letter not in letter_bank: + return FALSE + else: + if letter in letter_bank: + if word has same letter more than once, letter_bank must also! + + ''' + def score_word(word): pass From 242cebc3128fd4f6a8a8d132c44c8f534a17d153 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Tue, 29 Mar 2022 05:12:05 -0400 Subject: [PATCH 05/29] "Docstrings updated for reference." --- adagrams/game.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/adagrams/game.py b/adagrams/game.py index 602c5438..03e99927 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -48,6 +48,22 @@ def draw_letters(): def uses_available_letters(word, letter_bank): ''' + Next, you need a way to check if an input word (a word a player submits) only uses + characters that are contained within a collection (or hand) of drawn letters. + Essentially, you need a way to check if the word is an anagram of some or all of + the given letters in the hand. + +To do so, implement the function called uses_available_letters in game.py. +This function should have the following properties: + +Has two parameters: +word, the first parameter, describes some input word, and is a string +letter_bank, the second parameter, describes an array of drawn letters in a hand. +You can expect this to be an array of ten strings, with each string representing a letter +Returns either True or False +Returns True if every letter in the input word is available (in the right quantities) in the letter_bank +Returns False if not; if there is a letter in input that is not present in the +letter_bank or has too much of compared to the letter_bank word = word.upper() letter_bank = draw_letters() @@ -67,7 +83,45 @@ def uses_available_letters(word, letter_bank): pass def score_word(word): + """ +Wave 3: score_word +Now you need a function returns the score of a given word as defined by the Adagrams game. + +Implement the function score_word in game.py. This method should have the following properties: + +Has one parameter: word, which is a string of characters +Returns an integer representing the number of points +Each letter within word has a point value. The number of points of each letter is summed up to represent the total score of word +Each letter's point value is described in the table below +If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points + +""" pass def get_highest_word_score(word_list): + """ +Wave 4: get_highest_word_score +After several hands have been drawn, words have been submitted, checked, scored, and played, +you need a way to find the highest scoring word. + +This function looks at the list of word_list and calculates which of these words has the highest +score, applies any tie-breaking logic, and returns the winning word in a special data structure. + +Implement a function called get_highest_word_score in game.py. + +This method should have the following properties: + +Has one parameter: word_list, which is a list of strings +Returns a tuple that represents the data of a winning word and it's score. + +The tuple must contain the following elements: +index 0 ([0]): a string of a word +index 1 ([1]): the score of that word +In the case of tie in scores, use these tie-breaking rules: +prefer the word with the fewest letters... +...unless one word has 10 letters. +If the top score is tied between multiple words and one is 10 letters long, +choose the one with 10 letters over the one with fewer tiles +If the there are multiple words that are the same score and the same length, +pick the first one in the supplied list""" pass \ No newline at end of file From 9402c153cbf1dc7d94645c6542c1d180e0531107 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Tue, 29 Mar 2022 05:39:58 -0400 Subject: [PATCH 06/29] Back up file while troubleshooting. --- adagrams/back_up.py | 148 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 adagrams/back_up.py diff --git a/adagrams/back_up.py b/adagrams/back_up.py new file mode 100644 index 00000000..fb4f5922 --- /dev/null +++ b/adagrams/back_up.py @@ -0,0 +1,148 @@ + +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 +} + +def draw_letters(): + user_pool = copy.deepcopy(letter_pool) + letter_bank = [] + while len(letter_bank)< 10: + draw = random.choice(list(user_pool)) + for letter in user_pool.keys(): + if user_pool[letter] == 0: + continue + if letter == draw: + letter_bank.append(draw) + user_pool[letter] -= 1 + + return letter_bank + +from collections import Counter + +def uses_available_letters(word, letter_bank): + + word = word.upper() + + input_word = word.upper() + word_counter = Counter(input_word) + letter_bank_counter = Counter(letter_bank) + + for letter in input_word: + if letter not in letter_bank: + return False + + for (k,v), (k2,v2) in zip(word_counter.items(), letter_bank_counter.items()): + if k == k2 and v <= v2: + return True + else: + return False + + word = word.upper() + + letter_bank = draw_letters() + return TRUE or FALSE + + ## make sure that case doesn't matter for word input + ## do not change the letter_bank (no remove from list! only compare to list) + + for letter in word: + if letter not in letter_bank: + return FALSE + else: + if letter in letter_bank: + if word has same letter more than once, letter_bank must also!: + pass + + """ +Wave 2: use_available_letters +Next, you need a way to check if an input word (a word a player submits) only uses +characters that are contained within a collection (or hand) of drawn letters. +Essentially, you need a way to check if the word is an anagram of some or all of +the given letters in the hand. + +To do so, implement the function called uses_available_letters in game.py. +This function should have the following properties: + +Has two parameters: +word, the first parameter, describes some input word, and is a string +letter_bank, the second parameter, describes an array of drawn letters in a hand. +You can expect this to be an array of ten strings, with each string representing a letter +Returns either True or False +Returns True if every letter in the input word is available (in the right quantities) in the letter_bank +Returns False if not; if there is a letter in input that is not present in the +letter_bank or has too much of compared to the letter_bank.""" + + +def score_word(word): + pass + """ +Wave 3: score_word +Now you need a function returns the score of a given word as defined by the Adagrams game. + +Implement the function score_word in game.py. This method should have the following properties: + +Has one parameter: word, which is a string of characters +Returns an integer representing the number of points +Each letter within word has a point value. The number of points of each letter is summed up to represent the total score of word +Each letter's point value is described in the table below +If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points + +""" + + +def get_highest_word_score(word_list): + pass + """ +Wave 4: get_highest_word_score +After several hands have been drawn, words have been submitted, checked, scored, and played, +you need a way to find the highest scoring word. + +This function looks at the list of word_list and calculates which of these words has the highest +score, applies any tie-breaking logic, and returns the winning word in a special data structure. + +Implement a function called get_highest_word_score in game.py. + +This method should have the following properties: + +Has one parameter: word_list, which is a list of strings +Returns a tuple that represents the data of a winning word and it's score. + +The tuple must contain the following elements: +index 0 ([0]): a string of a word +index 1 ([1]): the score of that word +In the case of tie in scores, use these tie-breaking rules: +prefer the word with the fewest letters... +...unless one word has 10 letters. +If the top score is tied between multiple words and one is 10 letters long, +choose the one with 10 letters over the one with fewer tiles +If the there are multiple words that are the same score and the same length, +pick the first one in the supplied list""" + \ No newline at end of file From 81acaa6cd14a90f58d5b528a9041616a2eb00c09 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Tue, 29 Mar 2022 06:32:49 -0400 Subject: [PATCH 07/29] "Current functions and docstrings up to date." --- adagrams/game.py | 93 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/adagrams/game.py b/adagrams/game.py index 94659f96..de9494d4 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -47,3 +47,96 @@ def draw_letters(): from collections import Counter +def uses_available_letters(word, letter_bank): + + word = word.upper() + input_word = word.upper() + word_counter = Counter(input_word) + letter_bank_counter = Counter(letter_bank) + + for letter in input_word: + if letter not in letter_bank: + return False + + for (k,v), (k2,v2) in zip(word_counter.items(), letter_bank_counter.items()): + if k == k2 and v <= v2: + return True + else: + return False +""" + letter_bank = draw_letters() + return TRUE or FALSE + + ## make sure that case doesn't matter for word input + ## do not change the letter_bank (no remove from list! only compare to list) + + for letter in word: + if letter not in letter_bank: + return FALSE + else: + if letter in letter_bank: + if word has same letter more than once, letter_bank must also! + """ + +pass + +''' + word = word.upper() + letter_bank = draw_letters() + return TRUE or FALSE + ## make sure that case doesn't matter for word input + ## do not change the letter_bank (no remove from list! only compare to list) + for letter in word: + if letter not in letter_bank: + return FALSE + else: + if letter in letter_bank: + if word has same letter more than once, letter_bank must also! + ''' + + +def score_word(word): + pass + """ + Wave 3: score_word + Now you need a function returns the score of a given word as defined by the Adagrams game. + + Implement the function score_word in game.py. This method should have the following properties: + + Has one parameter: word, which is a string of characters + Returns an integer representing the number of points + Each letter within word has a point value. The number of points of each letter is summed up to represent the total score of word + Each letter's point value is described in the table below + If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points + + """ + + +def get_highest_word_score(word_list): + pass + """ + Wave 4: get_highest_word_score + After several hands have been drawn, words have been submitted, checked, scored, and played, + you need a way to find the highest scoring word. + + This function looks at the list of word_list and calculates which of these words has the highest + score, applies any tie-breaking logic, and returns the winning word in a special data structure. + + Implement a function called get_highest_word_score in game.py. + + This method should have the following properties: + + Has one parameter: word_list, which is a list of strings + Returns a tuple that represents the data of a winning word and it's score. + + The tuple must contain the following elements: + index 0 ([0]): a string of a word + index 1 ([1]): the score of that word + In the case of tie in scores, use these tie-breaking rules: + prefer the word with the fewest letters... + ...unless one word has 10 letters. + If the top score is tied between multiple words and one is 10 letters long, + choose the one with 10 letters over the one with fewer tiles + If the there are multiple words that are the same score and the same length, + pick the first one in the supplied list""" + \ No newline at end of file From acc29cbdde5074d59f93a28657a4c58c8ecab388 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Tue, 29 Mar 2022 07:01:59 -0400 Subject: [PATCH 08/29] Deleted back_up.py file. No longer needed since game.py has been restored. --- adagrams/back_up.py | 148 -------------------------------------------- adagrams/game.py | 1 - 2 files changed, 149 deletions(-) delete mode 100644 adagrams/back_up.py diff --git a/adagrams/back_up.py b/adagrams/back_up.py deleted file mode 100644 index fb4f5922..00000000 --- a/adagrams/back_up.py +++ /dev/null @@ -1,148 +0,0 @@ - -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 -} - -def draw_letters(): - user_pool = copy.deepcopy(letter_pool) - letter_bank = [] - while len(letter_bank)< 10: - draw = random.choice(list(user_pool)) - for letter in user_pool.keys(): - if user_pool[letter] == 0: - continue - if letter == draw: - letter_bank.append(draw) - user_pool[letter] -= 1 - - return letter_bank - -from collections import Counter - -def uses_available_letters(word, letter_bank): - - word = word.upper() - - input_word = word.upper() - word_counter = Counter(input_word) - letter_bank_counter = Counter(letter_bank) - - for letter in input_word: - if letter not in letter_bank: - return False - - for (k,v), (k2,v2) in zip(word_counter.items(), letter_bank_counter.items()): - if k == k2 and v <= v2: - return True - else: - return False - - word = word.upper() - - letter_bank = draw_letters() - return TRUE or FALSE - - ## make sure that case doesn't matter for word input - ## do not change the letter_bank (no remove from list! only compare to list) - - for letter in word: - if letter not in letter_bank: - return FALSE - else: - if letter in letter_bank: - if word has same letter more than once, letter_bank must also!: - pass - - """ -Wave 2: use_available_letters -Next, you need a way to check if an input word (a word a player submits) only uses -characters that are contained within a collection (or hand) of drawn letters. -Essentially, you need a way to check if the word is an anagram of some or all of -the given letters in the hand. - -To do so, implement the function called uses_available_letters in game.py. -This function should have the following properties: - -Has two parameters: -word, the first parameter, describes some input word, and is a string -letter_bank, the second parameter, describes an array of drawn letters in a hand. -You can expect this to be an array of ten strings, with each string representing a letter -Returns either True or False -Returns True if every letter in the input word is available (in the right quantities) in the letter_bank -Returns False if not; if there is a letter in input that is not present in the -letter_bank or has too much of compared to the letter_bank.""" - - -def score_word(word): - pass - """ -Wave 3: score_word -Now you need a function returns the score of a given word as defined by the Adagrams game. - -Implement the function score_word in game.py. This method should have the following properties: - -Has one parameter: word, which is a string of characters -Returns an integer representing the number of points -Each letter within word has a point value. The number of points of each letter is summed up to represent the total score of word -Each letter's point value is described in the table below -If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points - -""" - - -def get_highest_word_score(word_list): - pass - """ -Wave 4: get_highest_word_score -After several hands have been drawn, words have been submitted, checked, scored, and played, -you need a way to find the highest scoring word. - -This function looks at the list of word_list and calculates which of these words has the highest -score, applies any tie-breaking logic, and returns the winning word in a special data structure. - -Implement a function called get_highest_word_score in game.py. - -This method should have the following properties: - -Has one parameter: word_list, which is a list of strings -Returns a tuple that represents the data of a winning word and it's score. - -The tuple must contain the following elements: -index 0 ([0]): a string of a word -index 1 ([1]): the score of that word -In the case of tie in scores, use these tie-breaking rules: -prefer the word with the fewest letters... -...unless one word has 10 letters. -If the top score is tied between multiple words and one is 10 letters long, -choose the one with 10 letters over the one with fewer tiles -If the there are multiple words that are the same score and the same length, -pick the first one in the supplied list""" - \ No newline at end of file diff --git a/adagrams/game.py b/adagrams/game.py index de9494d4..2ecc0014 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -48,7 +48,6 @@ def draw_letters(): from collections import Counter def uses_available_letters(word, letter_bank): - word = word.upper() input_word = word.upper() word_counter = Counter(input_word) From d501ef9de125dccfce01ade2f6682a2b22e30c6c Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Tue, 29 Mar 2022 10:03:53 -0400 Subject: [PATCH 09/29] Wave 2 complete. --- adagrams/game.py | 61 ++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 2ecc0014..2534d0d0 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -48,20 +48,37 @@ def draw_letters(): from collections import Counter def uses_available_letters(word, letter_bank): - word = word.upper() input_word = word.upper() - word_counter = Counter(input_word) - letter_bank_counter = Counter(letter_bank) - - for letter in input_word: + print(f"This is the value of {input_word=}") + word_counter = Counter(input_word) + print(f"Thisis the data type of word_counter: {type(word_counter)=}") + print(f"This is the value of {word_counter=}") + letter_bank_counter = Counter(letter_bank) + print(f"This is the value of letter_bank_counter: {letter_bank_counter}") + + for letter in input_word: if letter not in letter_bank: - return False - - for (k,v), (k2,v2) in zip(word_counter.items(), letter_bank_counter.items()): - if k == k2 and v <= v2: - return True - else: - return False + return False + for letter in input_word: + if letter in letter_bank: + word_letter_frequency = input_word.count(letter) + letter_bank_frequency = letter_bank.count(letter) + if word_letter_frequency > letter_bank_frequency: + return False + elif word_letter_frequency == letter_bank_frequency: + return True + + # for letter in input_word: + # if letter not in letter_bank: + # return False + + # for (k, v), (k2, v2) in zip(word_counter.items(), letter_bank_counter.items()): + # # for (letter, letter_frequency), (letter, letter_frequency) in zip(word_counter.items(), letter_bank_counter.items()): + # zip(word_counter.items(), letter_bank_counter.items()) #But this isn't a dictionary ??? + # if k == k2 and v <= v2: + # return True + # else: + # return False """ letter_bank = draw_letters() return TRUE or FALSE @@ -77,25 +94,7 @@ def uses_available_letters(word, letter_bank): if word has same letter more than once, letter_bank must also! """ -pass - -''' - word = word.upper() - letter_bank = draw_letters() - return TRUE or FALSE - ## make sure that case doesn't matter for word input - ## do not change the letter_bank (no remove from list! only compare to list) - for letter in word: - if letter not in letter_bank: - return FALSE - else: - if letter in letter_bank: - if word has same letter more than once, letter_bank must also! - ''' - - def score_word(word): - pass """ Wave 3: score_word Now you need a function returns the score of a given word as defined by the Adagrams game. @@ -109,7 +108,7 @@ def score_word(word): If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points """ - + pass def get_highest_word_score(word_list): pass From 5e9967282a41f24bee0d9e45731c3c4a8a6894a4 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Tue, 29 Mar 2022 11:39:50 -0400 Subject: [PATCH 10/29] Reformatted function. Commented out uses of Counter. --- adagrams/game.py | 65 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 2534d0d0..86ef85ac 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -48,13 +48,14 @@ def draw_letters(): from collections import Counter def uses_available_letters(word, letter_bank): - input_word = word.upper() + if word.isalpha(): + input_word = word.upper() print(f"This is the value of {input_word=}") - word_counter = Counter(input_word) - print(f"Thisis the data type of word_counter: {type(word_counter)=}") - print(f"This is the value of {word_counter=}") - letter_bank_counter = Counter(letter_bank) - print(f"This is the value of letter_bank_counter: {letter_bank_counter}") + # word_counter = Counter(input_word) + # print(f"Thisis the data type of word_counter: {type(word_counter)=}") + # print(f"This is the value of {word_counter=}") + # # letter_bank_counter = Counter(letter_bank) + # print(f"This is the value of letter_bank_counter: {letter_bank_counter}") for letter in input_word: if letter not in letter_bank: @@ -65,13 +66,11 @@ def uses_available_letters(word, letter_bank): letter_bank_frequency = letter_bank.count(letter) if word_letter_frequency > letter_bank_frequency: return False + # elif word_letter_frequency < letter_bank_frequency: + # return False elif word_letter_frequency == letter_bank_frequency: return True - # for letter in input_word: - # if letter not in letter_bank: - # return False - # for (k, v), (k2, v2) in zip(word_counter.items(), letter_bank_counter.items()): # # for (letter, letter_frequency), (letter, letter_frequency) in zip(word_counter.items(), letter_bank_counter.items()): # zip(word_counter.items(), letter_bank_counter.items()) #But this isn't a dictionary ??? @@ -95,6 +94,50 @@ def uses_available_letters(word, letter_bank): """ def score_word(word): + input_word = word.upper() + score = 0 + # score_chart = { + # (A, E, I, O, U, L, N, R, S, T) + # } + # score_chart = { + # "A", "E", "I", "O", "U", "L", "N", "R", "S", "T": 1, + # "D","G": 2, + + # } + score_chart = { + 'A': 1, + 'B': 3, + 'C': 3, + 'D': 1, + 'E': 1, + 'F': 4, + 'G': 1, + '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 + + + } + + for letter in input_word: + word_score += letter_value + pass """ Wave 3: score_word Now you need a function returns the score of a given word as defined by the Adagrams game. @@ -108,6 +151,8 @@ def score_word(word): If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points """ + + pass def get_highest_word_score(word_list): From e2c490d322bc6a0e09f6fd909389c2f9686d3ec2 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Tue, 29 Mar 2022 12:14:42 -0400 Subject: [PATCH 11/29] "Wave 3 nearly complete. 1 test remaining. " --- adagrams/game.py | 85 ++++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 86ef85ac..2563f6fb 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -2,7 +2,7 @@ import random import copy -letter_pool = { +LETTER_POOL = { 'A': 9, 'B': 2, 'C': 2, @@ -30,9 +30,37 @@ 'Y': 2, 'Z': 1 } +SCORE_CHART = { + '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 + } def draw_letters(): - user_pool = copy.deepcopy(letter_pool) + user_pool = copy.deepcopy(LETTER_POOL) letter_bank = [] while len(letter_bank)< 10: draw = random.choice(list(user_pool)) @@ -95,49 +123,20 @@ def uses_available_letters(word, letter_bank): def score_word(word): input_word = word.upper() - score = 0 - # score_chart = { - # (A, E, I, O, U, L, N, R, S, T) - # } - # score_chart = { - # "A", "E", "I", "O", "U", "L", "N", "R", "S", "T": 1, - # "D","G": 2, - - # } - score_chart = { - 'A': 1, - 'B': 3, - 'C': 3, - 'D': 1, - 'E': 1, - 'F': 4, - 'G': 1, - '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 - + word_score = 0 + word_length = len(input_word) + letter_bank = draw_letters() - } - + if input_word == "": + return 0 for letter in input_word: - word_score += letter_value - pass + if word_length < 7: + word_score += SCORE_CHART[letter] + elif word_length >= 7: + word_score = word_score + 8 + + return word_score + """ Wave 3: score_word Now you need a function returns the score of a given word as defined by the Adagrams game. From ee586438c62593059e5c6cd36db079e8a324991f Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Tue, 29 Mar 2022 16:40:21 -0400 Subject: [PATCH 12/29] Refactored Wave 2. --- adagrams/game.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 2563f6fb..8ae84ae7 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -76,8 +76,7 @@ def draw_letters(): from collections import Counter def uses_available_letters(word, letter_bank): - if word.isalpha(): - input_word = word.upper() + input_word = word.upper() print(f"This is the value of {input_word=}") # word_counter = Counter(input_word) # print(f"Thisis the data type of word_counter: {type(word_counter)=}") @@ -88,24 +87,19 @@ def uses_available_letters(word, letter_bank): for letter in input_word: if letter not in letter_bank: return False - for letter in input_word: - if letter in letter_bank: + elif letter in letter_bank: word_letter_frequency = input_word.count(letter) letter_bank_frequency = letter_bank.count(letter) if word_letter_frequency > letter_bank_frequency: - return False - # elif word_letter_frequency < letter_bank_frequency: - # return False - elif word_letter_frequency == letter_bank_frequency: - return True + return False + return True # for (k, v), (k2, v2) in zip(word_counter.items(), letter_bank_counter.items()): - # # for (letter, letter_frequency), (letter, letter_frequency) in zip(word_counter.items(), letter_bank_counter.items()): - # zip(word_counter.items(), letter_bank_counter.items()) #But this isn't a dictionary ??? - # if k == k2 and v <= v2: - # return True - # else: - # return False + # zip(word_counter.items(), letter_bank_counter.items()) + # if k == k2 and v > v2: + # return False + # + # return True """ letter_bank = draw_letters() return TRUE or FALSE @@ -125,7 +119,6 @@ def score_word(word): input_word = word.upper() word_score = 0 word_length = len(input_word) - letter_bank = draw_letters() if input_word == "": return 0 From 2cb1aa510455ecfa7212be9b514279956500c133 Mon Sep 17 00:00:00 2001 From: jae Date: Tue, 29 Mar 2022 15:42:59 -0500 Subject: [PATCH 13/29] update of wave 3 & some crazy notes for wave 4 --- adagrams/game.py | 94 +++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 33 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 2563f6fb..328df7cb 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -96,7 +96,7 @@ def uses_available_letters(word, letter_bank): return False # elif word_letter_frequency < letter_bank_frequency: # return False - elif word_letter_frequency == letter_bank_frequency: + elif word_letter_frequency <= letter_bank_frequency: return True # for (k, v), (k2, v2) in zip(word_counter.items(), letter_bank_counter.items()): @@ -129,11 +129,13 @@ def score_word(word): if input_word == "": return 0 + if word_length >= 7: + word_score = 8 for letter in input_word: - if word_length < 7: - word_score += SCORE_CHART[letter] - elif word_length >= 7: - word_score = word_score + 8 + word_score += SCORE_CHART[letter] + # if word_length >= 7: + # # word_score = word_score + 8 + # word_score + 8 return word_score @@ -152,33 +154,59 @@ def score_word(word): """ - pass + def get_highest_word_score(word_list): - pass - """ - Wave 4: get_highest_word_score - After several hands have been drawn, words have been submitted, checked, scored, and played, - you need a way to find the highest scoring word. - - This function looks at the list of word_list and calculates which of these words has the highest - score, applies any tie-breaking logic, and returns the winning word in a special data structure. - - Implement a function called get_highest_word_score in game.py. - - This method should have the following properties: - - Has one parameter: word_list, which is a list of strings - Returns a tuple that represents the data of a winning word and it's score. - - The tuple must contain the following elements: - index 0 ([0]): a string of a word - index 1 ([1]): the score of that word - In the case of tie in scores, use these tie-breaking rules: - prefer the word with the fewest letters... - ...unless one word has 10 letters. - If the top score is tied between multiple words and one is 10 letters long, - choose the one with 10 letters over the one with fewer tiles - If the there are multiple words that are the same score and the same length, - pick the first one in the supplied list""" - \ No newline at end of file + score_list = [] + user_scores = () + winners = [] + best_score = [] + + for word in word_list: + score = score_word(word) + score_list.append(score) + max_score = max(score_list) + if score == max_score: + best_score.append(word, score) + if len(best_score) > 1: + + + user_scores = (word, score) + score_list.append(user_scores) + + max_score = max(score_list) + for user in score_list: + if user[1] > max_score: + user[1] = max_score + + + + + + + """ + Wave 4: get_highest_word_score + After several hands have been drawn, words have been submitted, checked, scored, and played, + you need a way to find the highest scoring word. + + This function looks at the list of word_list and calculates which of these words has the highest + score, applies any tie-breaking logic, and returns the winning word in a special data structure. + + Implement a function called get_highest_word_score in game.py. + + This method should have the following properties: + + Has one parameter: word_list, which is a list of strings + Returns a tuple that represents the data of a winning word and it's score. + + The tuple must contain the following elements: + index 0 ([0]): a string of a word + index 1 ([1]): the score of that word + In the case of tie in scores, use these tie-breaking rules: + prefer the word with the fewest letters... + ...unless one word has 10 letters. + If the top score is tied between multiple words and one is 10 letters long, + choose the one with 10 letters over the one with fewer tiles + If the there are multiple words that are the same score and the same length, + pick the first one in the supplied list""" + \ No newline at end of file From 1a79f9ea940f6d237764ca08a134a09fdbb67576 Mon Sep 17 00:00:00 2001 From: jae Date: Tue, 29 Mar 2022 16:22:49 -0500 Subject: [PATCH 14/29] wave 4 notes, slightly less unhinged --- adagrams/game.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 3674b6e9..7ed9be94 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -154,23 +154,29 @@ def get_highest_word_score(word_list): user_scores = () winners = [] best_score = [] + highest_score = () for word in word_list: score = score_word(word) - score_list.append(score) + # score_list.append(score) + #[a word, 3 another,6,10,4,10] + highest_score.append(word, score) + + max_score = max(score_list) if score == max_score: best_score.append(word, score) if len(best_score) > 1: - user_scores = (word, score) - score_list.append(user_scores) + # user_scores = (word, score) + # score_list.append(user_scores) - max_score = max(score_list) - for user in score_list: - if user[1] > max_score: - user[1] = max_score + # max_score = max(score_list) + # for user in score_list: + # if user[1] > max_score: + # user[1] = max_score + pass From 0c0d243655a4fcf6b37c543c516ebc9ad87062a2 Mon Sep 17 00:00:00 2001 From: jae Date: Tue, 29 Mar 2022 18:08:32 -0500 Subject: [PATCH 15/29] wave 4, for loops & length --- adagrams/game.py | 119 +++++++++++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 39 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 7ed9be94..b7ef6776 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -150,23 +150,65 @@ def score_word(word): def get_highest_word_score(word_list): - score_list = [] - user_scores = () - winners = [] - best_score = [] - highest_score = () + word_list_scores = [] + highest_score = 0 - for word in word_list: + + for word in word_list: + word_length= len(word) + word_score = score_word(word) + word_list_scores.append(word_score) + for word_score in word_list_scores: + word_score_frequency = word_list_scores.count(word_score) + if word_score == max(word_list_scores): + if word_score_frequency > 1: + if word_length == 10: + + + highest_score = word_score + highest_score_tuple = (word, highest_score) + + if word_length == 10: + if word_length + + + # highest_score.append(word_score) + # if word_score > highest_word_score: + + + + + + + + + + + score = score_word(word) - # score_list.append(score) - #[a word, 3 another,6,10,4,10] - highest_score.append(word, score) + score_list.append(score) + highest_score = max(score_list) + for score in score_list: + if score == highest_score: + highest_scores.append(score) + print(f' THIS SHOULD BE A LIST OF TUPLES{highest_scores=}') + + + + + # # score_list.append(score) + # #[a word, 3 another,6,10,4,10] + # highest_score = highest_score.append(word, score) + # best_score = highest_score[0] + # for word_info in highest_score: + # if word_info[1] > best_score[1]: + - max_score = max(score_list) - if score == max_score: - best_score.append(word, score) - if len(best_score) > 1: + # max_score = max(score_list) + # if score == max_score: + # best_score.append(word, score) + # if len(best_score) > 1: # user_scores = (word, score) @@ -181,31 +223,30 @@ def get_highest_word_score(word_list): - - - """ - Wave 4: get_highest_word_score - After several hands have been drawn, words have been submitted, checked, scored, and played, - you need a way to find the highest scoring word. - - This function looks at the list of word_list and calculates which of these words has the highest - score, applies any tie-breaking logic, and returns the winning word in a special data structure. - Implement a function called get_highest_word_score in game.py. - This method should have the following properties: - - Has one parameter: word_list, which is a list of strings - Returns a tuple that represents the data of a winning word and it's score. - - The tuple must contain the following elements: - index 0 ([0]): a string of a word - index 1 ([1]): the score of that word - In the case of tie in scores, use these tie-breaking rules: - prefer the word with the fewest letters... - ...unless one word has 10 letters. - If the top score is tied between multiple words and one is 10 letters long, - choose the one with 10 letters over the one with fewer tiles - If the there are multiple words that are the same score and the same length, - pick the first one in the supplied list""" - \ No newline at end of file +""" +Wave 4: get_highest_word_score +After several hands have been drawn, words have been submitted, checked, scored, and played, +you need a way to find the highest scoring word. + +This function looks at the list of word_list and calculates which of these words has the highest +score, applies any tie-breaking logic, and returns the winning word in a special data structure. + +Implement a function called get_highest_word_score in game.py. + +This method should have the following properties: + +Has one parameter: word_list, which is a list of strings +Returns a tuple that represents the data of a winning word and it's score. + +The tuple must contain the following elements: +index 0 ([0]): a string of a word +index 1 ([1]): the score of that word +In the case of tie in scores, use these tie-breaking rules: +prefer the word with the fewest letters... +...unless one word has 10 letters. +If the top score is tied between multiple words and one is 10 letters long, +choose the one with 10 letters over the one with fewer tiles +If the there are multiple words that are the same score and the same length, +pick the first one in the supplied list""" From 86d94efd811bd33bf6f9a51313fff15e70a4b7c0 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Tue, 29 Mar 2022 19:20:47 -0400 Subject: [PATCH 16/29] updated with pseudocode. --- adagrams/game.py | 81 +++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 3674b6e9..eaa0de44 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -101,20 +101,18 @@ def uses_available_letters(word, letter_bank): # # return True """ - letter_bank = draw_letters() - return TRUE or FALSE - - ## make sure that case doesn't matter for word input - ## do not change the letter_bank (no remove from list! only compare to list) - - for letter in word: - if letter not in letter_bank: - return FALSE - else: - if letter in letter_bank: - if word has same letter more than once, letter_bank must also! - """ +Wave 3: score_word +Now you need a function returns the score of a given word as defined by the Adagrams game. + +Implement the function score_word in game.py. This method should have the following properties: +Has one parameter: word, which is a string of characters +Returns an integer representing the number of points +Each letter within word has a point value. The number of points of each letter is summed up to represent the total score of word +Each letter's point value is described in the table below +If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points + +""" def score_word(word): input_word = word.upper() word_score = 0 @@ -126,30 +124,45 @@ def score_word(word): word_score = 8 for letter in input_word: word_score += SCORE_CHART[letter] - # if word_length >= 7: - # # word_score = word_score + 8 - # word_score + 8 return word_score + +def get_highest_word_score(word_list): """ - Wave 3: score_word - Now you need a function returns the score of a given word as defined by the Adagrams game. + The tuple must contain the following elements: + + In the case of tie in scores, use these tie-breaking rules: + prefer the word with the fewest letters... + ...unless one word has 10 letters. + If the top score is tied between multiple words and one is 10 letters long, + choose the one with 10 letters over the one with fewer tiles + If the there are multiple words that are the same score and the same length, + pick the first one in the supplied list + + --Establish key variables : word score, word_length = len(word) - Implement the function score_word in game.py. This method should have the following properties: + --initiate empty empty highest_score tuple - Has one parameter: word, which is a string of characters - Returns an integer representing the number of points - Each letter within word has a point value. The number of points of each letter is summed up to represent the total score of word - Each letter's point value is described in the table below - If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points + --for loop iterating word in word_list: + -- if word_score > highest_word_score + highest_score = (word, score) + --if word_score == highest_word_score + + if word_length == 10 + highest_score = (word, score) + elif word_length == highest_word_length + for word in word_list: + word_length = len(word) + + -- + + """ + - - -def get_highest_word_score(word_list): score_list = [] user_scores = () winners = [] @@ -191,15 +204,7 @@ def get_highest_word_score(word_list): Has one parameter: word_list, which is a list of strings Returns a tuple that represents the data of a winning word and it's score. +""" + + - The tuple must contain the following elements: - index 0 ([0]): a string of a word - index 1 ([1]): the score of that word - In the case of tie in scores, use these tie-breaking rules: - prefer the word with the fewest letters... - ...unless one word has 10 letters. - If the top score is tied between multiple words and one is 10 letters long, - choose the one with 10 letters over the one with fewer tiles - If the there are multiple words that are the same score and the same length, - pick the first one in the supplied list""" - \ No newline at end of file From d3b140f35ea0069909a4ed5e80ec9cdaffa31a0b Mon Sep 17 00:00:00 2001 From: jae Date: Tue, 29 Mar 2022 18:44:41 -0500 Subject: [PATCH 17/29] probably no changes? --- adagrams/game.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adagrams/game.py b/adagrams/game.py index b7ef6776..cc6b306c 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -154,6 +154,10 @@ def get_highest_word_score(word_list): highest_score = 0 + + + + for word in word_list: word_length= len(word) word_score = score_word(word) From 6463d4c7ee63e41b7fab161022edc4d8bb68008a Mon Sep 17 00:00:00 2001 From: jae Date: Tue, 29 Mar 2022 22:35:06 -0500 Subject: [PATCH 18/29] idk, tried something out -- we were counting the frequency of the wrong thing, so i tried idea of making a list of just words that have winning score level ? --- adagrams/game.py | 114 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 101 insertions(+), 13 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index aedb3862..9b6877e0 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -146,27 +146,56 @@ def get_highest_word_score(word_list): word_list_scores = [] highest_score = 0 - - + best_words = [] for word in word_list: - word_length= len(word) + # word_length= len(word) word_score = score_word(word) word_list_scores.append(word_score) + highest_score = max(word_list_scores) + if word_score == highest_score: + best_words.append(word) + + if len(best_words) == 1: + word = best_words[0] + highest_score_tuple = (word, highest_score) + return highest_score_tuple + + for word in best_words: + + if len(word) == 10: + highest_score_tuple = (word, highest_score) + else: + ### this isn't the right way to do it! + ## but thought is that we have a + shortest_word = min(word_list, key=lambda word: len(word)) + highest_score_tuple = (shortest_word, highest_score) - for word_score in word_list_scores: - word_score_frequency = word_list_scores.count(word_score) - print(f"THIS IS THE WORD SCORE FREQUENCY{word_score_frequency=}") - if word_score == max(word_list_scores): - if word_score_frequency > 1: - if word_length == 10: + + + + + # for word_score in word_list_scores: + # word_score_frequency = word_list_scores.count(word_score) + # highest_score = max(word_list_scores) + # print(f"THIS IS THE WORD SCORE FREQUENCY{word_score_frequency=}") + # if word_score == highest_score: + # highest_score = word_score + # highest_score_tuple = (word, highest_score) + # if word_score_frequency > 1: + # if word_length == 10: - highest_score = word_score - highest_score_tuple = (word, highest_score) + # highest_score_tuple = (word, highest_score) + # else: + # shortest_word = min(word_list, key=lambda word: len(word)) + # highest_score_tuple = (shortest_word, highest_score) - return highest_score_tuple + + + return highest_score_tuple + # highest_score.append(word_score) # if word_score > highest_word_score: @@ -205,10 +234,69 @@ def get_highest_word_score(word_list): # for user in score_list: # if user[1] > max_score: # user[1] = max_score - pass + +# def get_highest_scoring_words(word_list): +# best_score = 0 +# score_list = [] +# best_words = [] +# word_lengths = [] +# shortest_words = [] + +# for word in word_list: +# word_lengths.append(len(word)) +# smallest_length = min(word_lengths) +# if len(word) == smallest_length: +# shortest_words.append(word) + +# for word in word_list: +# score = score_word(word) +# score_list.append(score) +# best_score = max(score_list) +# if score == best_score: +# best_words.append(word) + +# return tuple(best_words, best_score, shortest_words[0]) + + + +# def get_highest_word_score(word_list): +# calculate_score = get_highest_scoring_words(word_list) +# score = calculate_score[1] +# winning_words = calculate_score[0] +# shortest_word = calculate_score[2] +# winning_word = '' + +# if len(winning_words) == 1: +# winning_word = winning_words[0] + +# for word in winning_words: +# if len(word) == 10: +# winning_word = word +# break +# else: +# winning_word = shortest_word + +# return tuple(winning_word, score) + + + + + + + + + + + + + + + + + From 59de25e39003587ea2d9a1d8b9b0c6d4f1d820cb Mon Sep 17 00:00:00 2001 From: jae Date: Tue, 29 Mar 2022 22:58:04 -0500 Subject: [PATCH 19/29] added a return after len 10 & more stuff is passing git add . but still gotta work on min --- adagrams/game.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 9b6877e0..bd38ccf9 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -148,8 +148,6 @@ def get_highest_word_score(word_list): highest_score = 0 best_words = [] - - for word in word_list: # word_length= len(word) word_score = score_word(word) @@ -167,11 +165,13 @@ def get_highest_word_score(word_list): if len(word) == 10: highest_score_tuple = (word, highest_score) + return highest_score_tuple else: ### this isn't the right way to do it! ## but thought is that we have a shortest_word = min(word_list, key=lambda word: len(word)) highest_score_tuple = (shortest_word, highest_score) + From b018f52ffb9ffa4b9d2d1ec96e660844fb2bd644 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Thu, 31 Mar 2022 15:21:09 -0400 Subject: [PATCH 20/29] "Revising Wave 4. Notes and code in progress." --- adagrams/game.py | 251 ++++++++++++++--------------------------------- 1 file changed, 75 insertions(+), 176 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index bd38ccf9..39e0c0c4 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -100,7 +100,9 @@ def uses_available_letters(word, letter_bank): # return False # # return True -""" + +def score_word(word): + """ Wave 3: score_word Now you need a function returns the score of a given word as defined by the Adagrams game. @@ -113,7 +115,6 @@ def uses_available_letters(word, letter_bank): If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points """ -def score_word(word): input_word = word.upper() word_score = 0 word_length = len(input_word) @@ -129,202 +130,100 @@ def score_word(word): def get_highest_word_score(word_list): - """ - --for loop iterating word in word_list: - -- if word_score > highest_word_score - highest_score = (word, score) - --if word_score == highest_word_score - - if word_length == 10 - highest_score = (word, score) - elif word_length == highest_word_length - for word in word_list: - word_length = len(word) - """ +Wave 4: +This method should have the following properties: + +Has one parameter: word_list, which is a list of strings +Returns a tuple that represents the data of a winning word and it's score. + +The tuple must contain the following elements: +index 0 ([0]): a string of a word +index 1 ([1]): the score of that word - word_list_scores = [] - highest_score = 0 - best_words = [] +In the case of tie in scores, use these tie-breaking rules: +prefer the word with the fewest letters... +...unless one word has 10 letters. + +If the top score is tied between multiple words and one is 10 letters long, +choose the one with 10 letters over the one with fewer tiles +If the there are multiple words that are the same score and the same length, +pick the first one in the supplied list""" for word in word_list: - # word_length= len(word) - word_score = score_word(word) + "This is where I am currently reworking" + highest_score = 0 + word_list_scores = [] + word_length = len(word) + word_score = score_word() word_list_scores.append(word_score) highest_score = max(word_list_scores) - if word_score == highest_score: - best_words.append(word) + word_score_dict = {} - if len(best_words) == 1: - word = best_words[0] - highest_score_tuple = (word, highest_score) - return highest_score_tuple - for word in best_words: - - if len(word) == 10: - highest_score_tuple = (word, highest_score) - return highest_score_tuple - else: - ### this isn't the right way to do it! - ## but thought is that we have a - shortest_word = min(word_list, key=lambda word: len(word)) - highest_score_tuple = (shortest_word, highest_score) - - - +# Oh darn...Tuples are immutable lists. +# No sorting, etc. Looking up tuple methods again. +#I will likely work with a dictionary instead +# and return the expected tuple in the end. - # for word_score in word_list_scores: - # word_score_frequency = word_list_scores.count(word_score) + word_score = score_word(word) + word_list_scores.append(word_score) + highest_score = max(word_list_scores) + word_score_pairs = (word, word_score) + if word_score_pairs[1] == highest_score: + best_word.append(word_score_pairs[0]) + best_word[0] = word_score_pairs[0] + if len(best_word) > 0: + holding_spot = [] + best_word = holding_spot.append(word) + +# ^^^^^I was working on this earlier until I realized Tuples are immutable. +#I am pseudo-coding and rewriting everything now. Everything below is old code. +# I broke it up with bits of docstring to make it easier to process. +################################## + + +""" Everything below is from the previous version that got us to 4 passed tests. """ + # for word in word_list: + # # word_length= len(word) + # word_score = score_word(word) + # word_list_scores.append(word_score) # highest_score = max(word_list_scores) - # print(f"THIS IS THE WORD SCORE FREQUENCY{word_score_frequency=}") # if word_score == highest_score: - # highest_score = word_score - # highest_score_tuple = (word, highest_score) - # if word_score_frequency > 1: - # if word_length == 10: - - # highest_score_tuple = (word, highest_score) - # else: - # shortest_word = min(word_list, key=lambda word: len(word)) - # highest_score_tuple = (shortest_word, highest_score) - - - - return highest_score_tuple - - # highest_score.append(word_score) - # if word_score > highest_word_score: - - - - # score = score_word(word) - # score_list.append(score) - # highest_score = max(score_list) - # for score in score_list: - # if score == highest_score: - # highest_scores.append(score) - # print(f' THIS SHOULD BE A LIST OF TUPLES{highest_scores=}') - - - - - # # score_list.append(score) - # #[a word, 3 another,6,10,4,10] - # highest_score = highest_score.append(word, score) - # best_score = highest_score[0] - # for word_info in highest_score: - # if word_info[1] > best_score[1]: - - - - # max_score = max(score_list) - # if score == max_score: - # best_score.append(word, score) - # if len(best_score) > 1: - - - # user_scores = (word, score) - # score_list.append(user_scores) - - # max_score = max(score_list) - # for user in score_list: - # if user[1] > max_score: - # user[1] = max_score - - -# def get_highest_scoring_words(word_list): -# best_score = 0 -# score_list = [] -# best_words = [] -# word_lengths = [] -# shortest_words = [] - -# for word in word_list: -# word_lengths.append(len(word)) -# smallest_length = min(word_lengths) -# if len(word) == smallest_length: -# shortest_words.append(word) - - -# for word in word_list: -# score = score_word(word) -# score_list.append(score) -# best_score = max(score_list) -# if score == best_score: -# best_words.append(word) - -# return tuple(best_words, best_score, shortest_words[0]) - - - - -# def get_highest_word_score(word_list): -# calculate_score = get_highest_scoring_words(word_list) -# score = calculate_score[1] -# winning_words = calculate_score[0] -# shortest_word = calculate_score[2] -# winning_word = '' - -# if len(winning_words) == 1: -# winning_word = winning_words[0] - -# for word in winning_words: -# if len(word) == 10: -# winning_word = word -# break -# else: -# winning_word = shortest_word - -# return tuple(winning_word, score) - - - - - - - - - - - - - - - - - - - - - """ -Wave 4: get_highest_word_score -After several hands have been drawn, words have been submitted, checked, scored, and played, -you need a way to find the highest scoring word. - -This function looks at the list of word_list and calculates which of these words has the highest -score, applies any tie-breaking logic, and returns the winning word in a special data structure. - -Implement a function called get_highest_word_score in game.py. - -This method should have the following properties: - -Has one parameter: word_list, which is a list of strings -Returns a tuple that represents the data of a winning word and it's score. + # best_word.append(word) + -The tuple must contain the following elements: -index 0 ([0]): a string of a word -index 1 ([1]): the score of that word +""" In the case of tie in scores, use these tie-breaking rules: prefer the word with the fewest letters... ...unless one word has 10 letters. +""" + # if len(best_word) == 1: + # word = best_word[0] + # highest_score_tuple = (word, highest_score) + # return highest_score_tuple + + +""" If the top score is tied between multiple words and one is 10 letters long, choose the one with 10 letters over the one with fewer tiles If the there are multiple words that are the same score and the same length, pick the first one in the supplied list""" + # for word in best_word: + + # if len(word) == 10: + # highest_score_tuple = (word, highest_score) + # return highest_score_tuple + # else: + # ### this isn't the right way to do it! + # ## but thought is that we have a + # shortest_word = min(word_list, key=lambda word: len(word)) + # highest_score_tuple = (shortest_word, highest_score) + + # return highest_score_tuple From c3964e5416500af38d779e3735a73125eea02939 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Thu, 31 Mar 2022 17:11:17 -0400 Subject: [PATCH 21/29] Some updates. Still in progress. --- adagrams/game.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 39e0c0c4..726e505f 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -155,11 +155,35 @@ def get_highest_word_score(word_list): "This is where I am currently reworking" highest_score = 0 word_list_scores = [] - word_length = len(word) + tracking_list = [] word_score = score_word() word_list_scores.append(word_score) - highest_score = max(word_list_scores) - word_score_dict = {} + highest_score = max(word_list_scores) #Does this require a key?? + + for word in word_list: + word_length = len(word) + best_word_list = [] + word_score_dict = {word: score_word() for word in word_list} + highest_score = max(word_score_dict[word]) + highest_score_list.append # Not sure if I will use this yet + # Remember the .items method returns tuples of key value pairs! + for keys, values in word_score_dict.items: + # if word_score_dict[word] == + max_word_score_dict = max(word_score_dict.keys(), key = lambda find_max: word_score_dict[word]) + if word_score == max_word_score_dict and word_score in best_word_list: + for best_word in best_word_list: + if word_length < len(best_word): + #Maybe try a zip function + + + + + + + + + + From b482dba5a32880dee5d634d734502a7731139386 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Thu, 31 Mar 2022 18:08:40 -0400 Subject: [PATCH 22/29] "Updates to first part of Wave 4 / in progress." --- adagrams/game.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 726e505f..b0f8277b 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -152,29 +152,30 @@ def get_highest_word_score(word_list): pick the first one in the supplied list""" for word in word_list: - "This is where I am currently reworking" highest_score = 0 - word_list_scores = [] - tracking_list = [] + # word_list_scores = [] word_score = score_word() - word_list_scores.append(word_score) - highest_score = max(word_list_scores) #Does this require a key?? + # word_list_scores.append(word_score) + # highest_score = max(word_list_scores) #Does this require a key?? As in key = lambda etc + highest_score_list = [] for word in word_list: - word_length = len(word) - best_word_list = [] - word_score_dict = {word: score_word() for word in word_list} - highest_score = max(word_score_dict[word]) - highest_score_list.append # Not sure if I will use this yet + word_score_dict = {word: word_score for word in word_list} #Dictionary comprehension + highest_score = max(word_score_dict[word]) #Will this return more than one value if they are equal??? + highest_score_list.append(highest_score) # Not sure if I will use this yet + # Remember the .items method returns tuples of key value pairs! - for keys, values in word_score_dict.items: - # if word_score_dict[word] == + for word, word_score in word_score_dict.items: max_word_score_dict = max(word_score_dict.keys(), key = lambda find_max: word_score_dict[word]) - if word_score == max_word_score_dict and word_score in best_word_list: - for best_word in best_word_list: - if word_length < len(best_word): - #Maybe try a zip function + if word_score == max_word_score_dict: + if word_score in... + pass + + + + #Maybe try a zip function + From 60de52ceae3f342c1872bd2b9dbfb4e339861f6c Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Thu, 31 Mar 2022 19:48:15 -0400 Subject: [PATCH 23/29] "Wave 4: 6 out of 7 tests passed." --- adagrams/game.py | 115 ++++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 55 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index b0f8277b..be0b5073 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -122,7 +122,7 @@ def score_word(word): if input_word == "": return 0 if word_length >= 7: - word_score = 8 + word_score += 8 for letter in input_word: word_score += SCORE_CHART[letter] @@ -130,80 +130,65 @@ def score_word(word): def get_highest_word_score(word_list): + best_word_list = [] - """ -Wave 4: -This method should have the following properties: +# Translating word list and scores into a dictionary and finding highest word score in dictionary: + for word in word_list: + word_score_dict = {word: score_word(word) for word in word_list} #Dictionary comprehension + highest_word_score = max(word_score_dict.values()) -Has one parameter: word_list, which is a list of strings -Returns a tuple that represents the data of a winning word and it's score. -The tuple must contain the following elements: -index 0 ([0]): a string of a word -index 1 ([1]): the score of that word +# Max only returns the first match so we need to check which if any other values == highest score +# Once clear append the keys for those highest_scores values to the best_word_list. + for word in word_score_dict: + if word_score_dict[word] == highest_word_score: + best_word_list.append(word) -In the case of tie in scores, use these tie-breaking rules: -prefer the word with the fewest letters... -...unless one word has 10 letters. +#Conditional check to see if length is more than 1 then apply tie-breaker logic (see below) + best_word = best_word_list[0] if len(best_word_list) == 1 else tie_breaker(best_word_list) -If the top score is tied between multiple words and one is 10 letters long, -choose the one with 10 letters over the one with fewer tiles -If the there are multiple words that are the same score and the same length, -pick the first one in the supplied list""" - - for word in word_list: - highest_score = 0 - # word_list_scores = [] - word_score = score_word() - # word_list_scores.append(word_score) - # highest_score = max(word_list_scores) #Does this require a key?? As in key = lambda etc - highest_score_list = [] + return (best_word, word_score_dict[best_word]) + +#Appy tie-breaker logic + +def tie_breaker(best_word_list): + for word in best_word_list: + if len(word) == 10: + return word + else: + return min(best_word_list, key=len) + - for word in word_list: - word_score_dict = {word: word_score for word in word_list} #Dictionary comprehension - highest_score = max(word_score_dict[word]) #Will this return more than one value if they are equal??? - highest_score_list.append(highest_score) # Not sure if I will use this yet + # highest_score_list.append(highest_score) # Not sure if I will use this yet # Remember the .items method returns tuples of key value pairs! - for word, word_score in word_score_dict.items: - max_word_score_dict = max(word_score_dict.keys(), key = lambda find_max: word_score_dict[word]) - if word_score == max_word_score_dict: - if word_score in... - pass + # for word, word_score in word_score_dict.items: + # max_word_score_dict = max(word_score_dict.keys(), key = lambda find_max: word_score_dict[word]) + # if word_score == max_word_score_dict: + # if word_score in... + # pass - - #Maybe try a zip function - - - - - - - - - - # Oh darn...Tuples are immutable lists. # No sorting, etc. Looking up tuple methods again. #I will likely work with a dictionary instead # and return the expected tuple in the end. - word_score = score_word(word) - word_list_scores.append(word_score) - highest_score = max(word_list_scores) - word_score_pairs = (word, word_score) - if word_score_pairs[1] == highest_score: - best_word.append(word_score_pairs[0]) - best_word[0] = word_score_pairs[0] - if len(best_word) > 0: - holding_spot = [] - best_word = holding_spot.append(word) + # word_score = score_word(word) + # word_list_scores.append(word_score) + # highest_score = max(word_list_scores) + # word_score_pairs = (word, word_score) + # if word_score_pairs[1] == highest_score: + # best_word.append(word_score_pairs[0]) + # best_word[0] = word_score_pairs[0] + # if len(best_word) > 0: + # holding_spot = [] + # best_word = holding_spot.append(word) # ^^^^^I was working on this earlier until I realized Tuples are immutable. #I am pseudo-coding and rewriting everything now. Everything below is old code. @@ -252,3 +237,23 @@ def get_highest_word_score(word_list): # return highest_score_tuple + +""" +Wave 4: +This method should have the following properties: + +Has one parameter: word_list, which is a list of strings +Returns a tuple that represents the data of a winning word and it's score. + +The tuple must contain the following elements: +index 0 ([0]): a string of a word +index 1 ([1]): the score of that word + +In the case of tie in scores, use these tie-breaking rules: +prefer the word with the fewest letters... +...unless one word has 10 letters. + +If the top score is tied between multiple words and one is 10 letters long, +choose the one with 10 letters over the one with fewer tiles +If the there are multiple words that are the same score and the same length, +pick the first one in the supplied list""" \ No newline at end of file From d630b7e14c4c8db0ea0ef75258dfb92f02984ba6 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Thu, 31 Mar 2022 19:56:17 -0400 Subject: [PATCH 24/29] 'Tidying up Wave 4. 1 test left.' --- adagrams/game.py | 60 +++++++----------------------------------------- 1 file changed, 8 insertions(+), 52 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index be0b5073..5b8c916c 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -104,13 +104,9 @@ def uses_available_letters(word, letter_bank): def score_word(word): """ Wave 3: score_word -Now you need a function returns the score of a given word as defined by the Adagrams game. +Returns the score of a given word as defined by the Adagrams game. -Implement the function score_word in game.py. This method should have the following properties: - -Has one parameter: word, which is a string of characters -Returns an integer representing the number of points -Each letter within word has a point value. The number of points of each letter is summed up to represent the total score of word +The number of points of each letter is summed up to represent the total score of word Each letter's point value is described in the table below If the length of the word is 7, 8, 9, or 10, then the word gets an additional 8 points @@ -125,32 +121,31 @@ def score_word(word): word_score += 8 for letter in input_word: word_score += SCORE_CHART[letter] - + return word_score def get_highest_word_score(word_list): best_word_list = [] - # Translating word list and scores into a dictionary and finding highest word score in dictionary: for word in word_list: - word_score_dict = {word: score_word(word) for word in word_list} #Dictionary comprehension + word_score_dict = {word: score_word(word) for word in word_list} #Dictionary comprehension highest_word_score = max(word_score_dict.values()) - -# Max only returns the first match so we need to check which if any other values == highest score +# Max only returns the first match so we need to check +# which if any other values == highest score # Once clear append the keys for those highest_scores values to the best_word_list. for word in word_score_dict: if word_score_dict[word] == highest_word_score: best_word_list.append(word) -#Conditional check to see if length is more than 1 then apply tie-breaker logic (see below) +#Conditional check to see if length is more than 1 then apply tie-breaker logic (see helper function) best_word = best_word_list[0] if len(best_word_list) == 1 else tie_breaker(best_word_list) return (best_word, word_score_dict[best_word]) -#Appy tie-breaker logic +#Appy tie-breaker logic def tie_breaker(best_word_list): for word in best_word_list: if len(word) == 10: @@ -159,43 +154,6 @@ def tie_breaker(best_word_list): return min(best_word_list, key=len) - # highest_score_list.append(highest_score) # Not sure if I will use this yet - - # Remember the .items method returns tuples of key value pairs! - # for word, word_score in word_score_dict.items: - # max_word_score_dict = max(word_score_dict.keys(), key = lambda find_max: word_score_dict[word]) - # if word_score == max_word_score_dict: - # if word_score in... - # pass - - - #Maybe try a zip function - - - - -# Oh darn...Tuples are immutable lists. -# No sorting, etc. Looking up tuple methods again. -#I will likely work with a dictionary instead -# and return the expected tuple in the end. - - # word_score = score_word(word) - # word_list_scores.append(word_score) - # highest_score = max(word_list_scores) - # word_score_pairs = (word, word_score) - # if word_score_pairs[1] == highest_score: - # best_word.append(word_score_pairs[0]) - # best_word[0] = word_score_pairs[0] - # if len(best_word) > 0: - # holding_spot = [] - # best_word = holding_spot.append(word) - -# ^^^^^I was working on this earlier until I realized Tuples are immutable. -#I am pseudo-coding and rewriting everything now. Everything below is old code. -# I broke it up with bits of docstring to make it easier to process. -################################## - - """ Everything below is from the previous version that got us to 4 passed tests. """ # for word in word_list: # # word_length= len(word) @@ -236,8 +194,6 @@ def tie_breaker(best_word_list): # return highest_score_tuple - - """ Wave 4: This method should have the following properties: From 41457d833553927c6f37937b2d80d917977bdae3 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Thu, 31 Mar 2022 20:08:35 -0400 Subject: [PATCH 25/29] "Wave 4 refactored with ternary operator." --- adagrams/game.py | 51 ++++-------------------------------------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5b8c916c..2f5546af 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -119,6 +119,7 @@ def score_word(word): return 0 if word_length >= 7: word_score += 8 + for letter in input_word: word_score += SCORE_CHART[letter] @@ -142,57 +143,13 @@ def get_highest_word_score(word_list): #Conditional check to see if length is more than 1 then apply tie-breaker logic (see helper function) best_word = best_word_list[0] if len(best_word_list) == 1 else tie_breaker(best_word_list) - return (best_word, word_score_dict[best_word]) - + return (best_word, highest_word_score) #Appy tie-breaker logic def tie_breaker(best_word_list): - for word in best_word_list: - if len(word) == 10: - return word - else: - return min(best_word_list, key=len) - - -""" Everything below is from the previous version that got us to 4 passed tests. """ - # for word in word_list: - # # word_length= len(word) - # word_score = score_word(word) - # word_list_scores.append(word_score) - # highest_score = max(word_list_scores) - # if word_score == highest_score: - # best_word.append(word) - - -""" -In the case of tie in scores, use these tie-breaking rules: -prefer the word with the fewest letters... -...unless one word has 10 letters. -""" - # if len(best_word) == 1: - # word = best_word[0] - # highest_score_tuple = (word, highest_score) - # return highest_score_tuple - + for word in best_word_list: + return word if len(word) == 10 else min(best_word_list, key = len) -""" -If the top score is tied between multiple words and one is 10 letters long, -choose the one with 10 letters over the one with fewer tiles -If the there are multiple words that are the same score and the same length, -pick the first one in the supplied list""" - - # for word in best_word: - - # if len(word) == 10: - # highest_score_tuple = (word, highest_score) - # return highest_score_tuple - # else: - # ### this isn't the right way to do it! - # ## but thought is that we have a - # shortest_word = min(word_list, key=lambda word: len(word)) - # highest_score_tuple = (shortest_word, highest_score) - - # return highest_score_tuple """ Wave 4: From d1a1fe95bc65a606b484af43d09d75b8a2064b37 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Fri, 1 Apr 2022 10:20:13 -0400 Subject: [PATCH 26/29] "Wave 4 complete." --- adagrams/game.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 2f5546af..a3e4f1c3 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -117,17 +117,26 @@ def score_word(word): if input_word == "": return 0 - if word_length >= 7: - word_score += 8 + # if word_length >= 7: + # word_score += 8 + + # for letter in input_word: + # word_score += SCORE_CHART[letter] + + # return word_score for letter in input_word: word_score += SCORE_CHART[letter] + if word_length >= 7: + word_score += 8 + return word_score def get_highest_word_score(word_list): best_word_list = [] + best_score_list =[] # Translating word list and scores into a dictionary and finding highest word score in dictionary: for word in word_list: word_score_dict = {word: score_word(word) for word in word_list} #Dictionary comprehension @@ -139,6 +148,7 @@ def get_highest_word_score(word_list): for word in word_score_dict: if word_score_dict[word] == highest_word_score: best_word_list.append(word) + best_score_list.append(word_score_dict[word]) #Conditional check to see if length is more than 1 then apply tie-breaker logic (see helper function) best_word = best_word_list[0] if len(best_word_list) == 1 else tie_breaker(best_word_list) @@ -148,7 +158,13 @@ def get_highest_word_score(word_list): #Appy tie-breaker logic def tie_breaker(best_word_list): for word in best_word_list: - return word if len(word) == 10 else min(best_word_list, key = len) + # return word if len(word) == 10 else min(best_word_list, key = len) + if len(word) == 10: + return word + + return min(best_word_list, key = len) + + """ From 87814594d76095170d77a76e4cdc0b9cdc5509e8 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Fri, 1 Apr 2022 10:46:24 -0400 Subject: [PATCH 27/29] "game.py tidied and reafactored." --- adagrams/game.py | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index a3e4f1c3..e8ee34aa 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -78,11 +78,10 @@ def draw_letters(): def uses_available_letters(word, letter_bank): input_word = word.upper() print(f"This is the value of {input_word=}") + #We initially explored using the Counter approach ut didnt go with it. + # We left it here (commented out) to be able to discuss in our 1:1with instructors # word_counter = Counter(input_word) - # print(f"Thisis the data type of word_counter: {type(word_counter)=}") - # print(f"This is the value of {word_counter=}") # # letter_bank_counter = Counter(letter_bank) - # print(f"This is the value of letter_bank_counter: {letter_bank_counter}") for letter in input_word: if letter not in letter_bank: @@ -117,13 +116,6 @@ def score_word(word): if input_word == "": return 0 - # if word_length >= 7: - # word_score += 8 - - # for letter in input_word: - # word_score += SCORE_CHART[letter] - - # return word_score for letter in input_word: word_score += SCORE_CHART[letter] @@ -137,28 +129,28 @@ def score_word(word): def get_highest_word_score(word_list): best_word_list = [] best_score_list =[] + # Translating word list and scores into a dictionary and finding highest word score in dictionary: for word in word_list: word_score_dict = {word: score_word(word) for word in word_list} #Dictionary comprehension highest_word_score = max(word_score_dict.values()) -# Max only returns the first match so we need to check -# which if any other values == highest score +# Max only returns the first match so we need to check which (if any) other values == highest score # Once clear append the keys for those highest_scores values to the best_word_list. for word in word_score_dict: if word_score_dict[word] == highest_word_score: best_word_list.append(word) best_score_list.append(word_score_dict[word]) -#Conditional check to see if length is more than 1 then apply tie-breaker logic (see helper function) +#Conditional check to see if length is more than 1 then apply tie-breaker logic +# (see helper function further below) best_word = best_word_list[0] if len(best_word_list) == 1 else tie_breaker(best_word_list) return (best_word, highest_word_score) -#Appy tie-breaker logic +#Tie-breaker logic def tie_breaker(best_word_list): for word in best_word_list: - # return word if len(word) == 10 else min(best_word_list, key = len) if len(word) == 10: return word @@ -167,22 +159,3 @@ def tie_breaker(best_word_list): -""" -Wave 4: -This method should have the following properties: - -Has one parameter: word_list, which is a list of strings -Returns a tuple that represents the data of a winning word and it's score. - -The tuple must contain the following elements: -index 0 ([0]): a string of a word -index 1 ([1]): the score of that word - -In the case of tie in scores, use these tie-breaking rules: -prefer the word with the fewest letters... -...unless one word has 10 letters. - -If the top score is tied between multiple words and one is 10 letters long, -choose the one with 10 letters over the one with fewer tiles -If the there are multiple words that are the same score and the same length, -pick the first one in the supplied list""" \ No newline at end of file From a56d56f5273e414471dfa2040637740faf1b2804 Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Fri, 1 Apr 2022 11:15:56 -0400 Subject: [PATCH 28/29] "Waves 1 to 4 refactored and tidied" --- adagrams/game.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index e8ee34aa..bd2d7dd6 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -78,8 +78,8 @@ def draw_letters(): def uses_available_letters(word, letter_bank): input_word = word.upper() print(f"This is the value of {input_word=}") - #We initially explored using the Counter approach ut didnt go with it. - # We left it here (commented out) to be able to discuss in our 1:1with instructors + #We initially explored using the Counter approach but didnt go with it. + # We left it here (commented out) to be able to discuss in our 1:1s with instructors # word_counter = Counter(input_word) # # letter_bank_counter = Counter(letter_bank) @@ -93,6 +93,7 @@ def uses_available_letters(word, letter_bank): return False return True + # Remnant from initial Counter approach: # for (k, v), (k2, v2) in zip(word_counter.items(), letter_bank_counter.items()): # zip(word_counter.items(), letter_bank_counter.items()) # if k == k2 and v > v2: From 6e2fad60a14f779daf159538af70054e95d21b2b Mon Sep 17 00:00:00 2001 From: Hope Olaide Date: Fri, 1 Apr 2022 11:17:59 -0400 Subject: [PATCH 29/29] Extra file for alternative code. Add here. --- adagrams/old_code_review.py | 153 ++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 adagrams/old_code_review.py diff --git a/adagrams/old_code_review.py b/adagrams/old_code_review.py new file mode 100644 index 00000000..08f15acc --- /dev/null +++ b/adagrams/old_code_review.py @@ -0,0 +1,153 @@ +"""WAVE 4 Old Code Review """ + +""" Everything below is from the previous version that got us to 4 passed tests. """ + # for word in word_list: + # # word_length= len(word) + # word_score = score_word(word) + # word_list_scores.append(word_score) + # highest_score = max(word_list_scores) + # if word_score == highest_score: + # best_word.append(word) + + +""" +In the case of tie in scores, use these tie-breaking rules: +prefer the word with the fewest letters... +...unless one word has 10 letters. +""" + # if len(best_word) == 1: + # word = best_word[0] + # highest_score_tuple = (word, highest_score) + # return highest_score_tuple + + +""" +If the top score is tied between multiple words and one is 10 letters long, +choose the one with 10 letters over the one with fewer tiles +If the there are multiple words that are the same score and the same length, +pick the first one in the supplied list""" + + # for word in best_word: + + # if len(word) == 10: + # highest_score_tuple = (word, highest_score) + # return highest_score_tuple + # else: + # ### this isn't the right way to do it! + # ## but thought is that we have a + # shortest_word = min(word_list, key=lambda word: len(word)) + # highest_score_tuple = (shortest_word, highest_score) + + # return highest_score_tuple + + + + + + + +""" + Super old Wave 4 code. Ignore below """ + + + + # for word_score in word_list_scores: + # word_score_frequency = word_list_scores.count(word_score) + # highest_score = max(word_list_scores) + # print(f"THIS IS THE WORD SCORE FREQUENCY{word_score_frequency=}") + # if word_score == highest_score: + # highest_score = word_score + # highest_score_tuple = (word, highest_score) + # if word_score_frequency > 1: + # if word_length == 10: + + # highest_score_tuple = (word, highest_score) + # else: + # shortest_word = min(word_list, key=lambda word: len(word)) + # highest_score_tuple = (shortest_word, highest_score) + + # highest_score.append(word_score) + # if word_score > highest_word_score: + + + + # score = score_word(word) + # score_list.append(score) + # highest_score = max(score_list) + # for score in score_list: + # if score == highest_score: + # highest_scores.append(score) + # print(f' THIS SHOULD BE A LIST OF TUPLES{highest_scores=}') + + + + + # # score_list.append(score) + # #[a word, 3 another,6,10,4,10] + # highest_score = highest_score.append(word, score) + # best_score = highest_score[0] + # for word_info in highest_score: + # if word_info[1] > best_score[1]: + + + + # max_score = max(score_list) + # if score == max_score: + # best_score.append(word, score) + # if len(best_score) > 1: + + + # user_scores = (word, score) + # score_list.append(user_scores) + + # max_score = max(score_list) + # for user in score_list: + # if user[1] > max_score: + # user[1] = max_score + + +# def get_highest_scoring_words(word_list): +# best_score = 0 +# score_list = [] +# best_words = [] +# word_lengths = [] +# shortest_words = [] + +# for word in word_list: +# word_lengths.append(len(word)) +# smallest_length = min(word_lengths) +# if len(word) == smallest_length: +# shortest_words.append(word) + + +# for word in word_list: +# score = score_word(word) +# score_list.append(score) +# best_score = max(score_list) +# if score == best_score: +# best_words.append(word) + +# return tuple(best_words, best_score, shortest_words[0]) + + + + +# def get_highest_word_score(word_list): +# calculate_score = get_highest_scoring_words(word_list) +# score = calculate_score[1] +# winning_words = calculate_score[0] +# shortest_word = calculate_score[2] +# winning_word = '' + +# if len(winning_words) == 1: +# winning_word = winning_words[0] + +# for word in winning_words: +# if len(word) == 10: +# winning_word = word +# break +# else: +# winning_word = shortest_word + +# return tuple(winning_word, score) +