Skip to content

Tigers- Selam Chaka #60

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

Open
wants to merge 12 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# AdaGrams
## Plan of Action
process each part of a wave on our own and try to work through it and code what we can. Check in on eachother for progress or questions. Get together to review code. Attend extra help sessions if needed.

## Skills Assessed

Expand Down
148 changes: 143 additions & 5 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,149 @@
def draw_letters():
pass
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,
'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
}

def draw_letters():
letter_freq = {}
random_letters=[]
selected_letters =[]
while len(random_letters) < 26:
r = random.choice(list(LETTER_POOL.keys()))
random_letters.append(r)
for letter in random_letters:
if letter in letter_freq:
letter_freq[letter] += 1
else:
letter_freq[letter] = 1
if letter_freq[letter] <= LETTER_POOL[letter]:
selected_letters.append(letter)
return (selected_letters[0:10])

Choose a reason for hiding this comment

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

This looks good, overall but remember that it is not accounting for the different probabilities of each letter! We could take that into account by creating a collection of some sort that holds every possible value (12 E's, 9 A's, etc) and then making our selections from that collection and removing them as they are picked!

def uses_available_letters(word, letter_bank):
pass
word_str = ""
temp_word = ""
letter_bank_dic = {}
word_dic ={}

for letter in word:
if str.upper(letter) in letter_bank:
temp_word += letter
word_str += str.upper(letter)
for letter in letter_bank:
if letter in letter_bank_dic:
letter_bank_dic[str.upper(letter)] += 1
else:
letter_bank_dic[str.upper(letter)] = 1
for letter in word_str:
if letter in word_dic:
word_dic[str.upper(letter)] += 1
else:
word_dic[str.upper(letter)] = 1
if word_dic[letter] > letter_bank_dic[letter]:
return False
elif temp_word != word:
return False
elif temp_word == word:
return True

Choose a reason for hiding this comment

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

I see exactly what y'all were doing here. The problem is that you are making a variety of extra dictionaries and strings that just aren't necessary. In cases like this, it would be much better to make a deep copy of the letter_bank. From there, you can simply manipulate your copy.

The process would be as follows:

  1. Make a deep copy of the letter bank.
  2. Go through each letter in the word and see if it is in the letter bank copy.
    a) If it is, remove it from the letter bank copy.
    b) If it isn't return False
  3. If you make it through the word without returning False, return True.

This will take into account multiples of the same letter!

Choose a reason for hiding this comment

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

I see exactly what y'all were doing here. The problem is that you are making a variety of extra dictionaries and strings that just aren't necessary. In cases like this, it would be much better to make a deep copy of the letter_bank. From there, you can simply manipulate your copy.

The process would be as follows:

  1. Make a deep copy of the letter bank.
  2. Go through each letter in the word and see if it is in the letter bank copy.
    a) If it is, remove it from the letter bank copy.
    b) If it isn't return False
  3. If you make it through the word without returning False, return True.

This will take into account multiples of the same letter!


def score_word(word):
pass
if word == "":
return 0
score_word = 0
upper_word = str.upper(word)

for letter in upper_word:
for key, value in SCORE_CHART.items():
if letter == key:
score_word += value

if len(word) in range(7, 11):
score_word += 8

return score_word

Choose a reason for hiding this comment

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

This looks great! It's a simple and effective implementation of the score method!


def get_highest_word_score(word_list):
pass
highest_word = []
highest_value = 0
tie_word = []
for word in word_list:
word_score = score_word(word)
if word_score > highest_value:
highest_word = word
highest_value = word_score
tie_word = [highest_word]
elif word_score == highest_value: # tie case
tie_word.append(word)

if len(tie_word) > 1 :
if len(tie_word[0]) > len(tie_word[1]) and len(tie_word[0])==10 :
return (tie_word[0], highest_value)
elif len(tie_word[0]) < len(tie_word[1]) and len(tie_word[1])!=10 :
return (tie_word[0], highest_value)
elif len(tie_word[0]) == len(tie_word[1]):
return(tie_word[0], highest_value)
else:
return(tie_word[1], highest_value)

return (highest_word, highest_value)

Choose a reason for hiding this comment

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

Once again, you are creating several extra lists that we don't necessarily need. This works and is a great first pass, but we could definitely pare it down a bit! One implementation would have been to have a tuple that just holds the highest scoring word and the highest score. From there, we can do the following:

  1. Make a tuple to hold the first word and its score.
  2. For each word in the list, score it and compare it to the score in your highest word tuple.
  3. If the score is higher, replace the tuple with the new word.
  4. If it is a tie, run the if/else statements you have there toward the bottom of the function!

This really just avoids having to write a tie_word list. We can kind of figure out what the highest word in place.






1 change: 1 addition & 0 deletions tests/test_wave_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ def test_letter_not_selected_too_many_times():
# Assert
for letter in letters:
assert letter_freq[letter] <= LETTER_POOL[letter]
pass