From d15af7221a3bb9481c82f977ac5a372550125bb3 Mon Sep 17 00:00:00 2001 From: Say Ryder Date: Wed, 22 Mar 2023 08:08:22 -0400 Subject: [PATCH 1/6] Made it past wave 1 --- adagrams/game.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..b9073f0f 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,5 +1,58 @@ +import random + + def draw_letters(): - pass + hand_dict = {} + LETTER_POOL = { 'A': 9, 'N': 6, + 'B': 2, 'O': 8, + 'C': 2, 'P': 2, + 'D': 4, 'Q': 1, + 'E': 12,'R': 6, + 'F': 2, 'S': 4, + 'G': 3, 'T': 6, + 'H': 2, 'U': 4, + 'I': 9, 'V': 2, + 'J': 1, 'W': 2, + 'K': 1, 'X': 1, + 'L': 4, 'Y': 2, + 'M': 2, 'Z': 1 + } + hand = [] + hand_dict = {} + num_letters = 10 + letters, weights = zip(*LETTER_POOL.items()) + hand = random.choices(letters, weights, k = num_letters) + valid_hand = False + + while not valid_hand: + for letter in hand: + if letter in hand_dict: + hand_dict[letter] += 1 + else: + hand_dict[letter] = 1 + + for letter in hand_dict.keys(): + if hand_dict[letter] <= LETTER_POOL[letter]: + valid_hand = True + else: + hand = random.choices(letters, weights, k = num_letters) + + return hand + + + + + + + + + + + + + + + def uses_available_letters(word, letter_bank): pass From f73c9f2086f6d16877834fc8682dc3a0255bf66c Mon Sep 17 00:00:00 2001 From: Say Ryder Date: Wed, 22 Mar 2023 18:22:22 -0400 Subject: [PATCH 2/6] made it past wave1 FOR REALZ --- adagrams/game.py | 74 +++++++++++++++++++++++-------------------- tests/test_wave_01.py | 1 + 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index b9073f0f..a2bc87b3 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,30 +1,45 @@ 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(): - hand_dict = {} - LETTER_POOL = { 'A': 9, 'N': 6, - 'B': 2, 'O': 8, - 'C': 2, 'P': 2, - 'D': 4, 'Q': 1, - 'E': 12,'R': 6, - 'F': 2, 'S': 4, - 'G': 3, 'T': 6, - 'H': 2, 'U': 4, - 'I': 9, 'V': 2, - 'J': 1, 'W': 2, - 'K': 1, 'X': 1, - 'L': 4, 'Y': 2, - 'M': 2, 'Z': 1 - } - hand = [] - hand_dict = {} num_letters = 10 letters, weights = zip(*LETTER_POOL.items()) - hand = random.choices(letters, weights, k = num_letters) + hand = [] valid_hand = False + while not valid_hand: + count = 0 + hand_dict = {} + hand = random.choices(letters, weights, k = num_letters) for letter in hand: if letter in hand_dict: hand_dict[letter] += 1 @@ -33,25 +48,14 @@ def draw_letters(): for letter in hand_dict.keys(): if hand_dict[letter] <= LETTER_POOL[letter]: - valid_hand = True - else: - hand = random.choices(letters, weights, k = num_letters) + count += 1 - return hand + if count == 10: + valid_hand = True + else: + hand = random.choices(letters, weights, k = num_letters) - - - - - - - - - - - - - + return hand def uses_available_letters(word, letter_bank): diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index ef48e03b..9e1ee217 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -54,6 +54,7 @@ def test_letter_not_selected_too_many_times(): for i in range(1000): # Arrange/Act letters = draw_letters() + print(letters) letter_freq = {} for letter in letters: From a1deee4e4041e20202fc022c8e3cc35b8e65ebab Mon Sep 17 00:00:00 2001 From: Say Ryder Date: Wed, 22 Mar 2023 21:23:28 -0400 Subject: [PATCH 3/6] passed wave 2 --- adagrams/game.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index a2bc87b3..d5363126 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -59,7 +59,38 @@ def draw_letters(): def uses_available_letters(word, letter_bank): - pass + word = list(word.upper()) + letter_bank = list("".join(letter_bank).upper()) + matched_letters = [] + + if len(word) <= len(letter_bank): + for letter in letter_bank: + if word.count(letter) <= letter_bank.count(letter): + continue + elif word.count(letter) > letter_bank.count(letter): + return False + + for letter in word: + if letter in letter_bank: + matched_letters.append(letter) + else: + return False + + + if len(word) == len(matched_letters): + for letter in word: + if word.count(letter) <= matched_letters.count(letter): + continue + else: + return False + + return True + else: + return False + + else: + return False + def score_word(word): pass From 513b40d04b508f95ef87f683d317e117401c0817 Mon Sep 17 00:00:00 2001 From: Say Ryder Date: Thu, 23 Mar 2023 18:58:10 -0400 Subject: [PATCH 4/6] wave 3 good to go --- adagrams/game.py | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index d5363126..b9fa105c 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -65,9 +65,8 @@ def uses_available_letters(word, letter_bank): if len(word) <= len(letter_bank): for letter in letter_bank: - if word.count(letter) <= letter_bank.count(letter): - continue - elif word.count(letter) > letter_bank.count(letter): + # erased if statement for continue + if word.count(letter) > letter_bank.count(letter): return False for letter in word: @@ -91,9 +90,46 @@ def uses_available_letters(word, letter_bank): else: return False - def score_word(word): - pass + score_value_dict = { + '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 +} + word = list(word.upper()) + score = 0 + + if len(word) >= 7: + score += 8 + + for letter in word: + if letter in score_value_dict: + score += score_value_dict[letter] + + return score def get_highest_word_score(word_list): pass \ No newline at end of file From 2ded86db21f355356d11f8e59947ade431ff95f1 Mon Sep 17 00:00:00 2001 From: Say Ryder Date: Thu, 23 Mar 2023 22:16:07 -0400 Subject: [PATCH 5/6] wave 4 complete --- adagrams/game.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index b9fa105c..fbf57df9 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -132,4 +132,27 @@ def score_word(word): return score def get_highest_word_score(word_list): - pass \ No newline at end of file + highest_score = 0 + winning_word = "" + words_len_ten = [] + + for word in word_list: + score = score_word(word) + + + if score == highest_score: + if len(word) == 10: + winning_word = word + words_len_ten.append(word) + elif len(word) < len(winning_word) and not len(winning_word) == 10: + winning_word = word + elif score > highest_score: + highest_score = score + winning_word = word + if len(word) == 10: + words_len_ten.append(word) + + if words_len_ten: + return (words_len_ten[0], highest_score) + else: + return (winning_word, highest_score) \ No newline at end of file From b81df293b4f64db9eba314fa15aebab63bcc8cb9 Mon Sep 17 00:00:00 2001 From: Say Ryder Date: Fri, 24 Mar 2023 11:31:48 -0400 Subject: [PATCH 6/6] refactor of uses_available_letters_() --- adagrams/game.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index fbf57df9..cde1023f 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,4 +1,6 @@ import random + + LETTER_POOL = { 'A': 9, 'B': 2, @@ -28,18 +30,17 @@ 'Z': 1 } - def draw_letters(): num_letters = 10 letters, weights = zip(*LETTER_POOL.items()) hand = [] valid_hand = False - while not valid_hand: - count = 0 + valid_letter_count = 0 hand_dict = {} hand = random.choices(letters, weights, k = num_letters) + for letter in hand: if letter in hand_dict: hand_dict[letter] += 1 @@ -48,9 +49,9 @@ def draw_letters(): for letter in hand_dict.keys(): if hand_dict[letter] <= LETTER_POOL[letter]: - count += 1 + valid_letter_count += 1 - if count == 10: + if valid_letter_count == 10: valid_hand = True else: hand = random.choices(letters, weights, k = num_letters) @@ -65,7 +66,6 @@ def uses_available_letters(word, letter_bank): if len(word) <= len(letter_bank): for letter in letter_bank: - # erased if statement for continue if word.count(letter) > letter_bank.count(letter): return False @@ -75,18 +75,15 @@ def uses_available_letters(word, letter_bank): else: return False - if len(word) == len(matched_letters): for letter in word: if word.count(letter) <= matched_letters.count(letter): continue else: return False - return True else: - return False - + return False else: return False @@ -132,27 +129,24 @@ def score_word(word): return score def get_highest_word_score(word_list): - highest_score = 0 + highest_word_score = 0 winning_word = "" words_len_ten = [] for word in word_list: score = score_word(word) - - - if score == highest_score: + if score == highest_word_score: if len(word) == 10: - winning_word = word words_len_ten.append(word) elif len(word) < len(winning_word) and not len(winning_word) == 10: winning_word = word - elif score > highest_score: - highest_score = score + elif score > highest_word_score: + highest_word_score = score winning_word = word if len(word) == 10: words_len_ten.append(word) if words_len_ten: - return (words_len_ten[0], highest_score) + return (words_len_ten[0], highest_word_score) else: - return (winning_word, highest_score) \ No newline at end of file + return (winning_word, highest_word_score) \ No newline at end of file