Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tigers - Rose and Kindra #63

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 107 additions & 5 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love a good helper function!! 👍 By creating a list of all letters by quantity, we get a more accurate hand of letter from the 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]:
Comment on lines +72 to +73

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the letter_pool_list has all the letters that can be pulled inside it, instead of finding the count of the letter every time, what if we just used remove and took out the letter from the list.

Now, the next time line 71 executes, it will have an accurate pool of letters that never need recounting. If it's in the list still, then it's fair game.

Either works! I don't think my suggestion is any more efficient than yours, however!

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
Comment on lines +81 to +82

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! While the tests all passed, I think we can expand on the logic here to make it more robust. Let's say our word is "DOG" and our hand is [D,G,G,I,O,D,L,A,S,T]

Would your function return this as true or false?

return True

def score_word(word):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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
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)
Comment on lines +111 to +112

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could combine these together in one line:

    return highest_scoring_word,highest_score


21 changes: 21 additions & 0 deletions adagrams/scratch.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down