From 7abbbc34c2dbf4ea5eab78363b6347bcb4d9b7d5 Mon Sep 17 00:00:00 2001 From: Intesar Siraj Date: Mon, 26 Sep 2022 20:34:13 -0700 Subject: [PATCH 01/10] wave 1 and 2 --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index bcd6ab0b..9bc645e6 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ def wave_1_run_game(): display_retry_instructions() continue_input = input() game_continue = continue_input == "y" - + display_goodbye_message() def wave_2_run_game(): From 4457635b7067311c0c5d2ea94a3a8d5dcffe280a Mon Sep 17 00:00:00 2001 From: Intesar Siraj Date: Tue, 27 Sep 2022 14:25:04 -0700 Subject: [PATCH 02/10] Wave 1 and 2 --- adagrams/game.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..3f404be7 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,11 +1,97 @@ +import random +import string +# from collections import Counter + def draw_letters(): - pass + #create a pool for all the letters, using a list + #import random + # use random.choices to randomly generate 10 letters from the letter pool + + # LETTER_POOL = ["A","A","A","A","A","A","A","A","A", "B","B", "C","C","D","D","D","D","E","E","E","E","E","E","E","E","E","E", + # "E","E","F","F","G","G","G","H","H","I","I","I","I","I","I","I","I","I","J","K","L","L","L","L","M","M","N","N","N","N","N","N","O" + # ,"O","O","O","O","O","O","O","O","P","P","Q","R","R","R","R","R","R","S","S","S","S","T","T","T","T","T","T","U","U","U","U","V","V","W","W","X","Y","Y","Z"] + LETTER_POOL_COUNT = { + '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 +} + hand = [] + while len(hand) < 11: + random_letter = random.choice(string.ascii_uppercase) + if hand.count(random_letter) < LETTER_POOL_COUNT[random_letter]: + hand.append(random_letter) + else: + continue + + return hand + + # # random_letter = random.choice(string.ascii_uppercase) + # random_letter = random.choice(LETTER_POOL_COUNT.keys()) + # # if random_letter in hand: + # hand.append(random_letter) + # if hand.count(draw_letters) > LETTER_POOL_COUNT[draw_letters]: + # hand.pop() + + # and hand.count(draw_letter) <= LETTER_POOL_COUNT[draw_letter]: + # draw_letter = random.choice(LETTER_POOL_COUNT.keys()) + # hand.append(draw_letter) + + # return hand + + # letter_list = LETTER_POOL_COUNT.keys() + + # for letter in letter_list: + + + # for i in range (LETTER_POOL_COUNT[letter]): + # LETTER_POOL.append(letter) + # return random.choices(LETTER_POOL_COUNT,k=10) + def uses_available_letters(word, letter_bank): - pass + word_case = word.capitalize() + for letter in word_case: + while letter in letter_bank: + if word.count(letter) <= letter_bank.count(letter): + return True + return False + return False + def score_word(word): pass + # create the dictionary for letter in word (score_chart) + # score is starting from 0 + # iterate over the word and add scores, value = dict["keys"] + # check len(word) == 7, 8, 9, or 10, then score += 8 points def get_highest_word_score(word_list): - pass \ No newline at end of file + pass + # word_list: stores all words user submitted + # build a list/dict for all words & scores: {"word1" : score1; "word2" : score2; ... etc} + # find the max value in the dict/list dict.values, append to winning_dict + # handling ties: len(word)==10 > smalles len(word) > len1==len2: word1 wins + # return a tuple for the highest score words (word, score) \ No newline at end of file From e05bc49c8c7c14311b744ebf36b5faa9252a5e0a Mon Sep 17 00:00:00 2001 From: Intesar Siraj Date: Tue, 27 Sep 2022 15:08:50 -0700 Subject: [PATCH 03/10] wave2 test passed --- adagrams/game.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 3f404be7..26639a9d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,6 +1,6 @@ import random import string -# from collections import Counter +from collections import Counter def draw_letters(): #create a pool for all the letters, using a list @@ -72,13 +72,17 @@ def draw_letters(): # return random.choices(LETTER_POOL_COUNT,k=10) def uses_available_letters(word, letter_bank): - word_case = word.capitalize() + word_case = word.upper() + letter_count_dict = Counter(letter_bank) for letter in word_case: - while letter in letter_bank: - if word.count(letter) <= letter_bank.count(letter): - return True + if letter in letter_count_dict and letter_count_dict[letter] > 0: + letter_count_dict[letter] -= 1 + continue + else: return False - return False + + + return True def score_word(word): From c6bb6da52eb118764c91e68a02e9f88f5c76c1c1 Mon Sep 17 00:00:00 2001 From: Intesar Siraj Date: Tue, 27 Sep 2022 15:23:33 -0700 Subject: [PATCH 04/10] Wave1 test passed --- adagrams/game.py | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 26639a9d..cd86f742 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -6,10 +6,6 @@ def draw_letters(): #create a pool for all the letters, using a list #import random # use random.choices to randomly generate 10 letters from the letter pool - - # LETTER_POOL = ["A","A","A","A","A","A","A","A","A", "B","B", "C","C","D","D","D","D","E","E","E","E","E","E","E","E","E","E", - # "E","E","F","F","G","G","G","H","H","I","I","I","I","I","I","I","I","I","J","K","L","L","L","L","M","M","N","N","N","N","N","N","O" - # ,"O","O","O","O","O","O","O","O","P","P","Q","R","R","R","R","R","R","S","S","S","S","T","T","T","T","T","T","U","U","U","U","V","V","W","W","X","Y","Y","Z"] LETTER_POOL_COUNT = { 'A': 9, 'B': 2, @@ -39,37 +35,15 @@ def draw_letters(): 'Z': 1 } hand = [] - while len(hand) < 11: + while len(hand) < 10: random_letter = random.choice(string.ascii_uppercase) if hand.count(random_letter) < LETTER_POOL_COUNT[random_letter]: hand.append(random_letter) + continue else: continue return hand - - # # random_letter = random.choice(string.ascii_uppercase) - # random_letter = random.choice(LETTER_POOL_COUNT.keys()) - # # if random_letter in hand: - # hand.append(random_letter) - # if hand.count(draw_letters) > LETTER_POOL_COUNT[draw_letters]: - # hand.pop() - - # and hand.count(draw_letter) <= LETTER_POOL_COUNT[draw_letter]: - # draw_letter = random.choice(LETTER_POOL_COUNT.keys()) - # hand.append(draw_letter) - - # return hand - - # letter_list = LETTER_POOL_COUNT.keys() - - # for letter in letter_list: - - - # for i in range (LETTER_POOL_COUNT[letter]): - # LETTER_POOL.append(letter) - - # return random.choices(LETTER_POOL_COUNT,k=10) def uses_available_letters(word, letter_bank): word_case = word.upper() From ef2520e73494e52faf2770bca24c8a44b03ce0b4 Mon Sep 17 00:00:00 2001 From: Intesar Siraj Date: Wed, 28 Sep 2022 14:02:12 -0700 Subject: [PATCH 05/10] wave 3 done --- adagrams/game.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index cd86f742..38cfdad1 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -60,12 +60,22 @@ def uses_available_letters(word, letter_bank): def score_word(word): - pass - # create the dictionary for letter in word (score_chart) - # score is starting from 0 + LETTER_SCORE = {'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_upper = word.upper() + score = 0 + + for letter in word_upper: + if letter in LETTER_SCORE: + score += LETTER_SCORE[letter] + if len(word_upper) >= 7 and len(word_upper) <= 10: + score += 8 + return score + # iterate over the word and add scores, value = dict["keys"] # check len(word) == 7, 8, 9, or 10, then score += 8 points + def get_highest_word_score(word_list): pass # word_list: stores all words user submitted From 19c50a0c0a3b414dc8a7f5164ec846aa0ff14b5b Mon Sep 17 00:00:00 2001 From: Intesar Siraj Date: Wed, 28 Sep 2022 14:22:52 -0700 Subject: [PATCH 06/10] Wave 4 done --- adagrams/game.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 38cfdad1..22f17630 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -72,14 +72,24 @@ def score_word(word): score += 8 return score - # iterate over the word and add scores, value = dict["keys"] - # check len(word) == 7, 8, 9, or 10, then score += 8 points - - def get_highest_word_score(word_list): - pass - # word_list: stores all words user submitted - # build a list/dict for all words & scores: {"word1" : score1; "word2" : score2; ... etc} - # find the max value in the dict/list dict.values, append to winning_dict - # handling ties: len(word)==10 > smalles len(word) > len1==len2: word1 wins - # return a tuple for the highest score words (word, score) \ No newline at end of file + sorted_word_list = sorted(word_list, key=len) + score_list = [] + word_score_dict = {} + for word in sorted_word_list: + word_score = score_word(word) + score_list.append(word_score) + word_score_dict[word] = word_score + + highest_word_score = max(set(score_list)) + highest_word_dict = {} + for word, score in word_score_dict.items(): + if score == highest_word_score: + highest_word_dict[word] = score + for word, score in highest_word_dict.items(): + if len(word) == 10: + winning_tuple = (word, score) + break + else: + winning_tuple = list(highest_word_dict.items())[0] + return winning_tuple From 871057939ef28f62ecdb8744a667cf28ea2e149e Mon Sep 17 00:00:00 2001 From: Intesar Siraj Date: Thu, 29 Sep 2022 13:39:42 -0700 Subject: [PATCH 07/10] Wave4 commented version by IS --- adagrams/game.py | 34 ++++++++++++++++++++++++++++++++++ main.py | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 22f17630..068077a1 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -93,3 +93,37 @@ def get_highest_word_score(word_list): else: winning_tuple = list(highest_word_dict.items())[0] return winning_tuple + +# def get_highest_word_score(word_list): +# word_to_score_dict = {} +# for word in word_list: +# word_score = score_word(word) +# word_to_score_dict[word] = word_score + +# highest_scoring_word = () + +# for word, word_score in word_to_score_dict.items(): +# highest_scoring_word = (word, word_score) +# # by putting [1] i am accessing the score 0 +# if word_score > highest_scoring_word[1]: +# highest_scoring_word = (word, word_score) +# return (highest_scoring_word) +# elif word_score == highest_scoring_word[1]: +# if len(highest_scoring_word[0]) == 10: +# return highest_scoring_word +# elif len(word) == 10: +# highest_scoring_word = (word, word_to_score_dict[word]) +# return highest_scoring_word +# elif len(highest_scoring_word[0]) <= len(word): +# return highest_scoring_word +# elif len(highest_scoring_word[0]) > len(word): +# highest_scoring_word = (word, word_to_score_dict[word]) +# return highest_scoring_word +# else: +# continue + + + + + + diff --git a/main.py b/main.py index 9bc645e6..9096f77a 100644 --- a/main.py +++ b/main.py @@ -33,7 +33,7 @@ def wave_2_run_game(): display_retry_instructions() continue_input = input() game_continue = continue_input == "y" - + display_goodbye_message() def wave_3_run_game(): From f2a9685fe57919ff0538571bd2ed59c56a956f66 Mon Sep 17 00:00:00 2001 From: Intesar Siraj Date: Thu, 29 Sep 2022 19:41:19 -0700 Subject: [PATCH 08/10] WaveIV commented by IS --- adagrams/game.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 068077a1..bef87b8d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -72,6 +72,7 @@ def score_word(word): score += 8 return score +#CODED_BY_YUN: def get_highest_word_score(word_list): sorted_word_list = sorted(word_list, key=len) score_list = [] @@ -94,33 +95,43 @@ def get_highest_word_score(word_list): winning_tuple = list(highest_word_dict.items())[0] return winning_tuple +#CODED_BY_IS # def get_highest_word_score(word_list): # word_to_score_dict = {} # for word in word_list: # word_score = score_word(word) # word_to_score_dict[word] = word_score - +# winning_words = [] # highest_scoring_word = () - +# highest_scoring_word = (word, word_score) + # for word, word_score in word_to_score_dict.items(): -# highest_scoring_word = (word, word_score) -# # by putting [1] i am accessing the score 0 +# if highest_scoring_word == (): +# highest_scoring_word = (word, word_score) +# continue # if word_score > highest_scoring_word[1]: # highest_scoring_word = (word, word_score) -# return (highest_scoring_word) -# elif word_score == highest_scoring_word[1]: +# winning_words.append(highest_scoring_word) + +# if word_score == highest_scoring_word[1]: # if len(highest_scoring_word[0]) == 10: +# winning_words.append(highest_scoring_word) # return highest_scoring_word -# elif len(word) == 10: + +# if len(word) == 10 and len(highest_scoring_word[0]) <= len(word): # highest_scoring_word = (word, word_to_score_dict[word]) +# winning_words.append(highest_scoring_word) # return highest_scoring_word -# elif len(highest_scoring_word[0]) <= len(word): -# return highest_scoring_word -# elif len(highest_scoring_word[0]) > len(word): +# if len(highest_scoring_word[0]) > len(word): # highest_scoring_word = (word, word_to_score_dict[word]) -# return highest_scoring_word -# else: -# continue +# elif len(highest_scoring_word[0]) == len(word): +# highest_scoring_word = (word, word_to_score_dict[word]) + +# winning_words.append(highest_scoring_word) +# return highest_scoring_word + + + From 769622e4f7e59a0be821123aa6ffa6df61be7e67 Mon Sep 17 00:00:00 2001 From: Intesar Siraj Date: Thu, 29 Sep 2022 20:40:46 -0700 Subject: [PATCH 09/10] last changes --- adagrams/game.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index bef87b8d..a72cc1dd 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -95,7 +95,7 @@ def get_highest_word_score(word_list): winning_tuple = list(highest_word_dict.items())[0] return winning_tuple -#CODED_BY_IS +##CODED_BY_IS## # def get_highest_word_score(word_list): # word_to_score_dict = {} # for word in word_list: From e0fe1744cc50319a52bb9a99d5d44759fd51189d Mon Sep 17 00:00:00 2001 From: Yun <109842432+YLiu811@users.noreply.github.com> Date: Fri, 30 Sep 2022 21:25:52 -0700 Subject: [PATCH 10/10] Yun added a solution for Wave 4 Following Intersar's idea, fixed bugs. Should pass all 4 tests, too. --- adagrams/game.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index a72cc1dd..00d0f6bb 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -129,7 +129,33 @@ def get_highest_word_score(word_list): # winning_words.append(highest_scoring_word) # return highest_scoring_word - + +# Sept 30, Yun: Hey Intersar. I tried to fix the bugs but followed your idea of using only tuple +# \and only iterate over once in the highest_scoring_word dict. +# \please see below code and I believe it should work now, for Wave 4. + +# word_to_score_dict = {} +# for word in word_list: +# word_score = score_word(word) +# word_to_score_dict[word] = word_score + +# highest_scoring_word = list(word_to_score_dict.items())[0] + +# for word, word_score in word_to_score_dict.items(): +# if word_score > highest_scoring_word[1]: +# highest_scoring_word = (word, word_score) + +# elif word_score == highest_scoring_word[1]: +# if len(highest_scoring_word[0]) == 10 and len(word) <= 10: +# continue +# elif len(word) == 10 and len(highest_scoring_word[0]) <= 10: +# highest_scoring_word = (word, word_score) +# elif len(word) < len(highest_scoring_word[0]): +# highest_scoring_word = (word, word_score) +# elif len(highest_scoring_word[0]) < len(word): +# continue +# return highest_scoring_word +#