From dcf52dde40b9aeaaa3dba80a15926400f766d850 Mon Sep 17 00:00:00 2001 From: Vange Spracklin Date: Wed, 22 Sep 2021 14:01:44 -0700 Subject: [PATCH 1/9] add pseudocode for draw_letters function --- adagrams/game.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..d94397c5 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,11 +1,71 @@ +# import random module +import random + +# create a constant variable called LETTER_POOL which will be a tuple +# filled with nested dictionaries that hold the letter info +# +# example: +# LETTER_POOL = ( +# {"A" : { +# "frequency" : 9, +# "point_value" : 1 +# } +# }, +# { "B" : { +# "frequency" : 2, +# "point_value" : 3 +# } +# } +# ) + + def draw_letters(): pass + # create an empty list that will eventually hold + # 10 strings, letter "hand of letters" + + # create an empty list that will eventually hold all + # the letters in letter pool in accurate frequency. + # example of how list will eventually look like: + # letter_pool_list = ["A","A","A","A","A","A","A","A","A","B","B" etc...] + + # iterate through the LETTER_POOL tuple with a forloop + # append each key (which will be a string like "A" or "B") to the list + # letter_pool_list the appropriate number of times aka the value (which will be + # an int like 9 or 2). + + # create a for loop that will run 10x + # generate a random int + # select a string from letter_pool_list with the index random int + # example: letter_pool_list[random_int] + # use the pop(index) function to remove the string at index random_int. + + # append the popped value to hand of letter list + + # return a list that contains 10 strings ["A", "B", "C" etc...] def uses_available_letters(word, letter_bank): pass + # returns a boolean value. + # True if the word can be spelled with the 10 letters + # in the list "letter_bank" that we are passed. + # False if the word cannote be spelled. + def score_word(word): pass def get_highest_word_score(word_list): - pass \ No newline at end of file + pass + + +# list = ["a","b","c"] +# hand_draw_letters = [] + +# picked_letter = list.pop(1) + +# #print(picked_letter) +# hand_draw_letters.append(picked_letter) + +# print(list) +# print(hand_draw_letters) \ No newline at end of file From 746a4b5fdae990538ea434562edb919182ba40cf Mon Sep 17 00:00:00 2001 From: Sandra Caballero Date: Wed, 22 Sep 2021 14:39:21 -0700 Subject: [PATCH 2/9] added list and beginning of for loop in draw_letters --- adagrams/game.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index d94397c5..590f228e 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,3 +1,4 @@ + # import random module import random @@ -5,29 +6,32 @@ # filled with nested dictionaries that hold the letter info # # example: -# LETTER_POOL = ( -# {"A" : { -# "frequency" : 9, -# "point_value" : 1 -# } -# }, -# { "B" : { -# "frequency" : 2, -# "point_value" : 3 -# } -# } -# ) +LETTER_POOL = ( + {"A" : { + "frequency" : 9, + "point_value" : 1 + } + }, + { "B" : { + "frequency" : 2, + "point_value" : 3 + } + } +) def draw_letters(): - pass + hand_of_letters = [] # create an empty list that will eventually hold # 10 strings, letter "hand of letters" - + letter_pool_list = [] # create an empty list that will eventually hold all # the letters in letter pool in accurate frequency. # example of how list will eventually look like: # letter_pool_list = ["A","A","A","A","A","A","A","A","A","B","B" etc...] + for letter in LETTER_POOL: + letter.keys() + # iterate through the LETTER_POOL tuple with a forloop # append each key (which will be a string like "A" or "B") to the list @@ -68,4 +72,6 @@ def get_highest_word_score(word_list): # hand_draw_letters.append(picked_letter) # print(list) -# print(hand_draw_letters) \ No newline at end of file +# print(hand_draw_letters) + +draw_letters() \ No newline at end of file From aa03d246451a6ac2a3467f77977390e2b22ba5b6 Mon Sep 17 00:00:00 2001 From: Vange Spracklin Date: Wed, 22 Sep 2021 15:21:42 -0700 Subject: [PATCH 3/9] passes wave 1 --- adagrams/game.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 590f228e..0bee0776 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -19,34 +19,41 @@ } ) - def draw_letters(): - hand_of_letters = [] # create an empty list that will eventually hold # 10 strings, letter "hand of letters" - letter_pool_list = [] + hand_of_letters = [] + # create an empty list that will eventually hold all # the letters in letter pool in accurate frequency. # example of how list will eventually look like: # letter_pool_list = ["A","A","A","A","A","A","A","A","A","B","B" etc...] - for letter in LETTER_POOL: - letter.keys() - + letter_pool_list = [] # iterate through the LETTER_POOL tuple with a forloop # append each key (which will be a string like "A" or "B") to the list # letter_pool_list the appropriate number of times aka the value (which will be # an int like 9 or 2). + for letter_dict in LETTER_POOL: + for key in letter_dict: + freq = letter_dict[key]["frequency"] + for i in range(0, freq): + letter_pool_list.append(key) # create a for loop that will run 10x - # generate a random int - # select a string from letter_pool_list with the index random int - # example: letter_pool_list[random_int] - # use the pop(index) function to remove the string at index random_int. - - # append the popped value to hand of letter list - - # return a list that contains 10 strings ["A", "B", "C" etc...] + # generate a random int + # select a string from letter_pool_list with the index position random int + # example: letter_pool_list[random_int] + # use the pop(index) function to remove the string at index random_int. + # append the popped value to hand of letter list + for i in range(10): + index = random.randint(0, len(letter_pool_list)-1) + letter = letter_pool_list[index] + hand_of_letters.append(letter) + letter_pool_list.pop(index) + + # return a list that contains 10 strings ["A", "B", "C" etc... + return hand_of_letters def uses_available_letters(word, letter_bank): pass @@ -74,4 +81,4 @@ def get_highest_word_score(word_list): # print(list) # print(hand_draw_letters) -draw_letters() \ No newline at end of file +print(draw_letters()) \ No newline at end of file From 846387e8fc5e72dd358e45e529cffd17bd7334f8 Mon Sep 17 00:00:00 2001 From: Sandra Caballero Date: Thu, 23 Sep 2021 12:13:40 -0700 Subject: [PATCH 4/9] completed LETTER_POOL --- adagrams/game.py | 120 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/adagrams/game.py b/adagrams/game.py index 0bee0776..a4422bdf 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -16,6 +16,126 @@ "frequency" : 2, "point_value" : 3 } + }, + {"C" : { + "frequency" : 2, + "point_value" : 3 + } + }, + {"D" : { + "frequency" : 4, + "point_value" : 2 + } + }, + {"E" : { + "frequency" : 12, + "point_value" : 1 + } + }, + {"F" : { + "frequency" : 2, + "point_value" : 4 + } + }, + {"G" : { + "frequency" : 3, + "point_value" : 2 + } + }, + {"H" : { + "frequency" : 2, + "point_value" : 4 + } + }, + {"I" : { + "frequency" : 9, + "point_value" : 1 + } + }, + {"J" : { + "frequency" : 1, + "point_value" : 8 + } + }, + {"K" : { + "frequency" : 1, + "point_value" : 5 + } + }, + {"L" : { + "frequency" : 4, + "point_value" : 1 + } + }, + {"M" : { + "frequency" : 2, + "point_value" : 3 + } + }, + {"N": { + "frequency" : 6, + "point_value" : 1 + } + }, + {"O" : { + "frequency" : 8, + "point_value" : 1 + } + }, + {"P" : { + "frequency" : 2, + "point_value" : 3 + } + }, + {"Q" : { + "frequency" : 1, + "point_value" : 10 + } + }, + {"R" : { + "frequency" : 6, + "point_value" : 1 + } + }, + {"S" : { + "frequency" : 4, + "point_value" : 1 + } + }, + {"T" : { + "frequency" : 6, + "point_value" : 1 + } + }, + {"U" : { + "frequency" : 4, + "point_value" : 1 + } + }, + {"V" : { + "frequency" : 2, + "point_value" : 4 + } + }, + {"W" : { + "frequency" : 2, + "point_value" : 4 + } + }, + {"X" : { + "frequency" : 1, + "point_value" : 8 + } + }, + {"Y" : { + "frequency" : 2, + "point_value" : 4 + } + }, + {"Z": { + "frequency" : 1, + "point_value" : 10 + } } ) From b52a7b0b71f09f16ba5af4d27fa8f2fbf3290996 Mon Sep 17 00:00:00 2001 From: Vange Spracklin Date: Fri, 24 Sep 2021 16:39:26 -0700 Subject: [PATCH 5/9] pseudo code for wave 2, 3, 4 --- adagrams/game.py | 76 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 10 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index a4422bdf..b193cb29 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -20,7 +20,7 @@ {"C" : { "frequency" : 2, "point_value" : 3 - } + } }, {"D" : { "frequency" : 4, @@ -176,7 +176,28 @@ def draw_letters(): return hand_of_letters def uses_available_letters(word, letter_bank): - pass + #make a copy of the list letter_bank for safe to operate on and change + letter_bank_copy = letter_bank[:] + + # make a list of characters in the word variable (which is a string) + word_character_list = list(word) + + # create a loop + count = 0 + for letter in word_character_list: + if letter in letter_bank_copy: + print(letter) + letter_bank_copy.pop() + count += 1 + else: + print(f"The letter {letter} is unavailale") + letter_bank_copy.pop() + # create an if statement that compares the letters in the letter bank with the letters + # in the word + + # use the pop function to remove a letter from the letter bank copy once it's been + # compared with a letter in the word + # returns a boolean value. # True if the word can be spelled with the 10 letters @@ -185,20 +206,55 @@ def uses_available_letters(word, letter_bank): def score_word(word): pass + # create a variable for the total_score, set the score to 0 + + # make the string variable we are passed ALL CAPS with the upper() function + # that way each character in our word will match the dictionary keys in LETTER_POOL + # example: word = word.upper() + + # make a 3 nested for loops (indentation indicates scope) + # iterate through each character in the word variable + # iterate through each element (we used "letter_dict" in the first function) in LETTER_POOL + # iterate through each key in the "letter_dict" to access it's value, which is another dictionary with data about the letter frequency and point value. + # i got this expression from the iterating over dictionaries lesson in Learn: "for letter, letter_data in letter_dict.items():" + # i'm not sure how to word what it's doing. + # compare the key of the dictionary (which will be a letter) to the character in the word from the first loop. if they match add the letter's point + # value to the variable total_score + + # evaluate the length of the word variable + # make an if statement where if the word is longer than 7 characters add 8 points to total_score + + # return total_score variable def get_highest_word_score(word_list): + pass + # create an empty list variable (best_word) that will eventually hold the best word's data + # where the first value is the string of the word and the second value is the point value + # example: best_word = ["reallygoodword", 14] + + #create an empty string variable that will eventually hold the word with the most points (top_word) + + #create a variable for the top score and set it to zero (top_score) + + # iterate through each word in word_list and calculate it's score with the score_word function + # compare the score to the variable top_score with if statements. + # if the score is bigger than top_score, make that word the top_word and that score top_score + # if the score is a tie compare the length of each word with if statements + # if one word has exactly 10 letters in it, thats the top_word + # if both words have 10 letters the word with the lowest index in word_list is top_word + # if neither of the words have 10 letters the shorter word it top_word -# list = ["a","b","c"] -# hand_draw_letters = [] + #return the best_word list with top_word as the first value and top_score as the 2nd value + # best_word = [top_word, top_score] -# picked_letter = list.pop(1) +letter_bank_test = draw_letters() +print(letter_bank_test) +water_character_list = list("WATER") -# #print(picked_letter) -# hand_draw_letters.append(picked_letter) +["W", "A", "T", "E", "R"] -# print(list) -# print(hand_draw_letters) +uses_available_letters("WATER", letter_bank_test) -print(draw_letters()) \ No newline at end of file +print(letter_bank_test) \ No newline at end of file From 07681e5a146d777e86bc3b0641e5a44537dac808 Mon Sep 17 00:00:00 2001 From: Sandra Caballero Date: Sat, 25 Sep 2021 15:57:45 -0700 Subject: [PATCH 6/9] completes wave 2 --- adagrams/game.py | 99 ++++-------------------------------------------- 1 file changed, 8 insertions(+), 91 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index b193cb29..f0a61357 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -140,121 +140,38 @@ ) def draw_letters(): - # create an empty list that will eventually hold - # 10 strings, letter "hand of letters" hand_of_letters = [] - - # create an empty list that will eventually hold all - # the letters in letter pool in accurate frequency. - # example of how list will eventually look like: - # letter_pool_list = ["A","A","A","A","A","A","A","A","A","B","B" etc...] letter_pool_list = [] - - # iterate through the LETTER_POOL tuple with a forloop - # append each key (which will be a string like "A" or "B") to the list - # letter_pool_list the appropriate number of times aka the value (which will be - # an int like 9 or 2). + for letter_dict in LETTER_POOL: for key in letter_dict: freq = letter_dict[key]["frequency"] for i in range(0, freq): letter_pool_list.append(key) - - # create a for loop that will run 10x - # generate a random int - # select a string from letter_pool_list with the index position random int - # example: letter_pool_list[random_int] - # use the pop(index) function to remove the string at index random_int. - # append the popped value to hand of letter list + for i in range(10): index = random.randint(0, len(letter_pool_list)-1) letter = letter_pool_list[index] hand_of_letters.append(letter) letter_pool_list.pop(index) - # return a list that contains 10 strings ["A", "B", "C" etc... return hand_of_letters def uses_available_letters(word, letter_bank): - #make a copy of the list letter_bank for safe to operate on and change letter_bank_copy = letter_bank[:] - - # make a list of characters in the word variable (which is a string) word_character_list = list(word) - # create a loop - count = 0 for letter in word_character_list: if letter in letter_bank_copy: print(letter) - letter_bank_copy.pop() - count += 1 + letter_bank_copy.remove(letter) + print(letter_bank_copy) else: - print(f"The letter {letter} is unavailale") - letter_bank_copy.pop() - # create an if statement that compares the letters in the letter bank with the letters - # in the word - - # use the pop function to remove a letter from the letter bank copy once it's been - # compared with a letter in the word - - - # returns a boolean value. - # True if the word can be spelled with the 10 letters - # in the list "letter_bank" that we are passed. - # False if the word cannote be spelled. + return False + return True def score_word(word): - pass - # create a variable for the total_score, set the score to 0 - - # make the string variable we are passed ALL CAPS with the upper() function - # that way each character in our word will match the dictionary keys in LETTER_POOL - # example: word = word.upper() - - # make a 3 nested for loops (indentation indicates scope) - # iterate through each character in the word variable - # iterate through each element (we used "letter_dict" in the first function) in LETTER_POOL - # iterate through each key in the "letter_dict" to access it's value, which is another dictionary with data about the letter frequency and point value. - # i got this expression from the iterating over dictionaries lesson in Learn: "for letter, letter_data in letter_dict.items():" - # i'm not sure how to word what it's doing. - # compare the key of the dictionary (which will be a letter) to the character in the word from the first loop. if they match add the letter's point - # value to the variable total_score - - # evaluate the length of the word variable - # make an if statement where if the word is longer than 7 characters add 8 points to total_score - - # return total_score variable - -def get_highest_word_score(word_list): - - pass - # create an empty list variable (best_word) that will eventually hold the best word's data - # where the first value is the string of the word and the second value is the point value - # example: best_word = ["reallygoodword", 14] - - #create an empty string variable that will eventually hold the word with the most points (top_word) - - #create a variable for the top score and set it to zero (top_score) - - # iterate through each word in word_list and calculate it's score with the score_word function - # compare the score to the variable top_score with if statements. - # if the score is bigger than top_score, make that word the top_word and that score top_score - # if the score is a tie compare the length of each word with if statements - # if one word has exactly 10 letters in it, thats the top_word - # if both words have 10 letters the word with the lowest index in word_list is top_word - # if neither of the words have 10 letters the shorter word it top_word - - - #return the best_word list with top_word as the first value and top_score as the 2nd value - # best_word = [top_word, top_score] - -letter_bank_test = draw_letters() -print(letter_bank_test) -water_character_list = list("WATER") - -["W", "A", "T", "E", "R"] + -uses_available_letters("WATER", letter_bank_test) -print(letter_bank_test) \ No newline at end of file +def get_highest_word_score(word_list): \ No newline at end of file From e9f6be36257d85b8965f433a8e477838d658e37e Mon Sep 17 00:00:00 2001 From: Sandra Caballero Date: Sat, 25 Sep 2021 16:14:14 -0700 Subject: [PATCH 7/9] completes wave 3 --- adagrams/game.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index f0a61357..a42a9a42 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -171,7 +171,20 @@ def uses_available_letters(word, letter_bank): return True def score_word(word): - + total_score = 0 + word = word.upper() + for letter in word: + for letter_dict in LETTER_POOL: + for letter_key, letter_data in letter_dict.items(): + if letter_key == letter: + total_score += letter_data["point_value"] + + if len(word) >= 7: + total_score += 8 -def get_highest_word_score(word_list): \ No newline at end of file + return total_score + + +def get_highest_word_score(word_list): + pass \ No newline at end of file From 430015c8af65a6951afae9b35c9957cf6970e60e Mon Sep 17 00:00:00 2001 From: Sandra Caballero Date: Sat, 25 Sep 2021 16:15:40 -0700 Subject: [PATCH 8/9] completes wave 4 --- adagrams/game.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index a42a9a42..7c430c00 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -187,4 +187,24 @@ def score_word(word): def get_highest_word_score(word_list): - pass \ No newline at end of file + top_word = "" + top_score = 0 + + for word in word_list: + if score_word(word) > top_score: + top_word = word + top_score = score_word(word) + elif score_word(word) == top_score: + if len(word) == 10 and len(top_word) == 10: + continue + elif len(top_word) == 10: + continue + elif len(word) == 10: + top_word = word + top_score = score_word(word) + elif len(word) < len(top_word): + top_word = word + top_score = score_word(word) + + best_word = [top_word, top_score] + return best_word \ No newline at end of file From 2a349561d0b11b7c99bd07c71ffce10b6bfe045e Mon Sep 17 00:00:00 2001 From: Vange Spracklin Date: Sun, 26 Sep 2021 14:58:49 -0700 Subject: [PATCH 9/9] adds finishing edits --- adagrams/game.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 7c430c00..a825696e 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,11 +1,5 @@ - -# import random module import random -# create a constant variable called LETTER_POOL which will be a tuple -# filled with nested dictionaries that hold the letter info -# -# example: LETTER_POOL = ( {"A" : { "frequency" : 9, @@ -142,7 +136,7 @@ def draw_letters(): hand_of_letters = [] letter_pool_list = [] - + for letter_dict in LETTER_POOL: for key in letter_dict: freq = letter_dict[key]["frequency"] @@ -163,29 +157,27 @@ def uses_available_letters(word, letter_bank): for letter in word_character_list: if letter in letter_bank_copy: - print(letter) letter_bank_copy.remove(letter) - print(letter_bank_copy) else: return False return True def score_word(word): total_score = 0 + word = word.upper() for letter in word: for letter_dict in LETTER_POOL: for letter_key, letter_data in letter_dict.items(): if letter_key == letter: - total_score += letter_data["point_value"] - + total_score += letter_data["point_value"] + if len(word) >= 7: total_score += 8 return total_score - def get_highest_word_score(word_list): top_word = "" top_score = 0 @@ -199,12 +191,9 @@ def get_highest_word_score(word_list): continue elif len(top_word) == 10: continue - elif len(word) == 10: + elif len(word) == 10 or len(word) < len(top_word): top_word = word top_score = score_word(word) - elif len(word) < len(top_word): - top_word = word - top_score = score_word(word) best_word = [top_word, top_score] return best_word \ No newline at end of file