From 71eab8a45c541e43b1d94e70002fa652d50834f6 Mon Sep 17 00:00:00 2001 From: Valerie Valentin Date: Wed, 22 Mar 2023 13:40:31 -0700 Subject: [PATCH 01/15] Finished wave 1 --- adagrams/game.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..a1d1723d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,5 +1,52 @@ +import random + +LETTER_POOL = { + 'A': 9, + 'B': 2, + 'C': 2, + 'D': 4, + 'E': 12, + 'F': 2, + 'G': 3, + 'H': 2, + 'I': 9, + 'J': 1, + 'K': 1, + 'L': 4, + 'M': 2, + 'N': 6, + 'O': 8, + 'P': 2, + 'Q': 1, + 'R': 6, + 'S': 4, + 'T': 6, + 'U': 4, + 'V': 2, + 'W': 2, + 'X': 1, + 'Y': 2, + 'Z': 1 +} + + + + def draw_letters(): - pass + hand = [] + #Create copy of LETTER_POOL dict to modify without changing original + copy_letter_pool = LETTER_POOL.copy() + + while len(hand) < 10: + #Using random.choices to select a random letter after converting the copy to a list & utitlizing the weighted feature to get the weighted possibility of each letter from dict.values() & setting our population sample to 1. + random_letter = random.choices(list(copy_letter_pool), weights = copy_letter_pool.values(), k=1) + #random.choices returns a list, so must index into list to retrieve the value of the random letter + str_random_letter = random_letter[0] + + if copy_letter_pool[str_random_letter] > 0: + hand.append(str_random_letter) + copy_letter_pool[str_random_letter] += -1 + return hand def uses_available_letters(word, letter_bank): pass From abc2e8b5fd532abc65722b164a9c0ebd63e9f359 Mon Sep 17 00:00:00 2001 From: Valerie Valentin Date: Wed, 22 Mar 2023 19:11:19 -0700 Subject: [PATCH 02/15] Finished wave 2 --- adagrams/game.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index a1d1723d..63b3b484 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -49,7 +49,28 @@ def draw_letters(): return hand def uses_available_letters(word, letter_bank): - pass + quantity_available = {} + validate_enough_available = {} + upper_word = word.upper() + + #Creating a dict to hold the quantity available for each letter + for letter in letter_bank: + available_count = letter_bank.count(letter) + quantity_available[letter] = available_count + #Validating if there is enough quantity available per letter & storing in another dict + for character in upper_word: + amount_needed_for_word = upper_word.count(character) + if character in quantity_available and (amount_needed_for_word <= quantity_available[character]): + validate_enough_available[character] = True + else: + validate_enough_available[character] = False + #Returning True or False if there is sufficent letters available to form word + if False in validate_enough_available.values(): + return False + else: + return True + + def score_word(word): pass From 9e1af5719cbf34b449117c04e94ea46e721eb46f Mon Sep 17 00:00:00 2001 From: Valerie Valentin Date: Wed, 22 Mar 2023 20:40:02 -0700 Subject: [PATCH 03/15] Finished Wave 3 --- adagrams/game.py | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 63b3b484..df80e3ec 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -69,11 +69,45 @@ def uses_available_letters(word, letter_bank): return False else: return True - - - + def score_word(word): - pass + score = 0 + 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, + } + + for letter in word.upper(): + if letter in score_chart: + score += score_chart[letter] + if len(word) >= 7: + score += 8 + return score + def get_highest_word_score(word_list): pass \ No newline at end of file From 925d2916949e57c90ffb5de260abae2902866225 Mon Sep 17 00:00:00 2001 From: Valerie Valentin Date: Thu, 23 Mar 2023 21:27:23 -0700 Subject: [PATCH 04/15] Finished wave 4 --- adagrams/game.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index df80e3ec..7a47b0a5 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -110,4 +110,29 @@ def score_word(word): def get_highest_word_score(word_list): - pass \ No newline at end of file + player_scores = {} + top_players = [] + + for word in word_list: + word_score = score_word(word) + player_scores[word] = word_score + + highest_score = max(player_scores.values()) + + for key, value in player_scores.items(): + if value >= highest_score: + top_players.append((key, value)) + + + winner = top_players[0] + + for word, score in top_players: + if len(word) == len(winner[0]): + winner = winner + elif len(word) >= 10: + winner = (word, score) + elif len(word) < len(winner[0]) and len(winner[0]) != 10: + winner = (word, score) + return winner + + From ec516def161a79d59433678330660d5e8f3af361 Mon Sep 17 00:00:00 2001 From: Valerie Valentin Date: Thu, 23 Mar 2023 22:24:33 -0700 Subject: [PATCH 05/15] Removed comments --- adagrams/game.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 7a47b0a5..7adb3020 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -30,17 +30,12 @@ } - - def draw_letters(): hand = [] - #Create copy of LETTER_POOL dict to modify without changing original copy_letter_pool = LETTER_POOL.copy() while len(hand) < 10: - #Using random.choices to select a random letter after converting the copy to a list & utitlizing the weighted feature to get the weighted possibility of each letter from dict.values() & setting our population sample to 1. random_letter = random.choices(list(copy_letter_pool), weights = copy_letter_pool.values(), k=1) - #random.choices returns a list, so must index into list to retrieve the value of the random letter str_random_letter = random_letter[0] if copy_letter_pool[str_random_letter] > 0: @@ -51,20 +46,18 @@ def draw_letters(): def uses_available_letters(word, letter_bank): quantity_available = {} validate_enough_available = {} - upper_word = word.upper() - #Creating a dict to hold the quantity available for each letter for letter in letter_bank: available_count = letter_bank.count(letter) quantity_available[letter] = available_count - #Validating if there is enough quantity available per letter & storing in another dict - for character in upper_word: - amount_needed_for_word = upper_word.count(character) + + for character in word.upper(): + amount_needed_for_word = (word.upper()).count(character) if character in quantity_available and (amount_needed_for_word <= quantity_available[character]): validate_enough_available[character] = True else: validate_enough_available[character] = False - #Returning True or False if there is sufficent letters available to form word + if False in validate_enough_available.values(): return False else: @@ -108,7 +101,6 @@ def score_word(word): score += 8 return score - def get_highest_word_score(word_list): player_scores = {} top_players = [] @@ -123,7 +115,6 @@ def get_highest_word_score(word_list): if value >= highest_score: top_players.append((key, value)) - winner = top_players[0] for word, score in top_players: From 9750c404eca34c6222fac0a339c91d781538a5cc Mon Sep 17 00:00:00 2001 From: Valerie Valentin Date: Thu, 23 Mar 2023 22:51:59 -0700 Subject: [PATCH 06/15] Fixed spacing --- adagrams/game.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 7adb3020..44e74517 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -109,9 +109,8 @@ def get_highest_word_score(word_list): word_score = score_word(word) player_scores[word] = word_score - highest_score = max(player_scores.values()) - for key, value in player_scores.items(): + highest_score = max(player_scores.values()) if value >= highest_score: top_players.append((key, value)) From 2a75177afaeba048ca3139d58ec3c8872320f38d Mon Sep 17 00:00:00 2001 From: Valerie Valentin Date: Fri, 24 Mar 2023 08:29:41 -0700 Subject: [PATCH 07/15] final version --- adagrams/game.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 44e74517..c2b6d08d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -104,23 +104,20 @@ def score_word(word): def get_highest_word_score(word_list): player_scores = {} top_players = [] - for word in word_list: word_score = score_word(word) player_scores[word] = word_score + highest_score = max(player_scores.values()) for key, value in player_scores.items(): - highest_score = max(player_scores.values()) if value >= highest_score: top_players.append((key, value)) winner = top_players[0] - for word, score in top_players: - if len(word) == len(winner[0]): - winner = winner - elif len(word) >= 10: + if len(word) >= 10: winner = (word, score) + return winner elif len(word) < len(winner[0]) and len(winner[0]) != 10: winner = (word, score) return winner From 133f16d3ac543ea539b9980179f867e0322080e9 Mon Sep 17 00:00:00 2001 From: Valerie Valentin Date: Fri, 24 Mar 2023 08:46:11 -0700 Subject: [PATCH 08/15] Final version --- adagrams/game.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index c2b6d08d..64e0ce18 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -33,7 +33,6 @@ def draw_letters(): hand = [] copy_letter_pool = LETTER_POOL.copy() - while len(hand) < 10: random_letter = random.choices(list(copy_letter_pool), weights = copy_letter_pool.values(), k=1) str_random_letter = random_letter[0] @@ -46,7 +45,6 @@ def draw_letters(): def uses_available_letters(word, letter_bank): quantity_available = {} validate_enough_available = {} - for letter in letter_bank: available_count = letter_bank.count(letter) quantity_available[letter] = available_count @@ -93,7 +91,7 @@ def score_word(word): "Y": 4, "Z": 10, } - + for letter in word.upper(): if letter in score_chart: score += score_chart[letter] From 577f93972ceb61efb7410cf465eef04185f17999 Mon Sep 17 00:00:00 2001 From: Valerie Valentin Date: Wed, 7 Jun 2023 00:00:49 -0700 Subject: [PATCH 09/15] Refactoring in progress --- adagrams/game.py | 105 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 32 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 64e0ce18..d7fe0acc 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -39,27 +39,32 @@ def draw_letters(): if copy_letter_pool[str_random_letter] > 0: hand.append(str_random_letter) - copy_letter_pool[str_random_letter] += -1 + copy_letter_pool[str_random_letter] -= 1 return hand def uses_available_letters(word, letter_bank): - quantity_available = {} - validate_enough_available = {} - for letter in letter_bank: - available_count = letter_bank.count(letter) - quantity_available[letter] = available_count + word_upper = word.upper() + for letter in word_upper: + if word_upper.count(letter) != letter_bank.count(letter): + return False + return True + # quantity_available = {} + # validate_enough_available = {} + # for letter in letter_bank: + # available_count = letter_bank.count(letter) + # quantity_available[letter] = available_count - for character in word.upper(): - amount_needed_for_word = (word.upper()).count(character) - if character in quantity_available and (amount_needed_for_word <= quantity_available[character]): - validate_enough_available[character] = True - else: - validate_enough_available[character] = False + # for character in word.upper(): + # amount_needed_for_word = (word.upper()).count(character) + # if character in quantity_available and (amount_needed_for_word <= quantity_available[character]): + # validate_enough_available[character] = True + # else: + # validate_enough_available[character] = False - if False in validate_enough_available.values(): - return False - else: - return True + # if False in validate_enough_available.values(): + # return False + # else: + # return True def score_word(word): score = 0 @@ -100,24 +105,60 @@ def score_word(word): return score def get_highest_word_score(word_list): - player_scores = {} - top_players = [] + highest_score = 0 + winner = None + for word in word_list: - word_score = score_word(word) - player_scores[word] = word_score + word_score = score_word(word) + if word_score > highest_score: + highest_score = word_score + winner = (word, word_score) + elif word_score == highest_score: + if len(word) == 10: + return (word, word_score) + elif len(word) < len(winner[0]): + winner = (word, word_score) + return winner - highest_score = max(player_scores.values()) - for key, value in player_scores.items(): - if value >= highest_score: - top_players.append((key, value)) + # highest_score = 0 + # top_players = None - winner = top_players[0] - for word, score in top_players: - if len(word) >= 10: - winner = (word, score) - return winner - elif len(word) < len(winner[0]) and len(winner[0]) != 10: - winner = (word, score) - return winner + # for word in word_list: + # word_score = score_word(word) + # if word_score > highest_score: + # highest_score = word_score + # top_players = [(word, word_score)] + # if word_score == top_players[0][1]: + # top_players.append((word, word_score)) + + # winner = top_players[0] + # for word, score in top_players: + # if len(word) == 10: + # winner = (word, score) + # return winner + # if len(word) < len(winner[0]): + # winner = (word, score) + # return winner + + + # player_scores = {} + # top_players = [] + # for word in word_list: + # word_score = score_word(word) + # player_scores[word] = word_score + + # highest_score = max(player_scores.values()) + # for key, value in player_scores.items(): + # if value >= highest_score: + # top_players.append((key, value)) + + # winner = top_players[0] + # for word, score in top_players: + # if len(word) == 10: + # winner = (word, score) + # return winner + # if len(word) < len(winner[0]): + # winner = (word, score) + # return winner From 021aa80eb5c519b74c7f4e6062465b0f5f615f7f Mon Sep 17 00:00:00 2001 From: Valerie Valentin <121909894+valerie-valentine@users.noreply.github.com> Date: Fri, 22 Mar 2024 12:55:12 -0700 Subject: [PATCH 10/15] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index cfaa5310..87d68333 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,7 @@ In this version of _Adagrams_, we will only be working with the English alphabet Follow these directions once, at the beginning of your project: -1. Navigate to your projects folder named `projects`. - -If you followed Ada's recommended file system structure from the Intro to Dev Environment lesson in Learn, you can navigate to your projects folder with the following command: +1. Navigate to the folder where this project will be stored. The example below is named `projects`. ```bash $ cd ~/Developer/projects From 0b56c2ed43edbe2e20229d2a5faf9aee32bc2ba2 Mon Sep 17 00:00:00 2001 From: Valerie Valentin <121909894+valerie-valentine@users.noreply.github.com> Date: Fri, 22 Mar 2024 12:56:13 -0700 Subject: [PATCH 11/15] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 87d68333..e076d85f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ ## Skills Assessed -- Following directions and reading comprehension - Reading tests - Using git to maintain code - Manipulating and processing data in lists and strings From e255e53c706c0586b5d1e610953a4b974e7435fe Mon Sep 17 00:00:00 2001 From: Valerie Valentin <121909894+valerie-valentine@users.noreply.github.com> Date: Fri, 22 Mar 2024 12:57:29 -0700 Subject: [PATCH 12/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e076d85f..f8c5e20e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ In this version of _Adagrams_, we will only be working with the English alphabet Follow these directions once, at the beginning of your project: -1. Navigate to the folder where this project will be stored. The example below is named `projects`. +1. Navigate to your folder which where this project will be cloned. Example below is named projects. ```bash $ cd ~/Developer/projects From 86cd71f454e783f8b1720d49202a67de382c3c9b Mon Sep 17 00:00:00 2001 From: Valerie Valentin <121909894+valerie-valentine@users.noreply.github.com> Date: Fri, 22 Mar 2024 12:58:34 -0700 Subject: [PATCH 13/15] Update README.md --- README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.md b/README.md index f8c5e20e..b6d2aa81 100644 --- a/README.md +++ b/README.md @@ -151,18 +151,9 @@ Go through the waves one-by-one and build the features of this game. You will use play-testing and unit tests to drive your development. -At submission time, no matter where you are, submit the project via Learn. - -This will let us give feedback on what you've finished so that you can be better prepared for the next project. ## Project Directions -### Get Familiar - -Take time to read through the Wave 1 implementation requirements and the tests for Wave 1. Write down your questions, and spend some time going through your understanding of the requirements and tests. Make sure you can run `$ pytest` and see the tests fail. - -If, after you have taken some time to think through the problem and would like direction for how to dissect the problem, or if you need clarity on the terms/vocabulary we used in this project, you can check out [a small hint we've provided](./project_docs/hints.md). - ### Wave 1: draw_letters Your first task is to build a hand of 10 letters for the user. To do so, implement the function `draw_letters` in `game.py`. This method should have the following properties: From b393f4092d64d7dbc43f823b70c00dc80c1ba058 Mon Sep 17 00:00:00 2001 From: Valerie Valentin <121909894+valerie-valentine@users.noreply.github.com> Date: Fri, 22 Mar 2024 12:59:10 -0700 Subject: [PATCH 14/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b6d2aa81..75eaa5ea 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ $ pytest $ pytest -s ``` -## Project Write-Up: How to Complete and Submit +## Notes The goal of this project is to write code in `game.py` so each of the functions meet the requirements outlined in the Project Directions below. From 7d1f6e6d081d7d3b978488cea3216d0f1ec80dfa Mon Sep 17 00:00:00 2001 From: Valerie Valentin Date: Fri, 22 Mar 2024 13:07:28 -0700 Subject: [PATCH 15/15] removing old code --- adagrams/game.py | 132 ++++++++++++++--------------------------------- 1 file changed, 38 insertions(+), 94 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index d7fe0acc..9982a594 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,31 +1,31 @@ import random LETTER_POOL = { - 'A': 9, - 'B': 2, - 'C': 2, - 'D': 4, - 'E': 12, - 'F': 2, - 'G': 3, - 'H': 2, - 'I': 9, - 'J': 1, - 'K': 1, - 'L': 4, - 'M': 2, - 'N': 6, - 'O': 8, - 'P': 2, - 'Q': 1, - 'R': 6, - 'S': 4, - 'T': 6, - 'U': 4, - 'V': 2, - 'W': 2, - 'X': 1, - 'Y': 2, + '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 } @@ -34,38 +34,24 @@ def draw_letters(): hand = [] copy_letter_pool = LETTER_POOL.copy() while len(hand) < 10: - random_letter = random.choices(list(copy_letter_pool), weights = copy_letter_pool.values(), k=1) - str_random_letter = random_letter[0] - - if copy_letter_pool[str_random_letter] > 0: - hand.append(str_random_letter) - copy_letter_pool[str_random_letter] -= 1 + random_letter = random.choices( + list(copy_letter_pool), weights=copy_letter_pool.values(), k=1) + str_random_letter = random_letter[0] + + if copy_letter_pool[str_random_letter] > 0: + hand.append(str_random_letter) + copy_letter_pool[str_random_letter] -= 1 return hand + def uses_available_letters(word, letter_bank): word_upper = word.upper() for letter in word_upper: if word_upper.count(letter) != letter_bank.count(letter): return False return True - # quantity_available = {} - # validate_enough_available = {} - # for letter in letter_bank: - # available_count = letter_bank.count(letter) - # quantity_available[letter] = available_count - # for character in word.upper(): - # amount_needed_for_word = (word.upper()).count(character) - # if character in quantity_available and (amount_needed_for_word <= quantity_available[character]): - # validate_enough_available[character] = True - # else: - # validate_enough_available[character] = False - - # if False in validate_enough_available.values(): - # return False - # else: - # return True - + def score_word(word): score = 0 score_chart = { @@ -75,11 +61,11 @@ def score_word(word): "D": 2, "E": 1, "F": 4, - "G": 2, + "G": 2, "H": 4, "I": 1, "J": 8, - "K": 5, + "K": 5, "L": 1, "M": 3, "N": 1, @@ -96,7 +82,7 @@ def score_word(word): "Y": 4, "Z": 10, } - + for letter in word.upper(): if letter in score_chart: score += score_chart[letter] @@ -104,6 +90,7 @@ def score_word(word): score += 8 return score + def get_highest_word_score(word_list): highest_score = 0 winner = None @@ -119,46 +106,3 @@ def get_highest_word_score(word_list): elif len(word) < len(winner[0]): winner = (word, word_score) return winner - - # highest_score = 0 - # top_players = None - - # for word in word_list: - # word_score = score_word(word) - # if word_score > highest_score: - # highest_score = word_score - # top_players = [(word, word_score)] - # if word_score == top_players[0][1]: - # top_players.append((word, word_score)) - - # winner = top_players[0] - # for word, score in top_players: - # if len(word) == 10: - # winner = (word, score) - # return winner - # if len(word) < len(winner[0]): - # winner = (word, score) - # return winner - - - # player_scores = {} - # top_players = [] - # for word in word_list: - # word_score = score_word(word) - # player_scores[word] = word_score - - # highest_score = max(player_scores.values()) - # for key, value in player_scores.items(): - # if value >= highest_score: - # top_players.append((key, value)) - - # winner = top_players[0] - # for word, score in top_players: - # if len(word) == 10: - # winner = (word, score) - # return winner - # if len(word) < len(winner[0]): - # winner = (word, score) - # return winner - -