diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..93c11de5 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,11 +1,113 @@ +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 +} + +SCORE_CHART = { + 'A': 1, + 'E': 1, + 'I': 1, + 'O': 1, + 'U': 1, + 'L': 1, + 'N': 1, + 'R': 1, + 'S': 1, + 'T': 1, + 'D': 2, + 'G': 2, + 'B': 3, + 'C': 3, + 'M': 3, + 'P': 3, + 'F': 4, + 'H': 4, + 'V': 4, + 'W': 4, + 'Y': 4, + 'K': 5, + 'J': 8, + 'X': 8, + 'Q': 10, + 'Z': 10 +} + +def create_letter_pool_list(LETTER_POOL): + letter_pool_list = [] + for key, value in LETTER_POOL.items(): + for i in range(value): + letter_pool_list.append(key) + return letter_pool_list + def draw_letters(): - pass + hand_of_ten_letters = [] + letter_pool_list = create_letter_pool_list(LETTER_POOL) + while len(hand_of_ten_letters) < 10: + random_letter = random.choice(letter_pool_list) + count = hand_of_ten_letters.count(random_letter) + if count < LETTER_POOL[random_letter]: + hand_of_ten_letters.append(random_letter) + return(hand_of_ten_letters) + -def uses_available_letters(word, letter_bank): - pass +def uses_available_letters(word, hand_of_ten_letters): + word = word.upper() + for char in word: + if word.count(char) is not hand_of_ten_letters.count(char): + return False + return True def score_word(word): - pass + word = word.upper() + score = 0 + for letter in word: + 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 + highest_score = 0 + highest_scoring_word = "" + for word in word_list: + score = score_word(word) + if highest_score < score: + highest_score = score + highest_scoring_word = word + elif highest_score == score: + highest_scoring_word_length = len(highest_scoring_word) + current_word_length = len(word) + if highest_scoring_word_length != current_word_length: + if current_word_length == 10: + highest_scoring_word = word + elif highest_scoring_word_length > current_word_length and highest_scoring_word_length != 10: + highest_scoring_word = word + + highest_score_tuple = highest_scoring_word,highest_score + return(highest_score_tuple) + \ No newline at end of file diff --git a/adagrams/scratch.py b/adagrams/scratch.py new file mode 100644 index 00000000..7306c12d --- /dev/null +++ b/adagrams/scratch.py @@ -0,0 +1,21 @@ +from tests.test_wave_01 import LETTER_POOL +import random + + +def draw_letters(): + #returns: ["a", "b", "c", ...] player's hand + #letter doesn't change + #can't have more than the alloted number of a letter + + #initialize empty list + result_list = [] + #set up dictionary of letter pool + character, frequency = random.choice(list(LETTER_POOL.items())) + print(character, frequency) + + + + #a loop to check if len is under 10 + #if not + #return result_list +draw_letters() \ No newline at end of file diff --git a/main.py b/main.py index bcd6ab0b..90cf71e5 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import sys from adagrams.ui_helper import * from adagrams.game import draw_letters, uses_available_letters, score_word, get_highest_word_score +# from tests.test_wave_01 import LETTER_POOL def wave_1_run_game(): display_welcome_message()